Coverage Report - org.owasp.dependencycheck.cli.CliParser
 
Classes in this File Line Coverage Branch Coverage Complexity
CliParser
66%
76/115
52%
26/50
1.784
CliParser$ArgumentName
N/A
N/A
1.784
 
 1  
 /*
 2  
  * This file is part of dependency-check-cli.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  *
 16  
  * Copyright (c) 2012 Jeremy Long. All Rights Reserved.
 17  
  */
 18  
 package org.owasp.dependencycheck.cli;
 19  
 
 20  
 import java.io.File;
 21  
 import java.io.FileNotFoundException;
 22  
 
 23  
 import org.apache.commons.cli.CommandLine;
 24  
 import org.apache.commons.cli.CommandLineParser;
 25  
 import org.apache.commons.cli.HelpFormatter;
 26  
 import org.apache.commons.cli.Option;
 27  
 import org.apache.commons.cli.OptionBuilder;
 28  
 import org.apache.commons.cli.OptionGroup;
 29  
 import org.apache.commons.cli.Options;
 30  
 import org.apache.commons.cli.ParseException;
 31  
 import org.apache.commons.cli.PosixParser;
 32  
 import org.owasp.dependencycheck.reporting.ReportGenerator.Format;
 33  
 import org.owasp.dependencycheck.utils.InvalidSettingException;
 34  
 import org.owasp.dependencycheck.utils.Settings;
 35  
 
 36  
 /**
 37  
  * A utility to parse command line arguments for the DependencyCheck.
 38  
  *
 39  
  * @author Jeremy Long <jeremy.long@owasp.org>
 40  
  */
 41  
 public final class CliParser {
 42  
 
 43  
     /**
 44  
      * The command line.
 45  
      */
 46  
     private CommandLine line;
 47  
     /**
 48  
      * Indicates whether the arguments are valid.
 49  
      */
 50  
     private boolean isValid = true;
 51  
 
 52  
     /**
 53  
      * Parses the arguments passed in and captures the results for later use.
 54  
      *
 55  
      * @param args the command line arguments
 56  
      * @throws FileNotFoundException is thrown when a 'file' argument does not point to a file that exists.
 57  
      * @throws ParseException is thrown when a Parse Exception occurs.
 58  
      */
 59  
     public void parse(String[] args) throws FileNotFoundException, ParseException {
 60  9
         line = parseArgs(args);
 61  
 
 62  8
         if (line != null) {
 63  8
             validateArgs();
 64  
         }
 65  7
     }
 66  
 
 67  
     /**
 68  
      * Parses the command line arguments.
 69  
      *
 70  
      * @param args the command line arguments
 71  
      * @return the results of parsing the command line arguments
 72  
      * @throws ParseException if the arguments are invalid
 73  
      */
 74  
     private CommandLine parseArgs(String[] args) throws ParseException {
 75  9
         final CommandLineParser parser = new PosixParser();
 76  9
         final Options options = createCommandLineOptions();
 77  9
         return parser.parse(options, args);
 78  
     }
 79  
 
 80  
     /**
 81  
      * Validates that the command line arguments are valid.
 82  
      *
 83  
      * @throws FileNotFoundException if there is a file specified by either the SCAN or CPE command line arguments that
 84  
      * does not exist.
 85  
      * @throws ParseException is thrown if there is an exception parsing the command line.
 86  
      */
 87  
     private void validateArgs() throws FileNotFoundException, ParseException {
 88  8
         if (isRunScan()) {
 89  2
             validatePathExists(getScanFiles(), ArgumentName.SCAN);
 90  1
             validatePathExists(getReportDirectory(), ArgumentName.OUT);
 91  1
             if (getPathToMono() != null) {
 92  0
                 validatePathExists(getPathToMono(), ArgumentName.PATH_TO_MONO);
 93  
             }
 94  1
             if (!line.hasOption(ArgumentName.APP_NAME)) {
 95  0
                 throw new ParseException("Missing 'app' argument; the scan cannot be run without the an application name.");
 96  
             }
 97  1
             if (line.hasOption(ArgumentName.OUTPUT_FORMAT)) {
 98  0
                 final String format = line.getOptionValue(ArgumentName.OUTPUT_FORMAT);
 99  
                 try {
 100  0
                     Format.valueOf(format);
 101  0
                 } catch (IllegalArgumentException ex) {
 102  0
                     final String msg = String.format("An invalid 'format' of '%s' was specified. "
 103  
                             + "Supported output formats are XML, HTML, VULN, or ALL", format);
 104  0
                     throw new ParseException(msg);
 105  0
                 }
 106  
             }
 107  
         }
 108  7
     }
 109  
 
 110  
     /**
 111  
      * Validates whether or not the path(s) points at a file that exists; if the path(s) does not point to an existing
 112  
      * file a FileNotFoundException is thrown.
 113  
      *
 114  
      * @param paths the paths to validate if they exists
 115  
      * @param optType the option being validated (e.g. scan, out, etc.)
 116  
      * @throws FileNotFoundException is thrown if one of the paths being validated does not exist.
 117  
      */
 118  
     private void validatePathExists(String[] paths, String optType) throws FileNotFoundException {
 119  3
         for (String path : paths) {
 120  2
             validatePathExists(path, optType);
 121  
         }
 122  1
     }
 123  
 
 124  
     /**
 125  
      * Validates whether or not the path points at a file that exists; if the path does not point to an existing file a
 126  
      * FileNotFoundException is thrown.
 127  
      *
 128  
      * @param path the paths to validate if they exists
 129  
      * @param argumentName the argument being validated (e.g. scan, out, etc.)
 130  
      * @throws FileNotFoundException is thrown if the path being validated does not exist.
 131  
      */
 132  
     private void validatePathExists(String path, String argumentName) throws FileNotFoundException {
 133  3
         final File f = new File(path);
 134  3
         if (!f.exists()) {
 135  1
             isValid = false;
 136  1
             final String msg = String.format("Invalid '%s' argument: '%s'", argumentName, path);
 137  1
             throw new FileNotFoundException(msg);
 138  
         }
 139  2
     }
 140  
 
 141  
     /**
 142  
      * Generates an Options collection that is used to parse the command line and to display the help message.
 143  
      *
 144  
      * @return the command line options used for parsing the command line
 145  
      */
 146  
     @SuppressWarnings("static-access")
 147  
     private Options createCommandLineOptions() {
 148  
 
 149  9
         final Options options = new Options();
 150  9
         addStandardOptions(options);
 151  9
         addAdvancedOptions(options);
 152  
 
 153  9
         return options;
 154  
     }
 155  
 
 156  
     /**
 157  
      * Adds the standard command line options to the given options collection.
 158  
      *
 159  
      * @param options a collection of command line arguments
 160  
      * @throws IllegalArgumentException thrown if there is an exception
 161  
      */
 162  
     @SuppressWarnings("static-access")
 163  
     private void addStandardOptions(final Options options) throws IllegalArgumentException {
 164  11
         final Option help = new Option(ArgumentName.HELP_SHORT, ArgumentName.HELP, false,
 165  
                 "Print this message.");
 166  
 
 167  11
         final Option advancedHelp = OptionBuilder.withLongOpt(ArgumentName.ADVANCED_HELP)
 168  
                 .withDescription("Print the advanced help message.").create();
 169  
 
 170  11
         final Option version = new Option(ArgumentName.VERSION_SHORT, ArgumentName.VERSION,
 171  
                 false, "Print the version information.");
 172  
 
 173  11
         final Option noUpdate = new Option(ArgumentName.DISABLE_AUTO_UPDATE_SHORT, ArgumentName.DISABLE_AUTO_UPDATE,
 174  
                 false, "Disables the automatic updating of the CPE data.");
 175  
 
 176  11
         final Option appName = OptionBuilder.withArgName("name").hasArg().withLongOpt(ArgumentName.APP_NAME)
 177  
                 .withDescription("The name of the application being scanned. This is a required argument.")
 178  
                 .create(ArgumentName.APP_NAME_SHORT);
 179  
 
 180  11
         final Option path = OptionBuilder.withArgName("path").hasArg().withLongOpt(ArgumentName.SCAN)
 181  
                 .withDescription("The path to scan - this option can be specified multiple times.")
 182  
                 .create(ArgumentName.SCAN_SHORT);
 183  
 
 184  11
         final Option props = OptionBuilder.withArgName("file").hasArg().withLongOpt(ArgumentName.PROP)
 185  
                 .withDescription("A property file to load.")
 186  
                 .create(ArgumentName.PROP_SHORT);
 187  
 
 188  11
         final Option out = OptionBuilder.withArgName("folder").hasArg().withLongOpt(ArgumentName.OUT)
 189  
                 .withDescription("The folder to write reports to. This defaults to the current directory.")
 190  
                 .create(ArgumentName.OUT_SHORT);
 191  
 
 192  11
         final Option outputFormat = OptionBuilder.withArgName("format").hasArg().withLongOpt(ArgumentName.OUTPUT_FORMAT)
 193  
                 .withDescription("The output format to write to (XML, HTML, VULN, ALL). The default is HTML.")
 194  
                 .create(ArgumentName.OUTPUT_FORMAT_SHORT);
 195  
 
 196  11
         final Option verboseLog = OptionBuilder.withArgName("file").hasArg().withLongOpt(ArgumentName.VERBOSE_LOG)
 197  
                 .withDescription("The file path to write verbose logging information.")
 198  
                 .create(ArgumentName.VERBOSE_LOG_SHORT);
 199  
 
 200  11
         final Option suppressionFile = OptionBuilder.withArgName("file").hasArg().withLongOpt(ArgumentName.SUPPRESION_FILE)
 201  
                 .withDescription("The file path to the suppression XML file.")
 202  
                 .create();
 203  
 
 204  
         //This is an option group because it can be specified more then once.
 205  11
         final OptionGroup og = new OptionGroup();
 206  11
         og.addOption(path);
 207  
 
 208  11
         options.addOptionGroup(og)
 209  
                 .addOption(out)
 210  
                 .addOption(outputFormat)
 211  
                 .addOption(appName)
 212  
                 .addOption(version)
 213  
                 .addOption(help)
 214  
                 .addOption(advancedHelp)
 215  
                 .addOption(noUpdate)
 216  
                 .addOption(props)
 217  
                 .addOption(verboseLog)
 218  
                 .addOption(suppressionFile);
 219  11
     }
 220  
 
 221  
     /**
 222  
      * Adds the advanced command line options to the given options collection. These are split out for purposes of being
 223  
      * able to display two different help messages.
 224  
      *
 225  
      * @param options a collection of command line arguments
 226  
      * @throws IllegalArgumentException thrown if there is an exception
 227  
      */
 228  
     @SuppressWarnings("static-access")
 229  
     private void addAdvancedOptions(final Options options) throws IllegalArgumentException {
 230  
 
 231  9
         final Option data = OptionBuilder.withArgName("path").hasArg().withLongOpt(ArgumentName.DATA_DIRECTORY)
 232  
                 .withDescription("The location of the H2 Database file. This option should generally not be set.")
 233  
                 .create(ArgumentName.DATA_DIRECTORY_SHORT);
 234  
 
 235  9
         final Option connectionTimeout = OptionBuilder.withArgName("timeout").hasArg().withLongOpt(ArgumentName.CONNECTION_TIMEOUT)
 236  
                 .withDescription("The connection timeout (in milliseconds) to use when downloading resources.")
 237  
                 .create(ArgumentName.CONNECTION_TIMEOUT_SHORT);
 238  
 
 239  9
         final Option proxyUrl = OptionBuilder.withArgName("url").hasArg().withLongOpt(ArgumentName.PROXY_URL)
 240  
                 .withDescription("The proxy url to use when downloading resources.")
 241  
                 .create(ArgumentName.PROXY_URL_SHORT);
 242  
 
 243  9
         final Option proxyPort = OptionBuilder.withArgName("port").hasArg().withLongOpt(ArgumentName.PROXY_PORT)
 244  
                 .withDescription("The proxy port to use when downloading resources.")
 245  
                 .create(ArgumentName.PROXY_PORT_SHORT);
 246  
 
 247  9
         final Option proxyUsername = OptionBuilder.withArgName("user").hasArg().withLongOpt(ArgumentName.PROXY_USERNAME)
 248  
                 .withDescription("The proxy username to use when downloading resources.")
 249  
                 .create();
 250  
 
 251  9
         final Option proxyPassword = OptionBuilder.withArgName("pass").hasArg().withLongOpt(ArgumentName.PROXY_PASSWORD)
 252  
                 .withDescription("The proxy password to use when downloading resources.")
 253  
                 .create();
 254  
 
 255  9
         final Option connectionString = OptionBuilder.withArgName("connStr").hasArg().withLongOpt(ArgumentName.CONNECTION_STRING)
 256  
                 .withDescription("The connection string to the database.")
 257  
                 .create();
 258  
 
 259  9
         final Option dbUser = OptionBuilder.withArgName("user").hasArg().withLongOpt(ArgumentName.DB_NAME)
 260  
                 .withDescription("The username used to connect to the database.")
 261  
                 .create();
 262  
 
 263  9
         final Option dbPassword = OptionBuilder.withArgName("password").hasArg().withLongOpt(ArgumentName.DB_PASSWORD)
 264  
                 .withDescription("The password for connecting to the database.")
 265  
                 .create();
 266  
 
 267  9
         final Option dbDriver = OptionBuilder.withArgName("driver").hasArg().withLongOpt(ArgumentName.DB_DRIVER)
 268  
                 .withDescription("The database driver name.")
 269  
                 .create();
 270  
 
 271  9
         final Option dbDriverPath = OptionBuilder.withArgName("path").hasArg().withLongOpt(ArgumentName.DB_DRIVER_PATH)
 272  
                 .withDescription("The path to the database driver; note, this does not need to be set unless the JAR is outside of the classpath.")
 273  
                 .create();
 274  
 
 275  9
         final Option disableNexusAnalyzer = OptionBuilder.withLongOpt(ArgumentName.DISABLE_NEXUS)
 276  
                 .withDescription("Disable the Nexus Analyzer.")
 277  
                 .create();
 278  
 
 279  9
         final Option nexusUrl = OptionBuilder.withArgName("url").hasArg().withLongOpt(ArgumentName.NEXUS_URL)
 280  
                 .withDescription("The url to the Nexus Server.")
 281  
                 .create();
 282  
 
 283  9
         final Option nexusUsesProxy = OptionBuilder.withArgName("true/false").hasArg().withLongOpt(ArgumentName.NEXUS_USES_PROXY)
 284  
                 .withDescription("Whether or not the configured proxy should be used when connecting to Nexus.")
 285  
                 .create();
 286  
 
 287  9
         final Option additionalZipExtensions = OptionBuilder.withArgName("extensions").hasArg()
 288  
                 .withLongOpt(ArgumentName.ADDITIONAL_ZIP_EXTENSIONS)
 289  
                 .withDescription("A comma seperated list of additional extensions to be scanned as ZIP files "
 290  
                         + "(ZIP, EAR, WAR are already treated as zip files)")
 291  
                 .create();
 292  
 
 293  9
         final Option pathToMono = OptionBuilder.withArgName("path").hasArg().withLongOpt(ArgumentName.PATH_TO_MONO)
 294  
                 .withDescription("The path to Mono for .NET Assembly analysis on non-windows systems.")
 295  
                 .create();
 296  
 
 297  9
         options.addOption(proxyPort)
 298  
                 .addOption(proxyUrl)
 299  
                 .addOption(proxyUsername)
 300  
                 .addOption(proxyPassword)
 301  
                 .addOption(connectionTimeout)
 302  
                 .addOption(connectionString)
 303  
                 .addOption(dbUser)
 304  
                 .addOption(data)
 305  
                 .addOption(dbPassword)
 306  
                 .addOption(dbDriver)
 307  
                 .addOption(dbDriverPath)
 308  
                 .addOption(disableNexusAnalyzer)
 309  
                 .addOption(nexusUrl)
 310  
                 .addOption(nexusUsesProxy)
 311  
                 .addOption(additionalZipExtensions)
 312  
                 .addOption(pathToMono);
 313  9
     }
 314  
 
 315  
     /**
 316  
      * Determines if the 'version' command line argument was passed in.
 317  
      *
 318  
      * @return whether or not the 'version' command line argument was passed in
 319  
      */
 320  
     public boolean isGetVersion() {
 321  7
         return (line != null) && line.hasOption(ArgumentName.VERSION);
 322  
     }
 323  
 
 324  
     /**
 325  
      * Determines if the 'help' command line argument was passed in.
 326  
      *
 327  
      * @return whether or not the 'help' command line argument was passed in
 328  
      */
 329  
     public boolean isGetHelp() {
 330  7
         return (line != null) && line.hasOption(ArgumentName.HELP);
 331  
     }
 332  
 
 333  
     /**
 334  
      * Determines if the 'scan' command line argument was passed in.
 335  
      *
 336  
      * @return whether or not the 'scan' command line argument was passed in
 337  
      */
 338  
     public boolean isRunScan() {
 339  15
         return (line != null) && isValid && line.hasOption(ArgumentName.SCAN);
 340  
     }
 341  
 
 342  
     /**
 343  
      * Returns true if the disableNexus command line argument was specified.
 344  
      *
 345  
      * @return true if the disableNexus command line argument was specified; otherwise false
 346  
      */
 347  
     public boolean isNexusDisabled() {
 348  0
         return (line != null) && line.hasOption(ArgumentName.DISABLE_NEXUS);
 349  
     }
 350  
 
 351  
     /**
 352  
      * Returns the url to the nexus server if one was specified.
 353  
      *
 354  
      * @return the url to the nexus server; if none was specified this will return null;
 355  
      */
 356  
     public String getNexusUrl() {
 357  0
         if (line == null || !line.hasOption(ArgumentName.NEXUS_URL)) {
 358  0
             return null;
 359  
         } else {
 360  0
             return line.getOptionValue(ArgumentName.NEXUS_URL);
 361  
         }
 362  
     }
 363  
 
 364  
     /**
 365  
      * Returns true if the Nexus Analyzer should use the configured proxy to connect to Nexus; otherwise false is
 366  
      * returned.
 367  
      *
 368  
      * @return true if the Nexus Analyzer should use the configured proxy to connect to Nexus; otherwise false
 369  
      */
 370  
     public boolean isNexusUsesProxy() {
 371  
         // If they didn't specify whether Nexus needs to use the proxy, we should
 372  
         // still honor the property if it's set.
 373  0
         if (line == null || !line.hasOption(ArgumentName.NEXUS_USES_PROXY)) {
 374  
             try {
 375  0
                 return Settings.getBoolean(Settings.KEYS.ANALYZER_NEXUS_PROXY);
 376  0
             } catch (InvalidSettingException ise) {
 377  0
                 return true;
 378  
             }
 379  
         } else {
 380  0
             return Boolean.parseBoolean(line.getOptionValue(ArgumentName.NEXUS_USES_PROXY));
 381  
         }
 382  
     }
 383  
 
 384  
     /**
 385  
      * Displays the command line help message to the standard output.
 386  
      */
 387  
     public void printHelp() {
 388  2
         final HelpFormatter formatter = new HelpFormatter();
 389  2
         final Options options = new Options();
 390  2
         addStandardOptions(options);
 391  2
         if (line != null && line.hasOption(ArgumentName.ADVANCED_HELP)) {
 392  0
             addAdvancedOptions(options);
 393  
         }
 394  2
         final String helpMsg = String.format("%n%s"
 395  
                 + " can be used to identify if there are any known CVE vulnerabilities in libraries utilized by an application. "
 396  
                 + "%s will automatically update required data from the Internet, such as the CVE and CPE data files from nvd.nist.gov.%n%n",
 397  
                 Settings.getString("application.name", "DependencyCheck"),
 398  
                 Settings.getString("application.name", "DependencyCheck"));
 399  
 
 400  2
         formatter.printHelp(Settings.getString("application.name", "DependencyCheck"),
 401  
                 helpMsg,
 402  
                 options,
 403  
                 "",
 404  
                 true);
 405  
 
 406  2
     }
 407  
 
 408  
     /**
 409  
      * Retrieves the file command line parameter(s) specified for the 'scan' argument.
 410  
      *
 411  
      * @return the file paths specified on the command line for scan
 412  
      */
 413  
     public String[] getScanFiles() {
 414  3
         return line.getOptionValues(ArgumentName.SCAN);
 415  
     }
 416  
 
 417  
     /**
 418  
      * Returns the directory to write the reports to specified on the command line.
 419  
      *
 420  
      * @return the path to the reports directory.
 421  
      */
 422  
     public String getReportDirectory() {
 423  1
         return line.getOptionValue(ArgumentName.OUT, ".");
 424  
     }
 425  
 
 426  
     /**
 427  
      * Returns the path to Mono for .NET Assembly analysis on non-windows systems.
 428  
      *
 429  
      * @return the path to Mono
 430  
      */
 431  
     public String getPathToMono() {
 432  1
         return line.getOptionValue(ArgumentName.PATH_TO_MONO);
 433  
     }
 434  
 
 435  
     /**
 436  
      * Returns the output format specified on the command line. Defaults to HTML if no format was specified.
 437  
      *
 438  
      * @return the output format name.
 439  
      */
 440  
     public String getReportFormat() {
 441  0
         return line.getOptionValue(ArgumentName.OUTPUT_FORMAT, "HTML");
 442  
     }
 443  
 
 444  
     /**
 445  
      * Returns the application name specified on the command line.
 446  
      *
 447  
      * @return the application name.
 448  
      */
 449  
     public String getApplicationName() {
 450  0
         return line.getOptionValue(ArgumentName.APP_NAME);
 451  
     }
 452  
 
 453  
     /**
 454  
      * Returns the connection timeout.
 455  
      *
 456  
      * @return the connection timeout
 457  
      */
 458  
     public String getConnectionTimeout() {
 459  0
         return line.getOptionValue(ArgumentName.CONNECTION_TIMEOUT);
 460  
     }
 461  
 
 462  
     /**
 463  
      * Returns the proxy url.
 464  
      *
 465  
      * @return the proxy url
 466  
      */
 467  
     public String getProxyUrl() {
 468  0
         return line.getOptionValue(ArgumentName.PROXY_URL);
 469  
     }
 470  
 
 471  
     /**
 472  
      * Returns the proxy port.
 473  
      *
 474  
      * @return the proxy port
 475  
      */
 476  
     public String getProxyPort() {
 477  0
         return line.getOptionValue(ArgumentName.PROXY_PORT);
 478  
     }
 479  
 
 480  
     /**
 481  
      * Returns the proxy username.
 482  
      *
 483  
      * @return the proxy username
 484  
      */
 485  
     public String getProxyUsername() {
 486  0
         return line.getOptionValue(ArgumentName.PROXY_USERNAME);
 487  
     }
 488  
 
 489  
     /**
 490  
      * Returns the proxy password.
 491  
      *
 492  
      * @return the proxy password
 493  
      */
 494  
     public String getProxyPassword() {
 495  0
         return line.getOptionValue(ArgumentName.PROXY_PASSWORD);
 496  
     }
 497  
 
 498  
     /**
 499  
      * Get the value of dataDirectory.
 500  
      *
 501  
      * @return the value of dataDirectory
 502  
      */
 503  
     public String getDataDirectory() {
 504  0
         return line.getOptionValue(ArgumentName.DATA_DIRECTORY);
 505  
     }
 506  
 
 507  
     /**
 508  
      * Returns the properties file specified on the command line.
 509  
      *
 510  
      * @return the properties file specified on the command line
 511  
      */
 512  
     public File getPropertiesFile() {
 513  0
         final String path = line.getOptionValue(ArgumentName.PROP);
 514  0
         if (path != null) {
 515  0
             return new File(path);
 516  
         }
 517  0
         return null;
 518  
     }
 519  
 
 520  
     /**
 521  
      * Returns the path to the verbose log file.
 522  
      *
 523  
      * @return the path to the verbose log file
 524  
      */
 525  
     public String getVerboseLog() {
 526  0
         return line.getOptionValue(ArgumentName.VERBOSE_LOG);
 527  
     }
 528  
 
 529  
     /**
 530  
      * Returns the path to the suppression file.
 531  
      *
 532  
      * @return the path to the suppression file
 533  
      */
 534  
     public String getSuppressionFile() {
 535  0
         return line.getOptionValue(ArgumentName.SUPPRESION_FILE);
 536  
     }
 537  
 
 538  
     /**
 539  
      * <p>
 540  
      * Prints the manifest information to standard output.</p>
 541  
      * <ul><li>Implementation-Title: ${pom.name}</li>
 542  
      * <li>Implementation-Version: ${pom.version}</li></ul>
 543  
      */
 544  
     public void printVersionInfo() {
 545  1
         final String version = String.format("%s version %s",
 546  
                 Settings.getString("application.name", "DependencyCheck"),
 547  
                 Settings.getString("application.version", "Unknown"));
 548  1
         System.out.println(version);
 549  1
     }
 550  
 
 551  
     /**
 552  
      * Checks if the auto update feature has been disabled. If it has been disabled via the command line this will
 553  
      * return false.
 554  
      *
 555  
      * @return if auto-update is allowed.
 556  
      */
 557  
     public boolean isAutoUpdate() {
 558  0
         return (line == null) || !line.hasOption(ArgumentName.DISABLE_AUTO_UPDATE);
 559  
     }
 560  
 
 561  
     /**
 562  
      * Returns the database driver name if specified; otherwise null is returned.
 563  
      *
 564  
      * @return the database driver name if specified; otherwise null is returned
 565  
      */
 566  
     public String getDatabaseDriverName() {
 567  0
         return line.getOptionValue(ArgumentName.DB_DRIVER);
 568  
     }
 569  
 
 570  
     /**
 571  
      * Returns the database driver path if specified; otherwise null is returned.
 572  
      *
 573  
      * @return the database driver name if specified; otherwise null is returned
 574  
      */
 575  
     public String getDatabaseDriverPath() {
 576  0
         return line.getOptionValue(ArgumentName.DB_DRIVER_PATH);
 577  
     }
 578  
 
 579  
     /**
 580  
      * Returns the database connection string if specified; otherwise null is returned.
 581  
      *
 582  
      * @return the database connection string if specified; otherwise null is returned
 583  
      */
 584  
     public String getConnectionString() {
 585  0
         return line.getOptionValue(ArgumentName.CONNECTION_STRING);
 586  
     }
 587  
 
 588  
     /**
 589  
      * Returns the database database user name if specified; otherwise null is returned.
 590  
      *
 591  
      * @return the database database user name if specified; otherwise null is returned
 592  
      */
 593  
     public String getDatabaseUser() {
 594  0
         return line.getOptionValue(ArgumentName.DB_NAME);
 595  
     }
 596  
 
 597  
     /**
 598  
      * Returns the database database password if specified; otherwise null is returned.
 599  
      *
 600  
      * @return the database database password if specified; otherwise null is returned
 601  
      */
 602  
     public String getDatabasePassword() {
 603  0
         return line.getOptionValue(ArgumentName.DB_PASSWORD);
 604  
     }
 605  
 
 606  
     /**
 607  
      * Returns the additional Extensions if specified; otherwise null is returned.
 608  
      *
 609  
      * @return the additional Extensions; otherwise null is returned
 610  
      */
 611  
     public String getAdditionalZipExtensions() {
 612  0
         return line.getOptionValue(ArgumentName.ADDITIONAL_ZIP_EXTENSIONS);
 613  
     }
 614  
 
 615  
     /**
 616  
      * A collection of static final strings that represent the possible command line arguments.
 617  
      */
 618  
     public static class ArgumentName {
 619  
 
 620  
         /**
 621  
          * The long CLI argument name specifying the directory/file to scan.
 622  
          */
 623  
         public static final String SCAN = "scan";
 624  
         /**
 625  
          * The short CLI argument name specifying the directory/file to scan.
 626  
          */
 627  
         public static final String SCAN_SHORT = "s";
 628  
         /**
 629  
          * The long CLI argument name specifying that the CPE/CVE/etc. data should not be automatically updated.
 630  
          */
 631  
         public static final String DISABLE_AUTO_UPDATE = "noupdate";
 632  
         /**
 633  
          * The short CLI argument name specifying that the CPE/CVE/etc. data should not be automatically updated.
 634  
          */
 635  
         public static final String DISABLE_AUTO_UPDATE_SHORT = "n";
 636  
         /**
 637  
          * The long CLI argument name specifying the directory to write the reports to.
 638  
          */
 639  
         public static final String OUT = "out";
 640  
         /**
 641  
          * The short CLI argument name specifying the directory to write the reports to.
 642  
          */
 643  
         public static final String OUT_SHORT = "o";
 644  
         /**
 645  
          * The long CLI argument name specifying the output format to write the reports to.
 646  
          */
 647  
         public static final String OUTPUT_FORMAT = "format";
 648  
         /**
 649  
          * The short CLI argument name specifying the output format to write the reports to.
 650  
          */
 651  
         public static final String OUTPUT_FORMAT_SHORT = "f";
 652  
         /**
 653  
          * The long CLI argument name specifying the name of the application to be scanned.
 654  
          */
 655  
         public static final String APP_NAME = "app";
 656  
         /**
 657  
          * The short CLI argument name specifying the name of the application to be scanned.
 658  
          */
 659  
         public static final String APP_NAME_SHORT = "a";
 660  
         /**
 661  
          * The long CLI argument name asking for help.
 662  
          */
 663  
         public static final String HELP = "help";
 664  
         /**
 665  
          * The long CLI argument name asking for advanced help.
 666  
          */
 667  
         public static final String ADVANCED_HELP = "advancedHelp";
 668  
         /**
 669  
          * The short CLI argument name asking for help.
 670  
          */
 671  
         public static final String HELP_SHORT = "h";
 672  
         /**
 673  
          * The long CLI argument name asking for the version.
 674  
          */
 675  
         public static final String VERSION_SHORT = "v";
 676  
         /**
 677  
          * The short CLI argument name asking for the version.
 678  
          */
 679  
         public static final String VERSION = "version";
 680  
         /**
 681  
          * The short CLI argument name indicating the proxy port.
 682  
          */
 683  
         public static final String PROXY_PORT_SHORT = "p";
 684  
         /**
 685  
          * The CLI argument name indicating the proxy port.
 686  
          */
 687  
         public static final String PROXY_PORT = "proxyport";
 688  
         /**
 689  
          * The short CLI argument name indicating the proxy url.
 690  
          */
 691  
         public static final String PROXY_URL_SHORT = "u";
 692  
         /**
 693  
          * The CLI argument name indicating the proxy url.
 694  
          */
 695  
         public static final String PROXY_URL = "proxyurl";
 696  
         /**
 697  
          * The CLI argument name indicating the proxy username.
 698  
          */
 699  
         public static final String PROXY_USERNAME = "proxyuser";
 700  
         /**
 701  
          * The CLI argument name indicating the proxy password.
 702  
          */
 703  
         public static final String PROXY_PASSWORD = "proxypass";
 704  
         /**
 705  
          * The short CLI argument name indicating the connection timeout.
 706  
          */
 707  
         public static final String CONNECTION_TIMEOUT_SHORT = "c";
 708  
         /**
 709  
          * The CLI argument name indicating the connection timeout.
 710  
          */
 711  
         public static final String CONNECTION_TIMEOUT = "connectiontimeout";
 712  
         /**
 713  
          * The short CLI argument name for setting the location of an additional properties file.
 714  
          */
 715  
         public static final String PROP_SHORT = "P";
 716  
         /**
 717  
          * The CLI argument name for setting the location of an additional properties file.
 718  
          */
 719  
         public static final String PROP = "propertyfile";
 720  
         /**
 721  
          * The CLI argument name for setting the location of the data directory.
 722  
          */
 723  
         public static final String DATA_DIRECTORY = "data";
 724  
         /**
 725  
          * The short CLI argument name for setting the location of the data directory.
 726  
          */
 727  
         public static final String DATA_DIRECTORY_SHORT = "d";
 728  
         /**
 729  
          * The CLI argument name for setting the location of the data directory.
 730  
          */
 731  
         public static final String VERBOSE_LOG = "log";
 732  
         /**
 733  
          * The short CLI argument name for setting the location of the data directory.
 734  
          */
 735  
         public static final String VERBOSE_LOG_SHORT = "l";
 736  
         /**
 737  
          * The CLI argument name for setting the location of the suppression file.
 738  
          */
 739  
         public static final String SUPPRESION_FILE = "suppression";
 740  
         /**
 741  
          * Disables the Nexus Analyzer.
 742  
          */
 743  
         public static final String DISABLE_NEXUS = "disableNexus";
 744  
         /**
 745  
          * The URL of the nexus server.
 746  
          */
 747  
         public static final String NEXUS_URL = "nexus";
 748  
         /**
 749  
          * Whether or not the defined proxy should be used when connecting to Nexus.
 750  
          */
 751  
         public static final String NEXUS_USES_PROXY = "nexusUsesProxy";
 752  
         /**
 753  
          * The CLI argument name for setting the connection string.
 754  
          */
 755  
         public static final String CONNECTION_STRING = "connectionString";
 756  
         /**
 757  
          * The CLI argument name for setting the database user name.
 758  
          */
 759  
         public static final String DB_NAME = "dbUser";
 760  
         /**
 761  
          * The CLI argument name for setting the database password.
 762  
          */
 763  
         public static final String DB_PASSWORD = "dbPassword";
 764  
         /**
 765  
          * The CLI argument name for setting the database driver name.
 766  
          */
 767  
         public static final String DB_DRIVER = "dbDriverName";
 768  
         /**
 769  
          * The CLI argument name for setting the path to the database driver; in case it is not on the class path.
 770  
          */
 771  
         public static final String DB_DRIVER_PATH = "dbDriverPath";
 772  
         /**
 773  
          * The CLI argument name for setting the path to mono for .NET Assembly analysis on non-windows systems.
 774  
          */
 775  
         public static final String PATH_TO_MONO = "mono";
 776  
         /**
 777  
          * The CLI argument name for setting extra extensions.
 778  
          */
 779  
         public static final String ADDITIONAL_ZIP_EXTENSIONS = "zipExtensions";
 780  
     }
 781  
 }