mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-01-16 08:36:55 +01:00
Add support for extra extensions provided externally
Former-commit-id: 6c8632566de0a46ff4ce24ef5285bbd84c8ef89f
This commit is contained in:
@@ -21,10 +21,14 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.owasp.dependencycheck.analyzer.Analyzer;
|
||||
import org.owasp.dependencycheck.analyzer.ArchiveAnalyzer;
|
||||
import org.owasp.dependencycheck.cli.CliParser;
|
||||
import org.owasp.dependencycheck.data.nvdcve.CveDB;
|
||||
import org.owasp.dependencycheck.data.nvdcve.DatabaseException;
|
||||
@@ -83,7 +87,7 @@ public class App {
|
||||
cli.printVersionInfo();
|
||||
} else if (cli.isRunScan()) {
|
||||
updateSettings(cli);
|
||||
runScan(cli.getReportDirectory(), cli.getReportFormat(), cli.getApplicationName(), cli.getScanFiles());
|
||||
runScan(cli.getReportDirectory(), cli.getReportFormat(), cli.getApplicationName(), cli.getScanFiles(), cli.getExtraExtensions());
|
||||
} else {
|
||||
cli.printHelp();
|
||||
}
|
||||
@@ -97,9 +101,14 @@ public class App {
|
||||
* @param applicationName the application name for the report
|
||||
* @param files the files/directories to scan
|
||||
*/
|
||||
private void runScan(String reportDirectory, String outputFormat, String applicationName, String[] files) {
|
||||
private void runScan(String reportDirectory, String outputFormat, String applicationName, String[] files, String extraExtensions) {
|
||||
final Engine scanner = new Engine();
|
||||
|
||||
if (extraExtensions != null && ! extraExtensions.isEmpty())
|
||||
for (Analyzer analyzer : scanner.getAnalyzers())
|
||||
if (analyzer instanceof ArchiveAnalyzer)
|
||||
((ArchiveAnalyzer)analyzer).addSupportedExtensions(new HashSet<String>(Arrays.asList(extraExtensions.split("\\s*,\\s*"))));
|
||||
|
||||
for (String file : files) {
|
||||
scanner.scan(file);
|
||||
}
|
||||
@@ -155,6 +164,7 @@ public class App {
|
||||
final String connectionString = cli.getConnectionString();
|
||||
final String databaseUser = cli.getDatabaseUser();
|
||||
final String databasePassword = cli.getDatabasePassword();
|
||||
final String extraExtensions = cli.getExtraExtensions();
|
||||
|
||||
if (propertiesFile != null) {
|
||||
try {
|
||||
@@ -220,5 +230,8 @@ public class App {
|
||||
if (databasePassword != null && !databasePassword.isEmpty()) {
|
||||
Settings.setString(Settings.KEYS.DB_PASSWORD, databasePassword);
|
||||
}
|
||||
if (extraExtensions!= null && !extraExtensions.isEmpty()) {
|
||||
Settings.setString(Settings.KEYS.EXTRA_EXTENSIONS, extraExtensions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,6 +204,10 @@ public final class CliParser {
|
||||
.withDescription("The url to the Nexus Server.")
|
||||
.create();
|
||||
|
||||
final Option extraExtensions = OptionBuilder.withArgName("extraExtensions").hasArg().withLongOpt(ArgumentName.EXTRA_EXTENSIONS)
|
||||
.withDescription("List of extra extensions to be scanned")
|
||||
.create();
|
||||
|
||||
//This is an option group because it can be specified more then once.
|
||||
final OptionGroup og = new OptionGroup();
|
||||
og.addOption(path);
|
||||
@@ -220,7 +224,8 @@ public final class CliParser {
|
||||
.addOption(verboseLog)
|
||||
.addOption(suppressionFile)
|
||||
.addOption(disableNexusAnalyzer)
|
||||
.addOption(nexusUrl);
|
||||
.addOption(nexusUrl)
|
||||
.addOption(extraExtensions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -548,6 +553,15 @@ public final class CliParser {
|
||||
return line.getOptionValue(ArgumentName.DB_PASSWORD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the extra Extensions if specified; otherwise null is returned.
|
||||
*
|
||||
* @return the extra Extensions; otherwise null is returned
|
||||
*/
|
||||
public String getExtraExtensions() {
|
||||
return line.getOptionValue(ArgumentName.EXTRA_EXTENSIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* A collection of static final strings that represent the possible command line arguments.
|
||||
*/
|
||||
@@ -701,5 +715,9 @@ public final class CliParser {
|
||||
* The CLI argument name for setting the path to the database driver; in case it is not on the class path.
|
||||
*/
|
||||
public static final String DB_DRIVER_PATH = "dbDriverPath";
|
||||
/**
|
||||
* The CLI argument name for setting extra extensions.
|
||||
*/
|
||||
public static final String EXTRA_EXTENSIONS = "extraExtension";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user