Coverage Report - org.owasp.dependencycheck.CliParser
 
Classes in this File Line Coverage Branch Coverage Complexity
CliParser
62%
100/161
35%
35/98
2.159
CliParser$ARGUMENT
0%
0/1
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  9
 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  9
     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 does not
 88  
      * 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 file a
 116  
      * 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".equalsIgnoreCase(argumentName.substring(0, 1)) && !"ALL".equalsIgnoreCase(this.getReportFormat())) {
 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 able to
 261  
      * 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 "
 328  
                         + "the Nexus Analyzer.")
 329  
                 .create();
 330  
 
 331  9
         final Option disableNexusAnalyzer = OptionBuilder.withLongOpt(ARGUMENT.DISABLE_NEXUS)
 332  
                 .withDescription("Disable the Nexus Analyzer.")
 333  
                 .create();
 334  
 
 335  9
         final Option nexusUrl = OptionBuilder.withArgName("url").hasArg().withLongOpt(ARGUMENT.NEXUS_URL)
 336  
                 .withDescription("The url to the Nexus Pro Server. If not set the Nexus Analyzer will be disabled.")
 337  
                 .create();
 338  
 
 339  9
         final Option nexusUsesProxy = OptionBuilder.withArgName("true/false").hasArg().withLongOpt(ARGUMENT.NEXUS_USES_PROXY)
 340  
                 .withDescription("Whether or not the configured proxy should be used when connecting to Nexus.")
 341  
                 .create();
 342  
 
 343  9
         final Option additionalZipExtensions = OptionBuilder.withArgName("extensions").hasArg()
 344  
                 .withLongOpt(ARGUMENT.ADDITIONAL_ZIP_EXTENSIONS)
 345  
                 .withDescription("A comma separated list of additional extensions to be scanned as ZIP files "
 346  
                         + "(ZIP, EAR, WAR are already treated as zip files)")
 347  
                 .create();
 348  
 
 349  9
         final Option pathToMono = OptionBuilder.withArgName("path").hasArg().withLongOpt(ARGUMENT.PATH_TO_MONO)
 350  
                 .withDescription("The path to Mono for .NET Assembly analysis on non-windows systems.")
 351  
                 .create();
 352  
 
 353  9
         options.addOption(proxyPort)
 354  
                 .addOption(proxyServer)
 355  
                 .addOption(proxyUsername)
 356  
                 .addOption(proxyPassword)
 357  
                 .addOption(connectionTimeout)
 358  
                 .addOption(connectionString)
 359  
                 .addOption(dbUser)
 360  
                 .addOption(data)
 361  
                 .addOption(dbPassword)
 362  
                 .addOption(dbDriver)
 363  
                 .addOption(dbDriverPath)
 364  
                 .addOption(disableJarAnalyzer)
 365  
                 .addOption(disableArchiveAnalyzer)
 366  
                 .addOption(disableAssemblyAnalyzer)
 367  
                 .addOption(disableNuspecAnalyzer)
 368  
                 .addOption(disableCentralAnalyzer)
 369  
                 .addOption(disableNexusAnalyzer)
 370  
                 .addOption(nexusUrl)
 371  
                 .addOption(nexusUsesProxy)
 372  
                 .addOption(additionalZipExtensions)
 373  
                 .addOption(pathToMono);
 374  9
     }
 375  
 
 376  
     /**
 377  
      * Adds the deprecated command line options to the given options collection. These are split out for purposes of not including
 378  
      * them in the help message. We need to add the deprecated options so as not to break existing scripts.
 379  
      *
 380  
      * @param options a collection of command line arguments
 381  
      * @throws IllegalArgumentException thrown if there is an exception
 382  
      */
 383  
     @SuppressWarnings("static-access")
 384  
     private void addDeprecatedOptions(final Options options) throws IllegalArgumentException {
 385  
 
 386  9
         final Option proxyServer = OptionBuilder.withArgName("url").hasArg().withLongOpt(ARGUMENT.PROXY_URL)
 387  
                 .withDescription("The proxy url argument is deprecated, use proxyserver instead.")
 388  
                 .create();
 389  
 
 390  9
         options.addOption(proxyServer);
 391  9
     }
 392  
 
 393  
     /**
 394  
      * Determines if the 'version' command line argument was passed in.
 395  
      *
 396  
      * @return whether or not the 'version' command line argument was passed in
 397  
      */
 398  
     public boolean isGetVersion() {
 399  7
         return (line != null) && line.hasOption(ARGUMENT.VERSION);
 400  
     }
 401  
 
 402  
     /**
 403  
      * Determines if the 'help' command line argument was passed in.
 404  
      *
 405  
      * @return whether or not the 'help' command line argument was passed in
 406  
      */
 407  
     public boolean isGetHelp() {
 408  7
         return (line != null) && line.hasOption(ARGUMENT.HELP);
 409  
     }
 410  
 
 411  
     /**
 412  
      * Determines if the 'scan' command line argument was passed in.
 413  
      *
 414  
      * @return whether or not the 'scan' command line argument was passed in
 415  
      */
 416  
     public boolean isRunScan() {
 417  14
         return (line != null) && isValid && line.hasOption(ARGUMENT.SCAN);
 418  
     }
 419  
 
 420  
     /**
 421  
      * Returns true if the disableJar command line argument was specified.
 422  
      *
 423  
      * @return true if the disableJar command line argument was specified; otherwise false
 424  
      */
 425  
     public boolean isJarDisabled() {
 426  0
         return (line != null) && line.hasOption(ARGUMENT.DISABLE_JAR);
 427  
     }
 428  
 
 429  
     /**
 430  
      * Returns true if the disableArchive command line argument was specified.
 431  
      *
 432  
      * @return true if the disableArchive command line argument was specified; otherwise false
 433  
      */
 434  
     public boolean isArchiveDisabled() {
 435  0
         return (line != null) && line.hasOption(ARGUMENT.DISABLE_ARCHIVE);
 436  
     }
 437  
 
 438  
     /**
 439  
      * Returns true if the disableNuspec command line argument was specified.
 440  
      *
 441  
      * @return true if the disableNuspec command line argument was specified; otherwise false
 442  
      */
 443  
     public boolean isNuspecDisabled() {
 444  0
         return (line != null) && line.hasOption(ARGUMENT.DISABLE_NUSPEC);
 445  
     }
 446  
 
 447  
     /**
 448  
      * Returns true if the disableAssembly command line argument was specified.
 449  
      *
 450  
      * @return true if the disableAssembly command line argument was specified; otherwise false
 451  
      */
 452  
     public boolean isAssemblyDisabled() {
 453  0
         return (line != null) && line.hasOption(ARGUMENT.DISABLE_ASSEMBLY);
 454  
     }
 455  
 
 456  
     /**
 457  
      * Returns true if the disableNexus command line argument was specified.
 458  
      *
 459  
      * @return true if the disableNexus command line argument was specified; otherwise false
 460  
      */
 461  
     public boolean isNexusDisabled() {
 462  0
         return (line != null) && line.hasOption(ARGUMENT.DISABLE_NEXUS);
 463  
     }
 464  
 
 465  
     /**
 466  
      * Returns true if the disableCentral command line argument was specified.
 467  
      *
 468  
      * @return true if the disableCentral command line argument was specified; otherwise false
 469  
      */
 470  
     public boolean isCentralDisabled() {
 471  0
         return (line != null) && line.hasOption(ARGUMENT.DISABLE_CENTRAL);
 472  
     }
 473  
 
 474  
     /**
 475  
      * Returns the url to the nexus server if one was specified.
 476  
      *
 477  
      * @return the url to the nexus server; if none was specified this will return null;
 478  
      */
 479  
     public String getNexusUrl() {
 480  0
         if (line == null || !line.hasOption(ARGUMENT.NEXUS_URL)) {
 481  0
             return null;
 482  
         } else {
 483  0
             return line.getOptionValue(ARGUMENT.NEXUS_URL);
 484  
         }
 485  
     }
 486  
 
 487  
     /**
 488  
      * Returns true if the Nexus Analyzer should use the configured proxy to connect to Nexus; otherwise false is 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 return false.
 691  
      *
 692  
      * @return if auto-update is allowed.
 693  
      */
 694  
     public boolean isAutoUpdate() {
 695  0
         return (line == null) || !line.hasOption(ARGUMENT.DISABLE_AUTO_UPDATE);
 696  
     }
 697  
 
 698  
     /**
 699  
      * Returns the database driver name if specified; otherwise null is returned.
 700  
      *
 701  
      * @return the database driver name if specified; otherwise null is returned
 702  
      */
 703  
     public String getDatabaseDriverName() {
 704  0
         return line.getOptionValue(ARGUMENT.DB_DRIVER);
 705  
     }
 706  
 
 707  
     /**
 708  
      * Returns the database driver path if specified; otherwise null is returned.
 709  
      *
 710  
      * @return the database driver name if specified; otherwise null is returned
 711  
      */
 712  
     public String getDatabaseDriverPath() {
 713  0
         return line.getOptionValue(ARGUMENT.DB_DRIVER_PATH);
 714  
     }
 715  
 
 716  
     /**
 717  
      * Returns the database connection string if specified; otherwise null is returned.
 718  
      *
 719  
      * @return the database connection string if specified; otherwise null is returned
 720  
      */
 721  
     public String getConnectionString() {
 722  0
         return line.getOptionValue(ARGUMENT.CONNECTION_STRING);
 723  
     }
 724  
 
 725  
     /**
 726  
      * Returns the database database user name if specified; otherwise null is returned.
 727  
      *
 728  
      * @return the database database user name if specified; otherwise null is returned
 729  
      */
 730  
     public String getDatabaseUser() {
 731  0
         return line.getOptionValue(ARGUMENT.DB_NAME);
 732  
     }
 733  
 
 734  
     /**
 735  
      * Returns the database database password if specified; otherwise null is returned.
 736  
      *
 737  
      * @return the database database password if specified; otherwise null is returned
 738  
      */
 739  
     public String getDatabasePassword() {
 740  0
         return line.getOptionValue(ARGUMENT.DB_PASSWORD);
 741  
     }
 742  
 
 743  
     /**
 744  
      * Returns the additional Extensions if specified; otherwise null is returned.
 745  
      *
 746  
      * @return the additional Extensions; otherwise null is returned
 747  
      */
 748  
     public String getAdditionalZipExtensions() {
 749  0
         return line.getOptionValue(ARGUMENT.ADDITIONAL_ZIP_EXTENSIONS);
 750  
     }
 751  
 
 752  
     /**
 753  
      * A collection of static final strings that represent the possible command line arguments.
 754  
      */
 755  9
     public static class ARGUMENT {
 756  
 
 757  
         /**
 758  
          * The long CLI argument name specifying the directory/file to scan.
 759  
          */
 760  
         public static final String SCAN = "scan";
 761  
         /**
 762  
          * The short CLI argument name specifying the directory/file to scan.
 763  
          */
 764  
         public static final String SCAN_SHORT = "s";
 765  
         /**
 766  
          * The long CLI argument name specifying that the CPE/CVE/etc. data should not be automatically updated.
 767  
          */
 768  
         public static final String DISABLE_AUTO_UPDATE = "noupdate";
 769  
         /**
 770  
          * The short CLI argument name specifying that the CPE/CVE/etc. data should not be automatically updated.
 771  
          */
 772  
         public static final String DISABLE_AUTO_UPDATE_SHORT = "n";
 773  
         /**
 774  
          * The long CLI argument name specifying the directory to write the reports to.
 775  
          */
 776  
         public static final String OUT = "out";
 777  
         /**
 778  
          * The short CLI argument name specifying the directory to write the reports to.
 779  
          */
 780  
         public static final String OUT_SHORT = "o";
 781  
         /**
 782  
          * The long CLI argument name specifying the output format to write the reports to.
 783  
          */
 784  
         public static final String OUTPUT_FORMAT = "format";
 785  
         /**
 786  
          * The short CLI argument name specifying the output format to write the reports to.
 787  
          */
 788  
         public static final String OUTPUT_FORMAT_SHORT = "f";
 789  
         /**
 790  
          * The long CLI argument name specifying the name of the application to be scanned.
 791  
          */
 792  
         public static final String APP_NAME = "app";
 793  
         /**
 794  
          * The short CLI argument name specifying the name of the application to be scanned.
 795  
          */
 796  
         public static final String APP_NAME_SHORT = "a";
 797  
         /**
 798  
          * The long CLI argument name asking for help.
 799  
          */
 800  
         public static final String HELP = "help";
 801  
         /**
 802  
          * The long CLI argument name asking for advanced help.
 803  
          */
 804  
         public static final String ADVANCED_HELP = "advancedHelp";
 805  
         /**
 806  
          * The short CLI argument name asking for help.
 807  
          */
 808  
         public static final String HELP_SHORT = "h";
 809  
         /**
 810  
          * The long CLI argument name asking for the version.
 811  
          */
 812  
         public static final String VERSION_SHORT = "v";
 813  
         /**
 814  
          * The short CLI argument name asking for the version.
 815  
          */
 816  
         public static final String VERSION = "version";
 817  
         /**
 818  
          * The CLI argument name indicating the proxy port.
 819  
          */
 820  
         public static final String PROXY_PORT = "proxyport";
 821  
         /**
 822  
          * The CLI argument name indicating the proxy server.
 823  
          */
 824  
         public static final String PROXY_SERVER = "proxyserver";
 825  
         /**
 826  
          * The CLI argument name indicating the proxy url.
 827  
          *
 828  
          * @deprecated use {@link org.owasp.dependencycheck.cli.CliParser.ArgumentName#PROXY_SERVER} instead
 829  
          */
 830  
         @Deprecated
 831  
         public static final String PROXY_URL = "proxyurl";
 832  
         /**
 833  
          * The CLI argument name indicating the proxy username.
 834  
          */
 835  
         public static final String PROXY_USERNAME = "proxyuser";
 836  
         /**
 837  
          * The CLI argument name indicating the proxy password.
 838  
          */
 839  
         public static final String PROXY_PASSWORD = "proxypass";
 840  
         /**
 841  
          * The short CLI argument name indicating the connection timeout.
 842  
          */
 843  
         public static final String CONNECTION_TIMEOUT_SHORT = "c";
 844  
         /**
 845  
          * The CLI argument name indicating the connection timeout.
 846  
          */
 847  
         public static final String CONNECTION_TIMEOUT = "connectiontimeout";
 848  
         /**
 849  
          * The short CLI argument name for setting the location of an additional properties file.
 850  
          */
 851  
         public static final String PROP_SHORT = "P";
 852  
         /**
 853  
          * The CLI argument name for setting the location of an additional properties file.
 854  
          */
 855  
         public static final String PROP = "propertyfile";
 856  
         /**
 857  
          * The CLI argument name for setting the location of the data directory.
 858  
          */
 859  
         public static final String DATA_DIRECTORY = "data";
 860  
         /**
 861  
          * The short CLI argument name for setting the location of the data directory.
 862  
          */
 863  
         public static final String DATA_DIRECTORY_SHORT = "d";
 864  
         /**
 865  
          * The CLI argument name for setting the location of the data directory.
 866  
          */
 867  
         public static final String VERBOSE_LOG = "log";
 868  
         /**
 869  
          * The short CLI argument name for setting the location of the data directory.
 870  
          */
 871  
         public static final String VERBOSE_LOG_SHORT = "l";
 872  
         /**
 873  
          * The CLI argument name for setting the location of the suppression file.
 874  
          */
 875  
         public static final String SUPPRESSION_FILE = "suppression";
 876  
         /**
 877  
          * Disables the Jar Analyzer.
 878  
          */
 879  
         public static final String DISABLE_JAR = "disableJar";
 880  
         /**
 881  
          * Disables the Archive Analyzer.
 882  
          */
 883  
         public static final String DISABLE_ARCHIVE = "disableArchive";
 884  
         /**
 885  
          * Disables the Assembly Analyzer.
 886  
          */
 887  
         public static final String DISABLE_ASSEMBLY = "disableAssembly";
 888  
         /**
 889  
          * Disables the Nuspec Analyzer.
 890  
          */
 891  
         public static final String DISABLE_NUSPEC = "disableNuspec";
 892  
         /**
 893  
          * Disables the Central Analyzer.
 894  
          */
 895  
         public static final String DISABLE_CENTRAL = "disableCentral";
 896  
         /**
 897  
          * Disables the Nexus Analyzer.
 898  
          */
 899  
         public static final String DISABLE_NEXUS = "disableNexus";
 900  
         /**
 901  
          * The URL of the nexus server.
 902  
          */
 903  
         public static final String NEXUS_URL = "nexus";
 904  
         /**
 905  
          * Whether or not the defined proxy should be used when connecting to Nexus.
 906  
          */
 907  
         public static final String NEXUS_USES_PROXY = "nexusUsesProxy";
 908  
         /**
 909  
          * The CLI argument name for setting the connection string.
 910  
          */
 911  
         public static final String CONNECTION_STRING = "connectionString";
 912  
         /**
 913  
          * The CLI argument name for setting the database user name.
 914  
          */
 915  
         public static final String DB_NAME = "dbUser";
 916  
         /**
 917  
          * The CLI argument name for setting the database password.
 918  
          */
 919  
         public static final String DB_PASSWORD = "dbPassword";
 920  
         /**
 921  
          * The CLI argument name for setting the database driver name.
 922  
          */
 923  
         public static final String DB_DRIVER = "dbDriverName";
 924  
         /**
 925  
          * The CLI argument name for setting the path to the database driver; in case it is not on the class path.
 926  
          */
 927  
         public static final String DB_DRIVER_PATH = "dbDriverPath";
 928  
         /**
 929  
          * The CLI argument name for setting the path to mono for .NET Assembly analysis on non-windows systems.
 930  
          */
 931  
         public static final String PATH_TO_MONO = "mono";
 932  
         /**
 933  
          * The CLI argument name for setting extra extensions.
 934  
          */
 935  
         public static final String ADDITIONAL_ZIP_EXTENSIONS = "zipExtensions";
 936  
         /**
 937  
          * Exclude path argument.
 938  
          */
 939  
         public static final String EXCLUDE = "exclude";
 940  
     }
 941  
 }