Coverage Report - org.owasp.dependencycheck.CliParser
 
Classes in this File Line Coverage Branch Coverage Complexity
CliParser
61%
97/158
35%
35/98
2.159
CliParser$ARGUMENT
N/A
N/A
2.159
 
 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;
 19  
 
 20  
 import java.io.File;
 21  
 import java.io.FileNotFoundException;
 22  
 import java.util.logging.Logger;
 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 logger.
 45  
      */
 46  1
     private static final Logger LOGGER = Logger.getLogger(CliParser.class.getName());
 47  
     /**
 48  
      * The command line.
 49  
      */
 50  
     private CommandLine line;
 51  
     /**
 52  
      * Indicates whether the arguments are valid.
 53  
      */
 54  
     private boolean isValid = true;
 55  
 
 56  
     /**
 57  
      * Parses the arguments passed in and captures the results for later use.
 58  
      *
 59  
      * @param args the command line arguments
 60  
      * @throws FileNotFoundException is thrown when a 'file' argument does not point to a file that exists.
 61  
      * @throws ParseException is thrown when a Parse Exception occurs.
 62  
      */
 63  
     public void parse(String[] args) throws FileNotFoundException, ParseException {
 64  9
         line = parseArgs(args);
 65  
 
 66  7
         if (line != null) {
 67  7
             validateArgs();
 68  
         }
 69  6
     }
 70  
 
 71  
     /**
 72  
      * Parses the command line arguments.
 73  
      *
 74  
      * @param args the command line arguments
 75  
      * @return the results of parsing the command line arguments
 76  
      * @throws ParseException if the arguments are invalid
 77  
      */
 78  
     private CommandLine parseArgs(String[] args) throws ParseException {
 79  9
         final CommandLineParser parser = new PosixParser();
 80  9
         final Options options = createCommandLineOptions();
 81  9
         return parser.parse(options, args);
 82  
     }
 83  
 
 84  
     /**
 85  
      * Validates that the command line arguments are valid.
 86  
      *
 87  
      * @throws FileNotFoundException if there is a file specified by either the SCAN or CPE command line arguments that
 88  
      * does not exist.
 89  
      * @throws ParseException is thrown if there is an exception parsing the command line.
 90  
      */
 91  
     private void validateArgs() throws FileNotFoundException, ParseException {
 92  7
         if (isRunScan()) {
 93  2
             validatePathExists(getScanFiles(), ARGUMENT.SCAN);
 94  1
             validatePathExists(getReportDirectory(), ARGUMENT.OUT);
 95  1
             if (getPathToMono() != null) {
 96  0
                 validatePathExists(getPathToMono(), ARGUMENT.PATH_TO_MONO);
 97  
             }
 98  1
             if (!line.hasOption(ARGUMENT.APP_NAME)) {
 99  0
                 throw new ParseException("Missing 'app' argument; the scan cannot be run without the an application name.");
 100  
             }
 101  1
             if (line.hasOption(ARGUMENT.OUTPUT_FORMAT)) {
 102  0
                 final String format = line.getOptionValue(ARGUMENT.OUTPUT_FORMAT);
 103  
                 try {
 104  0
                     Format.valueOf(format);
 105  0
                 } catch (IllegalArgumentException ex) {
 106  0
                     final String msg = String.format("An invalid 'format' of '%s' was specified. "
 107  
                             + "Supported output formats are XML, HTML, VULN, or ALL", format);
 108  0
                     throw new ParseException(msg);
 109  0
                 }
 110  
             }
 111  
         }
 112  6
     }
 113  
 
 114  
     /**
 115  
      * Validates whether or not the path(s) points at a file that exists; if the path(s) does not point to an existing
 116  
      * file a FileNotFoundException is thrown.
 117  
      *
 118  
      * @param paths the paths to validate if they exists
 119  
      * @param optType the option being validated (e.g. scan, out, etc.)
 120  
      * @throws FileNotFoundException is thrown if one of the paths being validated does not exist.
 121  
      */
 122  
     private void validatePathExists(String[] paths, String optType) throws FileNotFoundException {
 123  3
         for (String path : paths) {
 124  2
             validatePathExists(path, optType);
 125  
         }
 126  1
     }
 127  
 
 128  
     /**
 129  
      * Validates whether or not the path points at a file that exists; if the path does not point to an existing file a
 130  
      * FileNotFoundException is thrown.
 131  
      *
 132  
      * @param path the paths to validate if they exists
 133  
      * @param argumentName the argument being validated (e.g. scan, out, etc.)
 134  
      * @throws FileNotFoundException is thrown if the path being validated does not exist.
 135  
      */
 136  
     private void validatePathExists(String path, String argumentName) throws FileNotFoundException {
 137  3
         if (path == null) {
 138  0
             isValid = false;
 139  0
             final String msg = String.format("Invalid '%s' argument: null", argumentName);
 140  0
             throw new FileNotFoundException(msg);
 141  3
         } else if (!path.contains("*") && !path.contains("?")) {
 142  3
             File f = new File(path);
 143  3
             if ("o".equals(argumentName.substring(0, 1).toLowerCase()) && !"ALL".equals(this.getReportFormat().toUpperCase())) {
 144  1
                 final String checkPath = path.toLowerCase();
 145  1
                 if (checkPath.endsWith(".html") || checkPath.endsWith(".xml") || checkPath.endsWith(".htm")) {
 146  0
                     if (f.getParentFile() == null) {
 147  0
                         f = new File(".", path);
 148  
                     }
 149  0
                     if (!f.getParentFile().isDirectory()) {
 150  0
                         isValid = false;
 151  0
                         final String msg = String.format("Invalid '%s' argument: '%s'", argumentName, path);
 152  0
                         throw new FileNotFoundException(msg);
 153  
                     }
 154  
                 }
 155  1
             } else {
 156  2
                 if (!f.exists()) {
 157  1
                     isValid = false;
 158  1
                     final String msg = String.format("Invalid '%s' argument: '%s'", argumentName, path);
 159  1
                     throw new FileNotFoundException(msg);
 160  
                 }
 161  
             }
 162  2
         } else if (path.startsWith("//") || path.startsWith("\\\\")) {
 163  0
             isValid = false;
 164  0
             final String msg = String.format("Invalid '%s' argument: '%s'%nUnable to scan paths that start with '//'.", argumentName, path);
 165  0
             throw new FileNotFoundException(msg);
 166  
         }
 167  2
     }
 168  
 
 169  
     /**
 170  
      * Generates an Options collection that is used to parse the command line and to display the help message.
 171  
      *
 172  
      * @return the command line options used for parsing the command line
 173  
      */
 174  
     @SuppressWarnings("static-access")
 175  
     private Options createCommandLineOptions() {
 176  9
         final Options options = new Options();
 177  9
         addStandardOptions(options);
 178  9
         addAdvancedOptions(options);
 179  9
         addDeprecatedOptions(options);
 180  9
         return options;
 181  
     }
 182  
 
 183  
     /**
 184  
      * Adds the standard command line options to the given options collection.
 185  
      *
 186  
      * @param options a collection of command line arguments
 187  
      * @throws IllegalArgumentException thrown if there is an exception
 188  
      */
 189  
     @SuppressWarnings("static-access")
 190  
     private void addStandardOptions(final Options options) throws IllegalArgumentException {
 191  11
         final Option help = new Option(ARGUMENT.HELP_SHORT, ARGUMENT.HELP, false,
 192  
                 "Print this message.");
 193  
 
 194  11
         final Option advancedHelp = OptionBuilder.withLongOpt(ARGUMENT.ADVANCED_HELP)
 195  
                 .withDescription("Print the advanced help message.").create();
 196  
 
 197  11
         final Option version = new Option(ARGUMENT.VERSION_SHORT, ARGUMENT.VERSION,
 198  
                 false, "Print the version information.");
 199  
 
 200  11
         final Option noUpdate = new Option(ARGUMENT.DISABLE_AUTO_UPDATE_SHORT, ARGUMENT.DISABLE_AUTO_UPDATE,
 201  
                 false, "Disables the automatic updating of the CPE data.");
 202  
 
 203  11
         final Option appName = OptionBuilder.withArgName("name").hasArg().withLongOpt(ARGUMENT.APP_NAME)
 204  
                 .withDescription("The name of the application being scanned. This is a required argument.")
 205  
                 .create(ARGUMENT.APP_NAME_SHORT);
 206  
 
 207  11
         final Option path = OptionBuilder.withArgName("path").hasArg().withLongOpt(ARGUMENT.SCAN)
 208  
                 .withDescription("The path to scan - this option can be specified multiple times. Ant style"
 209  
                         + " paths are supported (e.g. path/**/*.jar).")
 210  
                 .create(ARGUMENT.SCAN_SHORT);
 211  
 
 212  11
         final Option excludes = OptionBuilder.withArgName("pattern").hasArg().withLongOpt(ARGUMENT.EXCLUDE)
 213  
                 .withDescription("Specify and exclusion pattern. This option can be specified multiple times"
 214  
                         + " and it accepts Ant style excludsions.")
 215  
                 .create();
 216  
 
 217  11
         final Option props = OptionBuilder.withArgName("file").hasArg().withLongOpt(ARGUMENT.PROP)
 218  
                 .withDescription("A property file to load.")
 219  
                 .create(ARGUMENT.PROP_SHORT);
 220  
 
 221  11
         final Option out = OptionBuilder.withArgName("path").hasArg().withLongOpt(ARGUMENT.OUT)
 222  
                 .withDescription("The folder to write reports to. This defaults to the current directory. "
 223  
                         + "It is possible to set this to a specific file name if the format argument is not set to ALL.")
 224  
                 .create(ARGUMENT.OUT_SHORT);
 225  
 
 226  11
         final Option outputFormat = OptionBuilder.withArgName("format").hasArg().withLongOpt(ARGUMENT.OUTPUT_FORMAT)
 227  
                 .withDescription("The output format to write to (XML, HTML, VULN, ALL). The default is HTML.")
 228  
                 .create(ARGUMENT.OUTPUT_FORMAT_SHORT);
 229  
 
 230  11
         final Option verboseLog = OptionBuilder.withArgName("file").hasArg().withLongOpt(ARGUMENT.VERBOSE_LOG)
 231  
                 .withDescription("The file path to write verbose logging information.")
 232  
                 .create(ARGUMENT.VERBOSE_LOG_SHORT);
 233  
 
 234  11
         final Option suppressionFile = OptionBuilder.withArgName("file").hasArg().withLongOpt(ARGUMENT.SUPPRESSION_FILE)
 235  
                 .withDescription("The file path to the suppression XML file.")
 236  
                 .create();
 237  
 
 238  
         //This is an option group because it can be specified more then once.
 239  11
         final OptionGroup og = new OptionGroup();
 240  11
         og.addOption(path);
 241  
 
 242  11
         final OptionGroup exog = new OptionGroup();
 243  11
         exog.addOption(excludes);
 244  
 
 245  11
         options.addOptionGroup(og)
 246  
                 .addOptionGroup(exog)
 247  
                 .addOption(out)
 248  
                 .addOption(outputFormat)
 249  
                 .addOption(appName)
 250  
                 .addOption(version)
 251  
                 .addOption(help)
 252  
                 .addOption(advancedHelp)
 253  
                 .addOption(noUpdate)
 254  
                 .addOption(props)
 255  
                 .addOption(verboseLog)
 256  
                 .addOption(suppressionFile);
 257  11
     }
 258  
 
 259  
     /**
 260  
      * Adds the advanced command line options to the given options collection. These are split out for purposes of being
 261  
      * able to display two different help messages.
 262  
      *
 263  
      * @param options a collection of command line arguments
 264  
      * @throws IllegalArgumentException thrown if there is an exception
 265  
      */
 266  
     @SuppressWarnings("static-access")
 267  
     private void addAdvancedOptions(final Options options) throws IllegalArgumentException {
 268  
 
 269  9
         final Option data = OptionBuilder.withArgName("path").hasArg().withLongOpt(ARGUMENT.DATA_DIRECTORY)
 270  
                 .withDescription("The location of the H2 Database file. This option should generally not be set.")
 271  
                 .create(ARGUMENT.DATA_DIRECTORY_SHORT);
 272  
 
 273  9
         final Option connectionTimeout = OptionBuilder.withArgName("timeout").hasArg().withLongOpt(ARGUMENT.CONNECTION_TIMEOUT)
 274  
                 .withDescription("The connection timeout (in milliseconds) to use when downloading resources.")
 275  
                 .create(ARGUMENT.CONNECTION_TIMEOUT_SHORT);
 276  
 
 277  9
         final Option proxyServer = OptionBuilder.withArgName("server").hasArg().withLongOpt(ARGUMENT.PROXY_SERVER)
 278  
                 .withDescription("The proxy server to use when downloading resources.")
 279  
                 .create();
 280  
 
 281  9
         final Option proxyPort = OptionBuilder.withArgName("port").hasArg().withLongOpt(ARGUMENT.PROXY_PORT)
 282  
                 .withDescription("The proxy port to use when downloading resources.")
 283  
                 .create();
 284  
 
 285  9
         final Option proxyUsername = OptionBuilder.withArgName("user").hasArg().withLongOpt(ARGUMENT.PROXY_USERNAME)
 286  
                 .withDescription("The proxy username to use when downloading resources.")
 287  
                 .create();
 288  
 
 289  9
         final Option proxyPassword = OptionBuilder.withArgName("pass").hasArg().withLongOpt(ARGUMENT.PROXY_PASSWORD)
 290  
                 .withDescription("The proxy password to use when downloading resources.")
 291  
                 .create();
 292  
 
 293  9
         final Option connectionString = OptionBuilder.withArgName("connStr").hasArg().withLongOpt(ARGUMENT.CONNECTION_STRING)
 294  
                 .withDescription("The connection string to the database.")
 295  
                 .create();
 296  
 
 297  9
         final Option dbUser = OptionBuilder.withArgName("user").hasArg().withLongOpt(ARGUMENT.DB_NAME)
 298  
                 .withDescription("The username used to connect to the database.")
 299  
                 .create();
 300  
 
 301  9
         final Option dbPassword = OptionBuilder.withArgName("password").hasArg().withLongOpt(ARGUMENT.DB_PASSWORD)
 302  
                 .withDescription("The password for connecting to the database.")
 303  
                 .create();
 304  
 
 305  9
         final Option dbDriver = OptionBuilder.withArgName("driver").hasArg().withLongOpt(ARGUMENT.DB_DRIVER)
 306  
                 .withDescription("The database driver name.")
 307  
                 .create();
 308  
 
 309  9
         final Option dbDriverPath = OptionBuilder.withArgName("path").hasArg().withLongOpt(ARGUMENT.DB_DRIVER_PATH)
 310  
                 .withDescription("The path to the database driver; note, this does not need to be set unless the JAR is outside of the classpath.")
 311  
                 .create();
 312  
 
 313  9
         final Option disableJarAnalyzer = OptionBuilder.withLongOpt(ARGUMENT.DISABLE_JAR)
 314  
                 .withDescription("Disable the Jar Analyzer.")
 315  
                 .create();
 316  9
         final Option disableArchiveAnalyzer = OptionBuilder.withLongOpt(ARGUMENT.DISABLE_ARCHIVE)
 317  
                 .withDescription("Disable the Archive Analyzer.")
 318  
                 .create();
 319  9
         final Option disableNuspecAnalyzer = OptionBuilder.withLongOpt(ARGUMENT.DISABLE_NUSPEC)
 320  
                 .withDescription("Disable the Nuspec Analyzer.")
 321  
                 .create();
 322  9
         final Option disableAssemblyAnalyzer = OptionBuilder.withLongOpt(ARGUMENT.DISABLE_ASSEMBLY)
 323  
                 .withDescription("Disable the .NET Assembly Analyzer.")
 324  
                 .create();
 325  
 
 326  9
         final Option disableCentralAnalyzer = OptionBuilder.withLongOpt(ARGUMENT.DISABLE_CENTRAL)
 327  
                 .withDescription("Disable the Central Analyzer. If this analyzer is disabled it is likely you also want to disable the Nexus Analyzer.")
 328  
                 .create();
 329  
 
 330  9
         final Option disableNexusAnalyzer = OptionBuilder.withLongOpt(ARGUMENT.DISABLE_NEXUS)
 331  
                 .withDescription("Disable the Nexus Analyzer.")
 332  
                 .create();
 333  
 
 334  9
         final Option nexusUrl = OptionBuilder.withArgName("url").hasArg().withLongOpt(ARGUMENT.NEXUS_URL)
 335  
                 .withDescription("The url to the Nexus Pro Server. If not set the Nexus Analyzer will be disabled.")
 336  
                 .create();
 337  
 
 338  9
         final Option nexusUsesProxy = OptionBuilder.withArgName("true/false").hasArg().withLongOpt(ARGUMENT.NEXUS_USES_PROXY)
 339  
                 .withDescription("Whether or not the configured proxy should be used when connecting to Nexus.")
 340  
                 .create();
 341  
 
 342  9
         final Option additionalZipExtensions = OptionBuilder.withArgName("extensions").hasArg()
 343  
                 .withLongOpt(ARGUMENT.ADDITIONAL_ZIP_EXTENSIONS)
 344  
                 .withDescription("A comma separated list of additional extensions to be scanned as ZIP files "
 345  
                         + "(ZIP, EAR, WAR are already treated as zip files)")
 346  
                 .create();
 347  
 
 348  9
         final Option pathToMono = OptionBuilder.withArgName("path").hasArg().withLongOpt(ARGUMENT.PATH_TO_MONO)
 349  
                 .withDescription("The path to Mono for .NET Assembly analysis on non-windows systems.")
 350  
                 .create();
 351  
 
 352  9
         options.addOption(proxyPort)
 353  
                 .addOption(proxyServer)
 354  
                 .addOption(proxyUsername)
 355  
                 .addOption(proxyPassword)
 356  
                 .addOption(connectionTimeout)
 357  
                 .addOption(connectionString)
 358  
                 .addOption(dbUser)
 359  
                 .addOption(data)
 360  
                 .addOption(dbPassword)
 361  
                 .addOption(dbDriver)
 362  
                 .addOption(dbDriverPath)
 363  
                 .addOption(disableJarAnalyzer)
 364  
                 .addOption(disableArchiveAnalyzer)
 365  
                 .addOption(disableAssemblyAnalyzer)
 366  
                 .addOption(disableNuspecAnalyzer)
 367  
                 .addOption(disableCentralAnalyzer)
 368  
                 .addOption(disableNexusAnalyzer)
 369  
                 .addOption(nexusUrl)
 370  
                 .addOption(nexusUsesProxy)
 371  
                 .addOption(additionalZipExtensions)
 372  
                 .addOption(pathToMono);
 373  9
     }
 374  
 
 375  
     /**
 376  
      * Adds the deprecated command line options to the given options collection. These are split out for purposes of not
 377  
      * including them in the help message. We need to add the deprecated options so as not to break existing scripts.
 378  
      *
 379  
      * @param options a collection of command line arguments
 380  
      * @throws IllegalArgumentException thrown if there is an exception
 381  
      */
 382  
     @SuppressWarnings("static-access")
 383  
     private void addDeprecatedOptions(final Options options) throws IllegalArgumentException {
 384  
 
 385  9
         final Option proxyServer = OptionBuilder.withArgName("url").hasArg().withLongOpt(ARGUMENT.PROXY_URL)
 386  
                 .withDescription("The proxy url argument is deprecated, use proxyserver instead.")
 387  
                 .create();
 388  
 
 389  9
         options.addOption(proxyServer);
 390  9
     }
 391  
 
 392  
     /**
 393  
      * Determines if the 'version' command line argument was passed in.
 394  
      *
 395  
      * @return whether or not the 'version' command line argument was passed in
 396  
      */
 397  
     public boolean isGetVersion() {
 398  7
         return (line != null) && line.hasOption(ARGUMENT.VERSION);
 399  
     }
 400  
 
 401  
     /**
 402  
      * Determines if the 'help' command line argument was passed in.
 403  
      *
 404  
      * @return whether or not the 'help' command line argument was passed in
 405  
      */
 406  
     public boolean isGetHelp() {
 407  7
         return (line != null) && line.hasOption(ARGUMENT.HELP);
 408  
     }
 409  
 
 410  
     /**
 411  
      * Determines if the 'scan' command line argument was passed in.
 412  
      *
 413  
      * @return whether or not the 'scan' command line argument was passed in
 414  
      */
 415  
     public boolean isRunScan() {
 416  14
         return (line != null) && isValid && line.hasOption(ARGUMENT.SCAN);
 417  
     }
 418  
 
 419  
     /**
 420  
      * Returns true if the disableJar command line argument was specified.
 421  
      *
 422  
      * @return true if the disableJar command line argument was specified; otherwise false
 423  
      */
 424  
     public boolean isJarDisabled() {
 425  0
         return (line != null) && line.hasOption(ARGUMENT.DISABLE_JAR);
 426  
     }
 427  
 
 428  
     /**
 429  
      * Returns true if the disableArchive command line argument was specified.
 430  
      *
 431  
      * @return true if the disableArchive command line argument was specified; otherwise false
 432  
      */
 433  
     public boolean isArchiveDisabled() {
 434  0
         return (line != null) && line.hasOption(ARGUMENT.DISABLE_ARCHIVE);
 435  
     }
 436  
 
 437  
     /**
 438  
      * Returns true if the disableNuspec command line argument was specified.
 439  
      *
 440  
      * @return true if the disableNuspec command line argument was specified; otherwise false
 441  
      */
 442  
     public boolean isNuspecDisabled() {
 443  0
         return (line != null) && line.hasOption(ARGUMENT.DISABLE_NUSPEC);
 444  
     }
 445  
 
 446  
     /**
 447  
      * Returns true if the disableAssembly command line argument was specified.
 448  
      *
 449  
      * @return true if the disableAssembly command line argument was specified; otherwise false
 450  
      */
 451  
     public boolean isAssemblyDisabled() {
 452  0
         return (line != null) && line.hasOption(ARGUMENT.DISABLE_ASSEMBLY);
 453  
     }
 454  
 
 455  
     /**
 456  
      * Returns true if the disableNexus command line argument was specified.
 457  
      *
 458  
      * @return true if the disableNexus command line argument was specified; otherwise false
 459  
      */
 460  
     public boolean isNexusDisabled() {
 461  0
         return (line != null) && line.hasOption(ARGUMENT.DISABLE_NEXUS);
 462  
     }
 463  
 
 464  
     /**
 465  
      * Returns true if the disableCentral command line argument was specified.
 466  
      *
 467  
      * @return true if the disableCentral command line argument was specified; otherwise false
 468  
      */
 469  
     public boolean isCentralDisabled() {
 470  0
         return (line != null) && line.hasOption(ARGUMENT.DISABLE_CENTRAL);
 471  
     }
 472  
 
 473  
     /**
 474  
      * Returns the url to the nexus server if one was specified.
 475  
      *
 476  
      * @return the url to the nexus server; if none was specified this will return null;
 477  
      */
 478  
     public String getNexusUrl() {
 479  0
         if (line == null || !line.hasOption(ARGUMENT.NEXUS_URL)) {
 480  0
             return null;
 481  
         } else {
 482  0
             return line.getOptionValue(ARGUMENT.NEXUS_URL);
 483  
         }
 484  
     }
 485  
 
 486  
     /**
 487  
      * Returns true if the Nexus Analyzer should use the configured proxy to connect to Nexus; otherwise false is
 488  
      * returned.
 489  
      *
 490  
      * @return true if the Nexus Analyzer should use the configured proxy to connect to Nexus; otherwise false
 491  
      */
 492  
     public boolean isNexusUsesProxy() {
 493  
         // If they didn't specify whether Nexus needs to use the proxy, we should
 494  
         // still honor the property if it's set.
 495  0
         if (line == null || !line.hasOption(ARGUMENT.NEXUS_USES_PROXY)) {
 496  
             try {
 497  0
                 return Settings.getBoolean(Settings.KEYS.ANALYZER_NEXUS_PROXY);
 498  0
             } catch (InvalidSettingException ise) {
 499  0
                 return true;
 500  
             }
 501  
         } else {
 502  0
             return Boolean.parseBoolean(line.getOptionValue(ARGUMENT.NEXUS_USES_PROXY));
 503  
         }
 504  
     }
 505  
 
 506  
     /**
 507  
      * Displays the command line help message to the standard output.
 508  
      */
 509  
     public void printHelp() {
 510  2
         final HelpFormatter formatter = new HelpFormatter();
 511  2
         final Options options = new Options();
 512  2
         addStandardOptions(options);
 513  2
         if (line != null && line.hasOption(ARGUMENT.ADVANCED_HELP)) {
 514  0
             addAdvancedOptions(options);
 515  
         }
 516  2
         final String helpMsg = String.format("%n%s"
 517  
                 + " can be used to identify if there are any known CVE vulnerabilities in libraries utilized by an application. "
 518  
                 + "%s will automatically update required data from the Internet, such as the CVE and CPE data files from nvd.nist.gov.%n%n",
 519  
                 Settings.getString("application.name", "DependencyCheck"),
 520  
                 Settings.getString("application.name", "DependencyCheck"));
 521  
 
 522  2
         formatter.printHelp(Settings.getString("application.name", "DependencyCheck"),
 523  
                 helpMsg,
 524  
                 options,
 525  
                 "",
 526  
                 true);
 527  2
     }
 528  
 
 529  
     /**
 530  
      * Retrieves the file command line parameter(s) specified for the 'scan' argument.
 531  
      *
 532  
      * @return the file paths specified on the command line for scan
 533  
      */
 534  
     public String[] getScanFiles() {
 535  3
         return line.getOptionValues(ARGUMENT.SCAN);
 536  
     }
 537  
 
 538  
     /**
 539  
      * Retrieves the list of excluded file patterns specified by the 'exclude' argument.
 540  
      *
 541  
      * @return the excluded file patterns
 542  
      */
 543  
     public String[] getExcludeList() {
 544  0
         return line.getOptionValues(ARGUMENT.EXCLUDE);
 545  
     }
 546  
 
 547  
     /**
 548  
      * Returns the directory to write the reports to specified on the command line.
 549  
      *
 550  
      * @return the path to the reports directory.
 551  
      */
 552  
     public String getReportDirectory() {
 553  1
         return line.getOptionValue(ARGUMENT.OUT, ".");
 554  
     }
 555  
 
 556  
     /**
 557  
      * Returns the path to Mono for .NET Assembly analysis on non-windows systems.
 558  
      *
 559  
      * @return the path to Mono
 560  
      */
 561  
     public String getPathToMono() {
 562  1
         return line.getOptionValue(ARGUMENT.PATH_TO_MONO);
 563  
     }
 564  
 
 565  
     /**
 566  
      * Returns the output format specified on the command line. Defaults to HTML if no format was specified.
 567  
      *
 568  
      * @return the output format name.
 569  
      */
 570  
     public String getReportFormat() {
 571  1
         return line.getOptionValue(ARGUMENT.OUTPUT_FORMAT, "HTML");
 572  
     }
 573  
 
 574  
     /**
 575  
      * Returns the application name specified on the command line.
 576  
      *
 577  
      * @return the application name.
 578  
      */
 579  
     public String getApplicationName() {
 580  0
         return line.getOptionValue(ARGUMENT.APP_NAME);
 581  
     }
 582  
 
 583  
     /**
 584  
      * Returns the connection timeout.
 585  
      *
 586  
      * @return the connection timeout
 587  
      */
 588  
     public String getConnectionTimeout() {
 589  0
         return line.getOptionValue(ARGUMENT.CONNECTION_TIMEOUT);
 590  
     }
 591  
 
 592  
     /**
 593  
      * Returns the proxy server.
 594  
      *
 595  
      * @return the proxy server
 596  
      */
 597  
     public String getProxyServer() {
 598  
 
 599  0
         String server = line.getOptionValue(ARGUMENT.PROXY_SERVER);
 600  0
         if (server == null) {
 601  0
             server = line.getOptionValue(ARGUMENT.PROXY_URL);
 602  0
             if (server != null) {
 603  0
                 LOGGER.warning("An old command line argument 'proxyurl' was detected; use proxyserver instead");
 604  
             }
 605  
         }
 606  0
         return server;
 607  
     }
 608  
 
 609  
     /**
 610  
      * Returns the proxy port.
 611  
      *
 612  
      * @return the proxy port
 613  
      */
 614  
     public String getProxyPort() {
 615  0
         return line.getOptionValue(ARGUMENT.PROXY_PORT);
 616  
     }
 617  
 
 618  
     /**
 619  
      * Returns the proxy username.
 620  
      *
 621  
      * @return the proxy username
 622  
      */
 623  
     public String getProxyUsername() {
 624  0
         return line.getOptionValue(ARGUMENT.PROXY_USERNAME);
 625  
     }
 626  
 
 627  
     /**
 628  
      * Returns the proxy password.
 629  
      *
 630  
      * @return the proxy password
 631  
      */
 632  
     public String getProxyPassword() {
 633  0
         return line.getOptionValue(ARGUMENT.PROXY_PASSWORD);
 634  
     }
 635  
 
 636  
     /**
 637  
      * Get the value of dataDirectory.
 638  
      *
 639  
      * @return the value of dataDirectory
 640  
      */
 641  
     public String getDataDirectory() {
 642  0
         return line.getOptionValue(ARGUMENT.DATA_DIRECTORY);
 643  
     }
 644  
 
 645  
     /**
 646  
      * Returns the properties file specified on the command line.
 647  
      *
 648  
      * @return the properties file specified on the command line
 649  
      */
 650  
     public File getPropertiesFile() {
 651  0
         final String path = line.getOptionValue(ARGUMENT.PROP);
 652  0
         if (path != null) {
 653  0
             return new File(path);
 654  
         }
 655  0
         return null;
 656  
     }
 657  
 
 658  
     /**
 659  
      * Returns the path to the verbose log file.
 660  
      *
 661  
      * @return the path to the verbose log file
 662  
      */
 663  
     public String getVerboseLog() {
 664  0
         return line.getOptionValue(ARGUMENT.VERBOSE_LOG);
 665  
     }
 666  
 
 667  
     /**
 668  
      * Returns the path to the suppression file.
 669  
      *
 670  
      * @return the path to the suppression file
 671  
      */
 672  
     public String getSuppressionFile() {
 673  0
         return line.getOptionValue(ARGUMENT.SUPPRESSION_FILE);
 674  
     }
 675  
 
 676  
     /**
 677  
      * <p>
 678  
      * Prints the manifest information to standard output.</p>
 679  
      * <ul><li>Implementation-Title: ${pom.name}</li>
 680  
      * <li>Implementation-Version: ${pom.version}</li></ul>
 681  
      */
 682  
     public void printVersionInfo() {
 683  1
         final String version = String.format("%s version %s",
 684  
                 Settings.getString(Settings.KEYS.APPLICATION_VAME, "dependency-check"),
 685  
                 Settings.getString(Settings.KEYS.APPLICATION_VERSION, "Unknown"));
 686  1
         System.out.println(version);
 687  1
     }
 688  
 
 689  
     /**
 690  
      * Checks if the auto update feature has been disabled. If it has been disabled via the command line this will
 691  
      * return false.
 692  
      *
 693  
      * @return if auto-update is allowed.
 694  
      */
 695  
     public boolean isAutoUpdate() {
 696  0
         return (line == null) || !line.hasOption(ARGUMENT.DISABLE_AUTO_UPDATE);
 697  
     }
 698  
 
 699  
     /**
 700  
      * Returns the database driver name if specified; otherwise null is returned.
 701  
      *
 702  
      * @return the database driver name if specified; otherwise null is returned
 703  
      */
 704  
     public String getDatabaseDriverName() {
 705  0
         return line.getOptionValue(ARGUMENT.DB_DRIVER);
 706  
     }
 707  
 
 708  
     /**
 709  
      * Returns the database driver path if specified; otherwise null is returned.
 710  
      *
 711  
      * @return the database driver name if specified; otherwise null is returned
 712  
      */
 713  
     public String getDatabaseDriverPath() {
 714  0
         return line.getOptionValue(ARGUMENT.DB_DRIVER_PATH);
 715  
     }
 716  
 
 717  
     /**
 718  
      * Returns the database connection string if specified; otherwise null is returned.
 719  
      *
 720  
      * @return the database connection string if specified; otherwise null is returned
 721  
      */
 722  
     public String getConnectionString() {
 723  0
         return line.getOptionValue(ARGUMENT.CONNECTION_STRING);
 724  
     }
 725  
 
 726  
     /**
 727  
      * Returns the database database user name if specified; otherwise null is returned.
 728  
      *
 729  
      * @return the database database user name if specified; otherwise null is returned
 730  
      */
 731  
     public String getDatabaseUser() {
 732  0
         return line.getOptionValue(ARGUMENT.DB_NAME);
 733  
     }
 734  
 
 735  
     /**
 736  
      * Returns the database database password if specified; otherwise null is returned.
 737  
      *
 738  
      * @return the database database password if specified; otherwise null is returned
 739  
      */
 740  
     public String getDatabasePassword() {
 741  0
         return line.getOptionValue(ARGUMENT.DB_PASSWORD);
 742  
     }
 743  
 
 744  
     /**
 745  
      * Returns the additional Extensions if specified; otherwise null is returned.
 746  
      *
 747  
      * @return the additional Extensions; otherwise null is returned
 748  
      */
 749  
     public String getAdditionalZipExtensions() {
 750  0
         return line.getOptionValue(ARGUMENT.ADDITIONAL_ZIP_EXTENSIONS);
 751  
     }
 752  
 
 753  
     /**
 754  
      * A collection of static final strings that represent the possible command line arguments.
 755  
      */
 756  
     public static class ARGUMENT {
 757  
 
 758  
         /**
 759  
          * The long CLI argument name specifying the directory/file to scan.
 760  
          */
 761  
         public static final String SCAN = "scan";
 762  
         /**
 763  
          * The short CLI argument name specifying the directory/file to scan.
 764  
          */
 765  
         public static final String SCAN_SHORT = "s";
 766  
         /**
 767  
          * The long CLI argument name specifying that the CPE/CVE/etc. data should not be automatically updated.
 768  
          */
 769  
         public static final String DISABLE_AUTO_UPDATE = "noupdate";
 770  
         /**
 771  
          * The short CLI argument name specifying that the CPE/CVE/etc. data should not be automatically updated.
 772  
          */
 773  
         public static final String DISABLE_AUTO_UPDATE_SHORT = "n";
 774  
         /**
 775  
          * The long CLI argument name specifying the directory to write the reports to.
 776  
          */
 777  
         public static final String OUT = "out";
 778  
         /**
 779  
          * The short CLI argument name specifying the directory to write the reports to.
 780  
          */
 781  
         public static final String OUT_SHORT = "o";
 782  
         /**
 783  
          * The long CLI argument name specifying the output format to write the reports to.
 784  
          */
 785  
         public static final String OUTPUT_FORMAT = "format";
 786  
         /**
 787  
          * The short CLI argument name specifying the output format to write the reports to.
 788  
          */
 789  
         public static final String OUTPUT_FORMAT_SHORT = "f";
 790  
         /**
 791  
          * The long CLI argument name specifying the name of the application to be scanned.
 792  
          */
 793  
         public static final String APP_NAME = "app";
 794  
         /**
 795  
          * The short CLI argument name specifying the name of the application to be scanned.
 796  
          */
 797  
         public static final String APP_NAME_SHORT = "a";
 798  
         /**
 799  
          * The long CLI argument name asking for help.
 800  
          */
 801  
         public static final String HELP = "help";
 802  
         /**
 803  
          * The long CLI argument name asking for advanced help.
 804  
          */
 805  
         public static final String ADVANCED_HELP = "advancedHelp";
 806  
         /**
 807  
          * The short CLI argument name asking for help.
 808  
          */
 809  
         public static final String HELP_SHORT = "h";
 810  
         /**
 811  
          * The long CLI argument name asking for the version.
 812  
          */
 813  
         public static final String VERSION_SHORT = "v";
 814  
         /**
 815  
          * The short CLI argument name asking for the version.
 816  
          */
 817  
         public static final String VERSION = "version";
 818  
         /**
 819  
          * The CLI argument name indicating the proxy port.
 820  
          */
 821  
         public static final String PROXY_PORT = "proxyport";
 822  
         /**
 823  
          * The CLI argument name indicating the proxy server.
 824  
          */
 825  
         public static final String PROXY_SERVER = "proxyserver";
 826  
         /**
 827  
          * The CLI argument name indicating the proxy url.
 828  
          *
 829  
          * @deprecated use {@link org.owasp.dependencycheck.cli.CliParser.ArgumentName#PROXY_SERVER} instead
 830  
          */
 831  
         @Deprecated
 832  
         public static final String PROXY_URL = "proxyurl";
 833  
         /**
 834  
          * The CLI argument name indicating the proxy username.
 835  
          */
 836  
         public static final String PROXY_USERNAME = "proxyuser";
 837  
         /**
 838  
          * The CLI argument name indicating the proxy password.
 839  
          */
 840  
         public static final String PROXY_PASSWORD = "proxypass";
 841  
         /**
 842  
          * The short CLI argument name indicating the connection timeout.
 843  
          */
 844  
         public static final String CONNECTION_TIMEOUT_SHORT = "c";
 845  
         /**
 846  
          * The CLI argument name indicating the connection timeout.
 847  
          */
 848  
         public static final String CONNECTION_TIMEOUT = "connectiontimeout";
 849  
         /**
 850  
          * The short CLI argument name for setting the location of an additional properties file.
 851  
          */
 852  
         public static final String PROP_SHORT = "P";
 853  
         /**
 854  
          * The CLI argument name for setting the location of an additional properties file.
 855  
          */
 856  
         public static final String PROP = "propertyfile";
 857  
         /**
 858  
          * The CLI argument name for setting the location of the data directory.
 859  
          */
 860  
         public static final String DATA_DIRECTORY = "data";
 861  
         /**
 862  
          * The short CLI argument name for setting the location of the data directory.
 863  
          */
 864  
         public static final String DATA_DIRECTORY_SHORT = "d";
 865  
         /**
 866  
          * The CLI argument name for setting the location of the data directory.
 867  
          */
 868  
         public static final String VERBOSE_LOG = "log";
 869  
         /**
 870  
          * The short CLI argument name for setting the location of the data directory.
 871  
          */
 872  
         public static final String VERBOSE_LOG_SHORT = "l";
 873  
         /**
 874  
          * The CLI argument name for setting the location of the suppression file.
 875  
          */
 876  
         public static final String SUPPRESSION_FILE = "suppression";
 877  
         /**
 878  
          * Disables the Jar Analyzer.
 879  
          */
 880  
         public static final String DISABLE_JAR = "disableJar";
 881  
         /**
 882  
          * Disables the Archive Analyzer.
 883  
          */
 884  
         public static final String DISABLE_ARCHIVE = "disableArchive";
 885  
         /**
 886  
          * Disables the Assembly Analyzer.
 887  
          */
 888  
         public static final String DISABLE_ASSEMBLY = "disableAssembly";
 889  
         /**
 890  
          * Disables the Nuspec Analyzer.
 891  
          */
 892  
         public static final String DISABLE_NUSPEC = "disableNuspec";
 893  
         /**
 894  
          * Disables the Central Analyzer.
 895  
          */
 896  
         public static final String DISABLE_CENTRAL = "disableCentral";
 897  
         /**
 898  
          * Disables the Nexus Analyzer.
 899  
          */
 900  
         public static final String DISABLE_NEXUS = "disableNexus";
 901  
         /**
 902  
          * The URL of the nexus server.
 903  
          */
 904  
         public static final String NEXUS_URL = "nexus";
 905  
         /**
 906  
          * Whether or not the defined proxy should be used when connecting to Nexus.
 907  
          */
 908  
         public static final String NEXUS_USES_PROXY = "nexusUsesProxy";
 909  
         /**
 910  
          * The CLI argument name for setting the connection string.
 911  
          */
 912  
         public static final String CONNECTION_STRING = "connectionString";
 913  
         /**
 914  
          * The CLI argument name for setting the database user name.
 915  
          */
 916  
         public static final String DB_NAME = "dbUser";
 917  
         /**
 918  
          * The CLI argument name for setting the database password.
 919  
          */
 920  
         public static final String DB_PASSWORD = "dbPassword";
 921  
         /**
 922  
          * The CLI argument name for setting the database driver name.
 923  
          */
 924  
         public static final String DB_DRIVER = "dbDriverName";
 925  
         /**
 926  
          * The CLI argument name for setting the path to the database driver; in case it is not on the class path.
 927  
          */
 928  
         public static final String DB_DRIVER_PATH = "dbDriverPath";
 929  
         /**
 930  
          * The CLI argument name for setting the path to mono for .NET Assembly analysis on non-windows systems.
 931  
          */
 932  
         public static final String PATH_TO_MONO = "mono";
 933  
         /**
 934  
          * The CLI argument name for setting extra extensions.
 935  
          */
 936  
         public static final String ADDITIONAL_ZIP_EXTENSIONS = "zipExtensions";
 937  
         /**
 938  
          * Exclude path argument.
 939  
          */
 940  
         public static final String EXCLUDE = "exclude";
 941  
     }
 942  
 }