1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.owasp.dependencycheck;
19
20 import java.io.File;
21 import java.io.FileNotFoundException;
22
23 import org.apache.commons.cli.CommandLine;
24 import org.apache.commons.cli.CommandLineParser;
25 import org.apache.commons.cli.HelpFormatter;
26 import org.apache.commons.cli.Option;
27 import org.apache.commons.cli.OptionBuilder;
28 import org.apache.commons.cli.OptionGroup;
29 import org.apache.commons.cli.Options;
30 import org.apache.commons.cli.ParseException;
31 import org.apache.commons.cli.PosixParser;
32 import org.owasp.dependencycheck.reporting.ReportGenerator.Format;
33 import org.owasp.dependencycheck.utils.InvalidSettingException;
34 import org.owasp.dependencycheck.utils.Settings;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38
39
40
41
42
43 public final class CliParser {
44
45
46
47
48 private static final Logger LOGGER = LoggerFactory.getLogger(CliParser.class);
49
50
51
52 private CommandLine line;
53
54
55
56 private boolean isValid = true;
57
58
59
60
61
62
63
64
65 public void parse(String[] args) throws FileNotFoundException, ParseException {
66 line = parseArgs(args);
67
68 if (line != null) {
69 validateArgs();
70 }
71 }
72
73
74
75
76
77
78
79
80 private CommandLine parseArgs(String[] args) throws ParseException {
81 final CommandLineParser parser = new PosixParser();
82 final Options options = createCommandLineOptions();
83 return parser.parse(options, args);
84 }
85
86
87
88
89
90
91
92
93 private void validateArgs() throws FileNotFoundException, ParseException {
94 if (isRunScan()) {
95 validatePathExists(getScanFiles(), ARGUMENT.SCAN);
96 validatePathExists(getReportDirectory(), ARGUMENT.OUT);
97 if (getPathToMono() != null) {
98 validatePathExists(getPathToMono(), ARGUMENT.PATH_TO_MONO);
99 }
100 if (!line.hasOption(ARGUMENT.APP_NAME)) {
101 throw new ParseException("Missing 'app' argument; the scan cannot be run without the an application name.");
102 }
103 if (line.hasOption(ARGUMENT.OUTPUT_FORMAT)) {
104 final String format = line.getOptionValue(ARGUMENT.OUTPUT_FORMAT);
105 try {
106 Format.valueOf(format);
107 } catch (IllegalArgumentException ex) {
108 final String msg = String.format("An invalid 'format' of '%s' was specified. "
109 + "Supported output formats are XML, HTML, VULN, or ALL", format);
110 throw new ParseException(msg);
111 }
112 }
113 if ((getBaseCve12Url() != null || getBaseCve20Url() != null || getModifiedCve12Url() != null || getModifiedCve20Url() != null)
114 && (getBaseCve12Url() == null || getBaseCve20Url() == null || getModifiedCve12Url() == null || getModifiedCve20Url() == null)) {
115 final String msg = "If one of the CVE URLs is specified they must all be specified; please add the missing CVE URL.";
116 throw new ParseException(msg);
117 }
118 if (line.hasOption((ARGUMENT.SYM_LINK_DEPTH))) {
119 try {
120 final int i = Integer.parseInt(line.getOptionValue(ARGUMENT.SYM_LINK_DEPTH));
121 if (i < 0) {
122 throw new ParseException("Symbolic Link Depth (symLink) must be greater than zero.");
123 }
124 } catch (NumberFormatException ex) {
125 throw new ParseException("Symbolic Link Depth (symLink) is not a number.");
126 }
127 }
128 }
129 }
130
131
132
133
134
135
136
137
138
139 private void validatePathExists(String[] paths, String optType) throws FileNotFoundException {
140 for (String path : paths) {
141 validatePathExists(path, optType);
142 }
143 }
144
145
146
147
148
149
150
151
152
153 private void validatePathExists(String path, String argumentName) throws FileNotFoundException {
154 if (path == null) {
155 isValid = false;
156 final String msg = String.format("Invalid '%s' argument: null", argumentName);
157 throw new FileNotFoundException(msg);
158 } else if (!path.contains("*") && !path.contains("?")) {
159 File f = new File(path);
160 if ("o".equalsIgnoreCase(argumentName.substring(0, 1)) && !"ALL".equalsIgnoreCase(this.getReportFormat())) {
161 final String checkPath = path.toLowerCase();
162 if (checkPath.endsWith(".html") || checkPath.endsWith(".xml") || checkPath.endsWith(".htm")) {
163 if (f.getParentFile() == null) {
164 f = new File(".", path);
165 }
166 if (!f.getParentFile().isDirectory()) {
167 isValid = false;
168 final String msg = String.format("Invalid '%s' argument: '%s'", argumentName, path);
169 throw new FileNotFoundException(msg);
170 }
171 }
172 } else {
173 if (!f.exists()) {
174 isValid = false;
175 final String msg = String.format("Invalid '%s' argument: '%s'", argumentName, path);
176 throw new FileNotFoundException(msg);
177 }
178 }
179 } else if (path.startsWith("//") || path.startsWith("\\\\")) {
180 isValid = false;
181 final String msg = String.format("Invalid '%s' argument: '%s'%nUnable to scan paths that start with '//'.", argumentName, path);
182 throw new FileNotFoundException(msg);
183 }
184 }
185
186
187
188
189
190
191 @SuppressWarnings("static-access")
192 private Options createCommandLineOptions() {
193 final Options options = new Options();
194 addStandardOptions(options);
195 addAdvancedOptions(options);
196 addDeprecatedOptions(options);
197 return options;
198 }
199
200
201
202
203
204
205
206 @SuppressWarnings("static-access")
207 private void addStandardOptions(final Options options) throws IllegalArgumentException {
208 final Option help = new Option(ARGUMENT.HELP_SHORT, ARGUMENT.HELP, false,
209 "Print this message.");
210
211 final Option advancedHelp = OptionBuilder.withLongOpt(ARGUMENT.ADVANCED_HELP)
212 .withDescription("Print the advanced help message.").create();
213
214 final Option version = new Option(ARGUMENT.VERSION_SHORT, ARGUMENT.VERSION,
215 false, "Print the version information.");
216
217 final Option noUpdate = new Option(ARGUMENT.DISABLE_AUTO_UPDATE_SHORT, ARGUMENT.DISABLE_AUTO_UPDATE,
218 false, "Disables the automatic updating of the CPE data.");
219
220 final Option appName = OptionBuilder.withArgName("name").hasArg().withLongOpt(ARGUMENT.APP_NAME)
221 .withDescription("The name of the application being scanned. This is a required argument.")
222 .create(ARGUMENT.APP_NAME_SHORT);
223
224 final Option path = OptionBuilder.withArgName("path").hasArg().withLongOpt(ARGUMENT.SCAN)
225 .withDescription("The path to scan - this option can be specified multiple times. Ant style"
226 + " paths are supported (e.g. path/**/*.jar).")
227 .create(ARGUMENT.SCAN_SHORT);
228
229 final Option excludes = OptionBuilder.withArgName("pattern").hasArg().withLongOpt(ARGUMENT.EXCLUDE)
230 .withDescription("Specify and exclusion pattern. This option can be specified multiple times"
231 + " and it accepts Ant style excludsions.")
232 .create();
233
234 final Option props = OptionBuilder.withArgName("file").hasArg().withLongOpt(ARGUMENT.PROP)
235 .withDescription("A property file to load.")
236 .create(ARGUMENT.PROP_SHORT);
237
238 final Option out = OptionBuilder.withArgName("path").hasArg().withLongOpt(ARGUMENT.OUT)
239 .withDescription("The folder to write reports to. This defaults to the current directory. "
240 + "It is possible to set this to a specific file name if the format argument is not set to ALL.")
241 .create(ARGUMENT.OUT_SHORT);
242
243 final Option outputFormat = OptionBuilder.withArgName("format").hasArg().withLongOpt(ARGUMENT.OUTPUT_FORMAT)
244 .withDescription("The output format to write to (XML, HTML, VULN, ALL). The default is HTML.")
245 .create(ARGUMENT.OUTPUT_FORMAT_SHORT);
246
247 final Option verboseLog = OptionBuilder.withArgName("file").hasArg().withLongOpt(ARGUMENT.VERBOSE_LOG)
248 .withDescription("The file path to write verbose logging information.")
249 .create(ARGUMENT.VERBOSE_LOG_SHORT);
250
251 final Option symLinkDepth = OptionBuilder.withArgName("depth").hasArg().withLongOpt(ARGUMENT.SYM_LINK_DEPTH)
252 .withDescription("Sets how deep nested symbolic links will be followed; 0 indicates symbolic links will not be followed.")
253 .create();
254
255 final Option suppressionFile = OptionBuilder.withArgName("file").hasArg().withLongOpt(ARGUMENT.SUPPRESSION_FILE)
256 .withDescription("The file path to the suppression XML file.")
257 .create();
258
259
260 final OptionGroup og = new OptionGroup();
261 og.addOption(path);
262
263 final OptionGroup exog = new OptionGroup();
264 exog.addOption(excludes);
265
266 options.addOptionGroup(og)
267 .addOptionGroup(exog)
268 .addOption(out)
269 .addOption(outputFormat)
270 .addOption(appName)
271 .addOption(version)
272 .addOption(help)
273 .addOption(advancedHelp)
274 .addOption(noUpdate)
275 .addOption(symLinkDepth)
276 .addOption(props)
277 .addOption(verboseLog)
278 .addOption(suppressionFile);
279 }
280
281
282
283
284
285
286
287
288 @SuppressWarnings("static-access")
289 private void addAdvancedOptions(final Options options) throws IllegalArgumentException {
290
291 final Option cve12Base = OptionBuilder.withArgName("url").hasArg().withLongOpt(ARGUMENT.CVE_BASE_12)
292 .withDescription("Base URL for each year’s CVE 1.2, the %d will be replaced with the year. ")
293 .create();
294
295 final Option cve20Base = OptionBuilder.withArgName("url").hasArg().withLongOpt(ARGUMENT.CVE_BASE_20)
296 .withDescription("Base URL for each year’s CVE 2.0, the %d will be replaced with the year.")
297 .create();
298
299 final Option cve12Modified = OptionBuilder.withArgName("url").hasArg().withLongOpt(ARGUMENT.CVE_MOD_12)
300 .withDescription("URL for the modified CVE 1.2.")
301 .create();
302
303 final Option cve20Modified = OptionBuilder.withArgName("url").hasArg().withLongOpt(ARGUMENT.CVE_MOD_20)
304 .withDescription("URL for the modified CVE 2.0.")
305 .create();
306
307 final Option updateOnly = OptionBuilder.withLongOpt(ARGUMENT.UPDATE_ONLY)
308 .withDescription("Only update the local NVD data cache; no scan will be executed.").create();
309
310 final Option data = OptionBuilder.withArgName("path").hasArg().withLongOpt(ARGUMENT.DATA_DIRECTORY)
311 .withDescription("The location of the H2 Database file. This option should generally not be set.")
312 .create(ARGUMENT.DATA_DIRECTORY_SHORT);
313
314 final Option nexusUrl = OptionBuilder.withArgName("url").hasArg().withLongOpt(ARGUMENT.NEXUS_URL)
315 .withDescription("The url to the Nexus Server's REST API Endpoint (http://domain/nexus/service/local). "
316 + "If not set the Nexus Analyzer will be disabled.").create();
317
318 final Option nexusUsesProxy = OptionBuilder.withArgName("true/false").hasArg().withLongOpt(ARGUMENT.NEXUS_USES_PROXY)
319 .withDescription("Whether or not the configured proxy should be used when connecting to Nexus.")
320 .create();
321
322 final Option additionalZipExtensions = OptionBuilder.withArgName("extensions").hasArg()
323 .withLongOpt(ARGUMENT.ADDITIONAL_ZIP_EXTENSIONS)
324 .withDescription("A comma separated list of additional extensions to be scanned as ZIP files "
325 + "(ZIP, EAR, WAR are already treated as zip files)").create();
326
327 final Option pathToMono = OptionBuilder.withArgName("path").hasArg().withLongOpt(ARGUMENT.PATH_TO_MONO)
328 .withDescription("The path to Mono for .NET Assembly analysis on non-windows systems.")
329 .create();
330
331 final Option connectionTimeout = OptionBuilder.withArgName("timeout").hasArg().withLongOpt(ARGUMENT.CONNECTION_TIMEOUT)
332 .withDescription("The connection timeout (in milliseconds) to use when downloading resources.")
333 .create(ARGUMENT.CONNECTION_TIMEOUT_SHORT);
334
335 final Option proxyServer = OptionBuilder.withArgName("server").hasArg().withLongOpt(ARGUMENT.PROXY_SERVER)
336 .withDescription("The proxy server to use when downloading resources.").create();
337
338 final Option proxyPort = OptionBuilder.withArgName("port").hasArg().withLongOpt(ARGUMENT.PROXY_PORT)
339 .withDescription("The proxy port to use when downloading resources.").create();
340
341 final Option proxyUsername = OptionBuilder.withArgName("user").hasArg().withLongOpt(ARGUMENT.PROXY_USERNAME)
342 .withDescription("The proxy username to use when downloading resources.").create();
343
344 final Option proxyPassword = OptionBuilder.withArgName("pass").hasArg().withLongOpt(ARGUMENT.PROXY_PASSWORD)
345 .withDescription("The proxy password to use when downloading resources.").create();
346
347 final Option connectionString = OptionBuilder.withArgName("connStr").hasArg().withLongOpt(ARGUMENT.CONNECTION_STRING)
348 .withDescription("The connection string to the database.").create();
349
350 final Option dbUser = OptionBuilder.withArgName("user").hasArg().withLongOpt(ARGUMENT.DB_NAME)
351 .withDescription("The username used to connect to the database.").create();
352
353 final Option dbPassword = OptionBuilder.withArgName("password").hasArg().withLongOpt(ARGUMENT.DB_PASSWORD)
354 .withDescription("The password for connecting to the database.").create();
355
356 final Option dbDriver = OptionBuilder.withArgName("driver").hasArg().withLongOpt(ARGUMENT.DB_DRIVER)
357 .withDescription("The database driver name.").create();
358
359 final Option dbDriverPath = OptionBuilder.withArgName("path").hasArg().withLongOpt(ARGUMENT.DB_DRIVER_PATH)
360 .withDescription("The path to the database driver; note, this does not need to be set unless the JAR is outside of the classpath.")
361 .create();
362
363 final Option disableJarAnalyzer = OptionBuilder.withLongOpt(ARGUMENT.DISABLE_JAR)
364 .withDescription("Disable the Jar Analyzer.").create();
365
366 final Option disableArchiveAnalyzer = OptionBuilder.withLongOpt(ARGUMENT.DISABLE_ARCHIVE)
367 .withDescription("Disable the Archive Analyzer.").create();
368
369 final Option disableNuspecAnalyzer = OptionBuilder.withLongOpt(ARGUMENT.DISABLE_NUSPEC)
370 .withDescription("Disable the Nuspec Analyzer.").create();
371
372 final Option disableAssemblyAnalyzer = OptionBuilder.withLongOpt(ARGUMENT.DISABLE_ASSEMBLY)
373 .withDescription("Disable the .NET Assembly Analyzer.").create();
374
375 final Option disablePythonDistributionAnalyzer = OptionBuilder.withLongOpt(ARGUMENT.DISABLE_PY_DIST)
376 .withDescription("Disable the Python Distribution Analyzer.").create();
377
378 final Option disablePythonPackageAnalyzer = OptionBuilder.withLongOpt(ARGUMENT.DISABLE_PY_PKG)
379 .withDescription("Disable the Python Package Analyzer.").create();
380
381 final Option disableAutoconfAnalyzer = OptionBuilder
382 .withLongOpt(ARGUMENT.DISABLE_AUTOCONF)
383 .withDescription("Disable the Autoconf Analyzer.").create();
384
385 final Option disableOpenSSLAnalyzer = OptionBuilder.withLongOpt(ARGUMENT.DISABLE_OPENSSL)
386 .withDescription("Disable the OpenSSL Analyzer.").create();
387 final Option disableCmakeAnalyzer = OptionBuilder.withLongOpt(ARGUMENT.DISABLE_CMAKE).
388 withDescription("Disable the Cmake Analyzer.").create();
389
390 final Option disableCentralAnalyzer = OptionBuilder.withLongOpt(ARGUMENT.DISABLE_CENTRAL)
391 .withDescription("Disable the Central Analyzer. If this analyzer is disabled it is likely you also want to disable "
392 + "the Nexus Analyzer.").create();
393
394 final Option disableNexusAnalyzer = OptionBuilder.withLongOpt(ARGUMENT.DISABLE_NEXUS)
395 .withDescription("Disable the Nexus Analyzer.").create();
396
397 options.addOption(updateOnly)
398 .addOption(cve12Base)
399 .addOption(cve20Base)
400 .addOption(cve12Modified)
401 .addOption(cve20Modified)
402 .addOption(proxyPort)
403 .addOption(proxyServer)
404 .addOption(proxyUsername)
405 .addOption(proxyPassword)
406 .addOption(connectionTimeout)
407 .addOption(connectionString)
408 .addOption(dbUser)
409 .addOption(data)
410 .addOption(dbPassword)
411 .addOption(dbDriver)
412 .addOption(dbDriverPath)
413 .addOption(disableJarAnalyzer)
414 .addOption(disableArchiveAnalyzer)
415 .addOption(disableAssemblyAnalyzer)
416 .addOption(disablePythonDistributionAnalyzer)
417 .addOption(disableCmakeAnalyzer)
418 .addOption(disablePythonPackageAnalyzer)
419 .addOption(disableAutoconfAnalyzer)
420 .addOption(disableOpenSSLAnalyzer)
421 .addOption(disableNuspecAnalyzer)
422 .addOption(disableCentralAnalyzer)
423 .addOption(disableNexusAnalyzer)
424 .addOption(nexusUrl)
425 .addOption(nexusUsesProxy)
426 .addOption(additionalZipExtensions)
427 .addOption(pathToMono);
428 }
429
430
431
432
433
434
435
436
437 @SuppressWarnings({"static-access", "deprecation"})
438 private void addDeprecatedOptions(final Options options) throws IllegalArgumentException {
439
440 final Option proxyServer = OptionBuilder.withArgName("url").hasArg().withLongOpt(ARGUMENT.PROXY_URL)
441 .withDescription("The proxy url argument is deprecated, use proxyserver instead.")
442 .create();
443
444 options.addOption(proxyServer);
445 }
446
447
448
449
450
451
452 public boolean isGetVersion() {
453 return (line != null) && line.hasOption(ARGUMENT.VERSION);
454 }
455
456
457
458
459
460
461 public boolean isGetHelp() {
462 return (line != null) && line.hasOption(ARGUMENT.HELP);
463 }
464
465
466
467
468
469
470 public boolean isRunScan() {
471 return (line != null) && isValid && line.hasOption(ARGUMENT.SCAN);
472 }
473
474
475
476
477
478
479 public int getSymLinkDepth() {
480 int value = 0;
481 try {
482 value = Integer.parseInt(line.getOptionValue(ARGUMENT.SYM_LINK_DEPTH, "0"));
483 if (value < 0) {
484 value = 0;
485 }
486 } catch (NumberFormatException ex) {
487 LOGGER.debug("Symbolic link was not a number");
488 }
489 return value;
490 }
491
492
493
494
495
496
497 public boolean isJarDisabled() {
498 return (line != null) && line.hasOption(ARGUMENT.DISABLE_JAR);
499 }
500
501
502
503
504
505
506 public boolean isArchiveDisabled() {
507 return (line != null) && line.hasOption(ARGUMENT.DISABLE_ARCHIVE);
508 }
509
510
511
512
513
514
515 public boolean isNuspecDisabled() {
516 return (line != null) && line.hasOption(ARGUMENT.DISABLE_NUSPEC);
517 }
518
519
520
521
522
523
524 public boolean isAssemblyDisabled() {
525 return (line != null) && line.hasOption(ARGUMENT.DISABLE_ASSEMBLY);
526 }
527
528
529
530
531
532
533 public boolean isPythonDistributionDisabled() {
534 return (line != null) && line.hasOption(ARGUMENT.DISABLE_PY_DIST);
535 }
536
537
538
539
540
541
542 public boolean isPythonPackageDisabled() {
543 return (line != null) && line.hasOption(ARGUMENT.DISABLE_PY_PKG);
544 }
545
546
547
548
549
550
551 public boolean isCmakeDisabled() {
552 return (line != null) && line.hasOption(ARGUMENT.DISABLE_CMAKE);
553 }
554
555
556
557
558
559
560 public boolean isAutoconfDisabled() {
561 return (line != null) && line.hasOption(ARGUMENT.DISABLE_AUTOCONF);
562 }
563
564
565
566
567
568
569 public boolean isNexusDisabled() {
570 return (line != null) && line.hasOption(ARGUMENT.DISABLE_NEXUS);
571 }
572
573
574
575
576
577
578 public boolean isOpenSSLDisabled() {
579 return (line != null) && line.hasOption(ARGUMENT.DISABLE_OPENSSL);
580 }
581
582
583
584
585
586
587 public boolean isCentralDisabled() {
588 return (line != null) && line.hasOption(ARGUMENT.DISABLE_CENTRAL);
589 }
590
591
592
593
594
595
596 public String getNexusUrl() {
597 if (line == null || !line.hasOption(ARGUMENT.NEXUS_URL)) {
598 return null;
599 } else {
600 return line.getOptionValue(ARGUMENT.NEXUS_URL);
601 }
602 }
603
604
605
606
607
608
609 public boolean isNexusUsesProxy() {
610
611
612 if (line == null || !line.hasOption(ARGUMENT.NEXUS_USES_PROXY)) {
613 try {
614 return Settings.getBoolean(Settings.KEYS.ANALYZER_NEXUS_PROXY);
615 } catch (InvalidSettingException ise) {
616 return true;
617 }
618 } else {
619 return Boolean.parseBoolean(line.getOptionValue(ARGUMENT.NEXUS_USES_PROXY));
620 }
621 }
622
623
624
625
626 public void printHelp() {
627 final HelpFormatter formatter = new HelpFormatter();
628 final Options options = new Options();
629 addStandardOptions(options);
630 if (line != null && line.hasOption(ARGUMENT.ADVANCED_HELP)) {
631 addAdvancedOptions(options);
632 }
633 final String helpMsg = String.format("%n%s"
634 + " can be used to identify if there are any known CVE vulnerabilities in libraries utilized by an application. "
635 + "%s will automatically update required data from the Internet, such as the CVE and CPE data files from nvd.nist.gov.%n%n",
636 Settings.getString("application.name", "DependencyCheck"),
637 Settings.getString("application.name", "DependencyCheck"));
638
639 formatter.printHelp(Settings.getString("application.name", "DependencyCheck"),
640 helpMsg,
641 options,
642 "",
643 true);
644 }
645
646
647
648
649
650
651 public String[] getScanFiles() {
652 return line.getOptionValues(ARGUMENT.SCAN);
653 }
654
655
656
657
658
659
660 public String[] getExcludeList() {
661 return line.getOptionValues(ARGUMENT.EXCLUDE);
662 }
663
664
665
666
667
668
669 public String getReportDirectory() {
670 return line.getOptionValue(ARGUMENT.OUT, ".");
671 }
672
673
674
675
676
677
678 public String getPathToMono() {
679 return line.getOptionValue(ARGUMENT.PATH_TO_MONO);
680 }
681
682
683
684
685
686
687 public String getReportFormat() {
688 return line.getOptionValue(ARGUMENT.OUTPUT_FORMAT, "HTML");
689 }
690
691
692
693
694
695
696 public String getApplicationName() {
697 return line.getOptionValue(ARGUMENT.APP_NAME);
698 }
699
700
701
702
703
704
705 public String getBaseCve12Url() {
706 return line.getOptionValue(ARGUMENT.CVE_BASE_12);
707 }
708
709
710
711
712
713
714 public String getBaseCve20Url() {
715 return line.getOptionValue(ARGUMENT.CVE_BASE_20);
716 }
717
718
719
720
721
722
723 public String getModifiedCve12Url() {
724 return line.getOptionValue(ARGUMENT.CVE_MOD_12);
725 }
726
727
728
729
730
731
732 public String getModifiedCve20Url() {
733 return line.getOptionValue(ARGUMENT.CVE_MOD_20);
734 }
735
736
737
738
739
740
741 public String getConnectionTimeout() {
742 return line.getOptionValue(ARGUMENT.CONNECTION_TIMEOUT);
743 }
744
745
746
747
748
749
750 @SuppressWarnings("deprecation")
751 public String getProxyServer() {
752
753 String server = line.getOptionValue(ARGUMENT.PROXY_SERVER);
754 if (server == null) {
755 server = line.getOptionValue(ARGUMENT.PROXY_URL);
756 if (server != null) {
757 LOGGER.warn("An old command line argument 'proxyurl' was detected; use proxyserver instead");
758 }
759 }
760 return server;
761 }
762
763
764
765
766
767
768 public String getProxyPort() {
769 return line.getOptionValue(ARGUMENT.PROXY_PORT);
770 }
771
772
773
774
775
776
777 public String getProxyUsername() {
778 return line.getOptionValue(ARGUMENT.PROXY_USERNAME);
779 }
780
781
782
783
784
785
786 public String getProxyPassword() {
787 return line.getOptionValue(ARGUMENT.PROXY_PASSWORD);
788 }
789
790
791
792
793
794
795 public String getDataDirectory() {
796 return line.getOptionValue(ARGUMENT.DATA_DIRECTORY);
797 }
798
799
800
801
802
803
804 public File getPropertiesFile() {
805 final String path = line.getOptionValue(ARGUMENT.PROP);
806 if (path != null) {
807 return new File(path);
808 }
809 return null;
810 }
811
812
813
814
815
816
817 public String getVerboseLog() {
818 return line.getOptionValue(ARGUMENT.VERBOSE_LOG);
819 }
820
821
822
823
824
825
826 public String getSuppressionFile() {
827 return line.getOptionValue(ARGUMENT.SUPPRESSION_FILE);
828 }
829
830
831
832
833
834
835
836 public void printVersionInfo() {
837 final String version = String.format("%s version %s",
838 Settings.getString(Settings.KEYS.APPLICATION_VAME, "dependency-check"),
839 Settings.getString(Settings.KEYS.APPLICATION_VERSION, "Unknown"));
840 System.out.println(version);
841 }
842
843
844
845
846
847
848 public boolean isAutoUpdate() {
849 return (line == null) || !line.hasOption(ARGUMENT.DISABLE_AUTO_UPDATE);
850 }
851
852
853
854
855
856
857 public boolean isUpdateOnly() {
858 return (line == null) || line.hasOption(ARGUMENT.UPDATE_ONLY);
859 }
860
861
862
863
864
865
866 public String getDatabaseDriverName() {
867 return line.getOptionValue(ARGUMENT.DB_DRIVER);
868 }
869
870
871
872
873
874
875 public String getDatabaseDriverPath() {
876 return line.getOptionValue(ARGUMENT.DB_DRIVER_PATH);
877 }
878
879
880
881
882
883
884 public String getConnectionString() {
885 return line.getOptionValue(ARGUMENT.CONNECTION_STRING);
886 }
887
888
889
890
891
892
893 public String getDatabaseUser() {
894 return line.getOptionValue(ARGUMENT.DB_NAME);
895 }
896
897
898
899
900
901
902 public String getDatabasePassword() {
903 return line.getOptionValue(ARGUMENT.DB_PASSWORD);
904 }
905
906
907
908
909
910
911 public String getAdditionalZipExtensions() {
912 return line.getOptionValue(ARGUMENT.ADDITIONAL_ZIP_EXTENSIONS);
913 }
914
915
916
917
918 public static class ARGUMENT {
919
920
921
922
923 public static final String SCAN = "scan";
924
925
926
927 public static final String SCAN_SHORT = "s";
928
929
930
931 public static final String DISABLE_AUTO_UPDATE = "noupdate";
932
933
934
935 public static final String DISABLE_AUTO_UPDATE_SHORT = "n";
936
937
938
939 public static final String UPDATE_ONLY = "updateonly";
940
941
942
943 public static final String OUT = "out";
944
945
946
947 public static final String OUT_SHORT = "o";
948
949
950
951 public static final String OUTPUT_FORMAT = "format";
952
953
954
955 public static final String OUTPUT_FORMAT_SHORT = "f";
956
957
958
959 public static final String APP_NAME = "app";
960
961
962
963 public static final String APP_NAME_SHORT = "a";
964
965
966
967 public static final String HELP = "help";
968
969
970
971 public static final String ADVANCED_HELP = "advancedHelp";
972
973
974
975 public static final String HELP_SHORT = "h";
976
977
978
979 public static final String VERSION_SHORT = "v";
980
981
982
983 public static final String VERSION = "version";
984
985
986
987 public static final String PROXY_PORT = "proxyport";
988
989
990
991 public static final String PROXY_SERVER = "proxyserver";
992
993
994
995
996
997 @Deprecated
998 public static final String PROXY_URL = "proxyurl";
999
1000
1001
1002 public static final String PROXY_USERNAME = "proxyuser";
1003
1004
1005
1006 public static final String PROXY_PASSWORD = "proxypass";
1007
1008
1009
1010 public static final String CONNECTION_TIMEOUT_SHORT = "c";
1011
1012
1013
1014 public static final String CONNECTION_TIMEOUT = "connectiontimeout";
1015
1016
1017
1018 public static final String PROP_SHORT = "P";
1019
1020
1021
1022 public static final String PROP = "propertyfile";
1023
1024
1025
1026 public static final String DATA_DIRECTORY = "data";
1027
1028
1029
1030 public static final String CVE_MOD_12 = "cveUrl12Modified";
1031
1032
1033
1034 public static final String CVE_MOD_20 = "cveUrl20Modified";
1035
1036
1037
1038 public static final String CVE_BASE_12 = "cveUrl12Base";
1039
1040
1041
1042 public static final String CVE_BASE_20 = "cveUrl20Base";
1043
1044
1045
1046 public static final String DATA_DIRECTORY_SHORT = "d";
1047
1048
1049
1050 public static final String VERBOSE_LOG = "log";
1051
1052
1053
1054 public static final String VERBOSE_LOG_SHORT = "l";
1055
1056
1057
1058
1059 public static final String SYM_LINK_DEPTH = "symLink";
1060
1061
1062
1063 public static final String SUPPRESSION_FILE = "suppression";
1064
1065
1066
1067 public static final String DISABLE_JAR = "disableJar";
1068
1069
1070
1071 public static final String DISABLE_ARCHIVE = "disableArchive";
1072
1073
1074
1075 public static final String DISABLE_PY_DIST = "disablePyDist";
1076
1077
1078
1079 public static final String DISABLE_PY_PKG = "disablePyPkg";
1080
1081
1082
1083 public static final String DISABLE_AUTOCONF = "disableAutoconf";
1084
1085
1086
1087 public static final String DISABLE_CMAKE = "disableCmake";
1088
1089
1090
1091 public static final String DISABLE_ASSEMBLY = "disableAssembly";
1092
1093
1094
1095 public static final String DISABLE_NUSPEC = "disableNuspec";
1096
1097
1098
1099 public static final String DISABLE_CENTRAL = "disableCentral";
1100
1101
1102
1103 public static final String DISABLE_NEXUS = "disableNexus";
1104
1105
1106
1107 public static final String DISABLE_OPENSSL = "disableOpenSSL";
1108
1109
1110
1111 public static final String NEXUS_URL = "nexus";
1112
1113
1114
1115 public static final String NEXUS_USES_PROXY = "nexusUsesProxy";
1116
1117
1118
1119 public static final String CONNECTION_STRING = "connectionString";
1120
1121
1122
1123 public static final String DB_NAME = "dbUser";
1124
1125
1126
1127 public static final String DB_PASSWORD = "dbPassword";
1128
1129
1130
1131 public static final String DB_DRIVER = "dbDriverName";
1132
1133
1134
1135 public static final String DB_DRIVER_PATH = "dbDriverPath";
1136
1137
1138
1139 public static final String PATH_TO_MONO = "mono";
1140
1141
1142
1143 public static final String ADDITIONAL_ZIP_EXTENSIONS = "zipExtensions";
1144
1145
1146
1147 public static final String EXCLUDE = "exclude";
1148 }
1149 }