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