Compare commits

...

14 Commits

Author SHA1 Message Date
Jeremy Long
3553489f2e version 1.0.4
Former-commit-id: 4792f22bc0e21dec5078790bbd266030185f1a04
2013-10-21 21:16:20 -04:00
Jeremy Long
f74efd5b96 initial version
Former-commit-id: c5b10651f9973aa1d6355f2aebdc5681923c18ea
2013-10-20 21:29:12 -04:00
Jeremy Long
ba887fdf21 moved logging initializatoin to utility class
Former-commit-id: 421c728e8033b2783647baf0c9e4aaac86d322d7
2013-10-20 21:28:45 -04:00
Jeremy Long
3995cd64da updated to make tests go faster. Only downloading recent CVE data files
Former-commit-id: 970c4b77eecbd265e1f966fd877b78f87a3d9f51
2013-10-20 21:28:00 -04:00
Jeremy Long
9fdf22a475 added anoter mergeProperties to take a File object instead of a String path
Former-commit-id: efd4a93b47beac16c7005bf8dc62436de4c2cde6
2013-10-20 21:27:18 -04:00
Jeremy Long
5980d0a6fa updated initialize to not ignore errors generaged when creating directories
Former-commit-id: 10f4a9e962f82dbb4be426bc681c9a1cf32a8637
2013-10-20 21:26:18 -04:00
Jeremy Long
21f8b0b553 minor update to logged message
Former-commit-id: d4a7d9435f654c7a52f426460cd9723bbc16cbcc
2013-10-20 21:25:25 -04:00
Jeremy Long
d98ca9d21f minor change to FileHandler.pattern
Former-commit-id: a62df7faab98abd38eb3bcfd08d7da982a2a4704
2013-10-20 21:24:42 -04:00
Jeremy Long
fe2cdfe81a added cli argument to enable verbose logging
Former-commit-id: 9d0d5edb8ad17cd72eb480f03c31b1c9a93ad735
2013-10-20 21:23:59 -04:00
Jeremy Long
878d9ad8d9 moved logger setup to utility class
Former-commit-id: 347819ac9e660f494eb4c00914779dbbbecccf4d
2013-10-20 21:23:13 -04:00
Jeremy Long
e25961f40c moved logger setup to utlity class
Former-commit-id: 20d462ce61629a17064ee5887154ee7d53431fb8
2013-10-20 21:22:34 -04:00
Jeremy Long
7987800567 improved logging
Former-commit-id: b1a7147c8da8263deedcc9a69f814dc8c825299d
2013-10-15 21:03:10 -04:00
Jeremy Long
daec4c2e4e fixed npe
Former-commit-id: b0db873cacc6c2d931b97d33c8b028a7e603220e
2013-10-15 20:34:34 -04:00
Jeremy Long
5ea52b47ab version 1.0.4-SNAPSHOT
Former-commit-id: 80cf3b1ca2fa65ad4d7fd949dafa8202193e8150
2013-10-14 14:05:15 -04:00
18 changed files with 252 additions and 105 deletions

View File

@@ -22,7 +22,7 @@ Copyright (c) 2013 - Jeremy Long. All Rights Reserved.
<parent> <parent>
<groupId>org.owasp</groupId> <groupId>org.owasp</groupId>
<artifactId>dependency-check-parent</artifactId> <artifactId>dependency-check-parent</artifactId>
<version>1.0.3</version> <version>1.0.4</version>
</parent> </parent>
<artifactId>dependency-check-ant</artifactId> <artifactId>dependency-check-ant</artifactId>

View File

@@ -23,7 +23,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
@@ -38,6 +37,7 @@ import org.owasp.dependencycheck.dependency.Dependency;
import org.owasp.dependencycheck.dependency.Vulnerability; import org.owasp.dependencycheck.dependency.Vulnerability;
import org.owasp.dependencycheck.reporting.ReportGenerator; import org.owasp.dependencycheck.reporting.ReportGenerator;
import org.owasp.dependencycheck.reporting.ReportGenerator.Format; import org.owasp.dependencycheck.reporting.ReportGenerator.Format;
import org.owasp.dependencycheck.utils.LogUtils;
import org.owasp.dependencycheck.utils.Settings; import org.owasp.dependencycheck.utils.Settings;
/** /**
@@ -345,41 +345,33 @@ public class DependencyCheckTask extends Task {
public void setConnectionTimeout(String connectionTimeout) { public void setConnectionTimeout(String connectionTimeout) {
this.connectionTimeout = connectionTimeout; this.connectionTimeout = connectionTimeout;
} }
/**
* The file path used for verbose logging.
*/
private String logFile = null;
/** /**
* Configures the logger for use by the application. * Get the value of logFile.
*
* @return the value of logFile
*/ */
private static void prepareLogger() { public String getLogFile() {
InputStream in = null; return logFile;
try { }
in = DependencyCheckTask.class.getClassLoader().getResourceAsStream(LOG_PROPERTIES_FILE);
LogManager.getLogManager().reset(); /**
LogManager.getLogManager().readConfiguration(in); * Set the value of logFile.
//TODO add code to disable fine grained log file. *
// Logger logger = LogManager.getLogManager().getLogger(""); * @param logFile new value of logFile
// for (Handler h : logger.getHandlers()) { */
// if (h.getFormatter(). h.toString()); public void setLogFile(String logFile) {
// } this.logFile = logFile;
} catch (IOException ex) {
System.err.println(ex.toString());
Logger.getLogger(DependencyCheckTask.class.getName()).log(Level.SEVERE, null, ex);
} catch (SecurityException ex) {
Logger.getLogger(DependencyCheckTask.class.getName()).log(Level.SEVERE, null, ex);
} finally {
if (in != null) {
try {
in.close();
} catch (Exception ex) {
//noinspection UnusedAssignment
in = null;
}
}
}
} }
@Override @Override
public void execute() throws BuildException { public void execute() throws BuildException {
prepareLogger(); final InputStream in = DependencyCheckTask.class.getClassLoader().getResourceAsStream(LOG_PROPERTIES_FILE);
LogUtils.prepareLogger(in, logFile);
dealWithReferences(); dealWithReferences();
validateConfiguration(); validateConfiguration();
@@ -512,6 +504,7 @@ public class DependencyCheckTask extends Task {
* *
* @return the list of values for the report format * @return the list of values for the report format
*/ */
@Override
public String[] getValues() { public String[] getValues() {
int i = 0; int i = 0;
final Format[] formats = Format.values(); final Format[] formats = Format.values();

View File

@@ -22,7 +22,7 @@ Copyright (c) 2012 - Jeremy Long. All Rights Reserved.
<parent> <parent>
<groupId>org.owasp</groupId> <groupId>org.owasp</groupId>
<artifactId>dependency-check-parent</artifactId> <artifactId>dependency-check-parent</artifactId>
<version>1.0.3</version> <version>1.0.4</version>
</parent> </parent>
<artifactId>dependency-check-cli</artifactId> <artifactId>dependency-check-cli</artifactId>

View File

@@ -24,12 +24,12 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.apache.commons.cli.ParseException; import org.apache.commons.cli.ParseException;
import org.owasp.dependencycheck.reporting.ReportGenerator; import org.owasp.dependencycheck.reporting.ReportGenerator;
import org.owasp.dependencycheck.dependency.Dependency; import org.owasp.dependencycheck.dependency.Dependency;
import org.owasp.dependencycheck.cli.CliParser; import org.owasp.dependencycheck.cli.CliParser;
import org.owasp.dependencycheck.utils.LogUtils;
import org.owasp.dependencycheck.utils.Settings; import org.owasp.dependencycheck.utils.Settings;
/* /*
@@ -67,35 +67,10 @@ public class App {
* @param args the command line arguments * @param args the command line arguments
*/ */
public static void main(String[] args) { public static void main(String[] args) {
prepareLogger();
final App app = new App(); final App app = new App();
app.run(args); app.run(args);
} }
/**
* Configures the logger for use by the application.
*/
private static void prepareLogger() {
InputStream in = null;
try {
in = App.class.getClassLoader().getResourceAsStream(LOG_PROPERTIES_FILE);
LogManager.getLogManager().reset();
LogManager.getLogManager().readConfiguration(in);
} catch (IOException ex) {
Logger.getLogger(App.class.getName()).log(Level.FINE, "IO Error preparing the logger", ex);
} catch (SecurityException ex) {
Logger.getLogger(App.class.getName()).log(Level.FINE, "Error preparing the logger", ex);
} finally {
if (in != null) {
try {
in.close();
} catch (Exception ex) {
Logger.getLogger(App.class.getName()).log(Level.FINEST, "Error closing resource stream", ex);
}
}
}
}
/** /**
* Main CLI entry-point into the application. * Main CLI entry-point into the application.
* *
@@ -116,10 +91,14 @@ public class App {
return; return;
} }
final InputStream in = App.class.getClassLoader().getResourceAsStream(LOG_PROPERTIES_FILE);
LogUtils.prepareLogger(in, cli.getVerboseLog());
if (cli.isGetVersion()) { if (cli.isGetVersion()) {
cli.printVersionInfo(); cli.printVersionInfo();
} else if (cli.isRunScan()) { } else if (cli.isRunScan()) {
updateSettings(cli.isAutoUpdate(), cli.getConnectionTimeout(), cli.getProxyUrl(), cli.getProxyPort(), cli.getDataDirectory()); updateSettings(cli.isAutoUpdate(), cli.getConnectionTimeout(), cli.getProxyUrl(),
cli.getProxyPort(), cli.getDataDirectory(), cli.getPropertiesFile());
runScan(cli.getReportDirectory(), cli.getReportFormat(), cli.getApplicationName(), cli.getScanFiles()); runScan(cli.getReportDirectory(), cli.getReportFormat(), cli.getApplicationName(), cli.getScanFiles());
} else { } else {
cli.printHelp(); cli.printHelp();
@@ -168,8 +147,24 @@ public class App {
* @param proxyPort the proxy port (null or blank means no port will be * @param proxyPort the proxy port (null or blank means no port will be
* used) * used)
* @param dataDirectory the directory to store/retrieve persistent data from * @param dataDirectory the directory to store/retrieve persistent data from
* @param propertiesFile the properties file to utilize
*/ */
private void updateSettings(boolean autoUpdate, String connectionTimeout, String proxyUrl, String proxyPort, String dataDirectory) { private void updateSettings(boolean autoUpdate, String connectionTimeout, String proxyUrl,
String proxyPort, String dataDirectory, File propertiesFile) {
if (propertiesFile != null) {
try {
Settings.mergeProperties(propertiesFile);
} catch (FileNotFoundException ex) {
final String msg = String.format("Unable to load properties file '%s'", propertiesFile.getPath());
Logger.getLogger(App.class.getName()).log(Level.SEVERE, msg);
Logger.getLogger(App.class.getName()).log(Level.FINE, null, ex);
} catch (IOException ex) {
final String msg = String.format("Unable to find properties file '%s'", propertiesFile.getPath());
Logger.getLogger(App.class.getName()).log(Level.SEVERE, msg);
Logger.getLogger(App.class.getName()).log(Level.FINE, null, ex);
}
}
if (dataDirectory != null) { if (dataDirectory != null) {
Settings.setString(Settings.KEYS.DATA_DIRECTORY, dataDirectory); Settings.setString(Settings.KEYS.DATA_DIRECTORY, dataDirectory);
} else if (System.getProperty("basedir") != null) { } else if (System.getProperty("basedir") != null) {
@@ -182,8 +177,6 @@ public class App {
final File dataDir = new File(base, sub); final File dataDir = new File(base, sub);
Settings.setString(Settings.KEYS.DATA_DIRECTORY, dataDir.getAbsolutePath()); Settings.setString(Settings.KEYS.DATA_DIRECTORY, dataDir.getAbsolutePath());
} }
Settings.setBoolean(Settings.KEYS.AUTO_UPDATE, autoUpdate); Settings.setBoolean(Settings.KEYS.AUTO_UPDATE, autoUpdate);
if (proxyUrl != null && !proxyUrl.isEmpty()) { if (proxyUrl != null && !proxyUrl.isEmpty()) {
Settings.setString(Settings.KEYS.PROXY_URL, proxyUrl); Settings.setString(Settings.KEYS.PROXY_URL, proxyUrl);

View File

@@ -195,6 +195,10 @@ public final class CliParser {
.withDescription("The output format to write to (XML, HTML, VULN, ALL). The default is HTML.") .withDescription("The output format to write to (XML, HTML, VULN, ALL). The default is HTML.")
.create(ArgumentName.OUTPUT_FORMAT_SHORT); .create(ArgumentName.OUTPUT_FORMAT_SHORT);
final Option verboseLog = OptionBuilder.withArgName("file").hasArg().withLongOpt(ArgumentName.VERBOSE_LOG)
.withDescription("The file path to write verbose logging information.")
.create(ArgumentName.VERBOSE_LOG_SHORT);
final OptionGroup og = new OptionGroup(); final OptionGroup og = new OptionGroup();
og.addOption(path); og.addOption(path);
@@ -208,6 +212,7 @@ public final class CliParser {
opts.addOption(noUpdate); opts.addOption(noUpdate);
opts.addOption(props); opts.addOption(props);
opts.addOption(data); opts.addOption(data);
opts.addOption(verboseLog);
opts.addOption(proxyPort); opts.addOption(proxyPort);
opts.addOption(proxyUrl); opts.addOption(proxyUrl);
opts.addOption(connectionTimeout); opts.addOption(connectionTimeout);
@@ -334,6 +339,28 @@ public final class CliParser {
return line.getOptionValue(ArgumentName.DATA_DIRECTORY); return line.getOptionValue(ArgumentName.DATA_DIRECTORY);
} }
/**
* Returns the properties file specified on the command line.
*
* @return the properties file specified on the command line
*/
public File getPropertiesFile() {
final String path = line.getOptionValue(ArgumentName.PROP);
if (path != null) {
return new File(path);
}
return null;
}
/**
* Returns the path to the verbose log file.
*
* @return the path to the verbose log file
*/
public String getVerboseLog() {
return line.getOptionValue(ArgumentName.VERBOSE_LOG);
}
/** /**
* <p>Prints the manifest information to standard output.</p> * <p>Prints the manifest information to standard output.</p>
* <ul><li>Implementation-Title: ${pom.name}</li> * <ul><li>Implementation-Title: ${pom.name}</li>
@@ -469,5 +496,14 @@ public final class CliParser {
* directory. * directory.
*/ */
public static final String DATA_DIRECTORY_SHORT = "d"; public static final String DATA_DIRECTORY_SHORT = "d";
/**
* The CLI argument name for setting the location of the data directory.
*/
public static final String VERBOSE_LOG = "log";
/**
* The short CLI argument name for setting the location of the data
* directory.
*/
public static final String VERBOSE_LOG_SHORT = "l";
} }
} }

View File

@@ -7,8 +7,6 @@ handlers=java.util.logging.ConsoleHandler
# Configure the ConsoleHandler. # Configure the ConsoleHandler.
java.util.logging.ConsoleHandler.level=INFO java.util.logging.ConsoleHandler.level=INFO
org.owasp.dependencycheck.data.nvdcve.xml
# Configure the FileHandler. # Configure the FileHandler.
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.FileHandler.level=FINE java.util.logging.FileHandler.level=FINE
@@ -21,4 +19,4 @@ java.util.logging.FileHandler.level=FINE
# %g - generation number for rotating logs # %g - generation number for rotating logs
# %u - unique number to avoid conflicts # %u - unique number to avoid conflicts
# FileHandler writes to %h/demo0.log by default. # FileHandler writes to %h/demo0.log by default.
java.util.logging.FileHandler.pattern=./logs/DependencyCheck.log java.util.logging.FileHandler.pattern=./dependency-check.log

View File

@@ -22,7 +22,7 @@ along with Dependency-Check. If not, see <http://www.gnu.org/licenses />.
<parent> <parent>
<groupId>org.owasp</groupId> <groupId>org.owasp</groupId>
<artifactId>dependency-check-parent</artifactId> <artifactId>dependency-check-parent</artifactId>
<version>1.0.3</version> <version>1.0.4</version>
</parent> </parent>
<artifactId>dependency-check-core</artifactId> <artifactId>dependency-check-core</artifactId>

View File

@@ -282,11 +282,13 @@ public class Engine {
final List<Analyzer> analyzerList = analyzers.get(phase); final List<Analyzer> analyzerList = analyzers.get(phase);
for (Analyzer a : analyzerList) { for (Analyzer a : analyzerList) {
try { try {
final String msg = String.format("Initializing %s", a.getName());
Logger.getLogger(Engine.class.getName()).log(Level.FINE, msg);
a.initialize(); a.initialize();
} catch (Exception ex) { } catch (Exception ex) {
final String msg = String.format("\"Exception occurred initializing \"%s\".\"", a.getName()); final String msg = String.format("Exception occurred initializing %s.", a.getName());
Logger.getLogger(Engine.class.getName()).log(Level.SEVERE, msg); Logger.getLogger(Engine.class.getName()).log(Level.SEVERE, msg);
Logger.getLogger(Engine.class.getName()).log(Level.INFO, msg, ex); Logger.getLogger(Engine.class.getName()).log(Level.INFO, null, ex);
try { try {
a.close(); a.close();
} catch (Exception ex1) { } catch (Exception ex1) {
@@ -305,9 +307,13 @@ public class Engine {
* analyzers may modify it. This prevents ConcurrentModificationExceptions. * analyzers may modify it. This prevents ConcurrentModificationExceptions.
* This is okay for adds/deletes because it happens per analyzer. * This is okay for adds/deletes because it happens per analyzer.
*/ */
final String msg = String.format("Begin Analyzer '%s'", a.getName());
Logger.getLogger(Engine.class.getName()).log(Level.FINE, msg);
final Set<Dependency> dependencySet = new HashSet<Dependency>(); final Set<Dependency> dependencySet = new HashSet<Dependency>();
dependencySet.addAll(dependencies); dependencySet.addAll(dependencies);
for (Dependency d : dependencySet) { for (Dependency d : dependencySet) {
final String msgFile = String.format("Begin Analysis of '%s'", d.getActualFilePath());
Logger.getLogger(Engine.class.getName()).log(Level.FINE, msgFile);
if (a.supportsExtension(d.getFileExtension())) { if (a.supportsExtension(d.getFileExtension())) {
try { try {
a.analyze(d, this); a.analyze(d, this);
@@ -323,6 +329,8 @@ public class Engine {
for (AnalysisPhase phase : AnalysisPhase.values()) { for (AnalysisPhase phase : AnalysisPhase.values()) {
final List<Analyzer> analyzerList = analyzers.get(phase); final List<Analyzer> analyzerList = analyzers.get(phase);
for (Analyzer a : analyzerList) { for (Analyzer a : analyzerList) {
final String msg = String.format("Closing Analyzer '%s'", a.getName());
Logger.getLogger(Engine.class.getName()).log(Level.FINE, msg);
try { try {
a.close(); a.close();
} catch (Exception ex) { } catch (Exception ex) {

View File

@@ -145,7 +145,10 @@ public class ArchiveAnalyzer extends AbstractAnalyzer implements Analyzer {
public void initialize() throws Exception { public void initialize() throws Exception {
final File baseDir = Settings.getTempDirectory(); final File baseDir = Settings.getTempDirectory();
if (!baseDir.exists()) { if (!baseDir.exists()) {
baseDir.mkdirs(); if (!baseDir.mkdirs()) {
final String msg = String.format("Unable to make a temporary folder '%s'", baseDir.getPath());
throw new AnalysisException(msg);
}
} }
tempFileLocation = File.createTempFile("check", "tmp", baseDir); tempFileLocation = File.createTempFile("check", "tmp", baseDir);
if (!tempFileLocation.delete()) { if (!tempFileLocation.delete()) {

View File

@@ -444,6 +444,9 @@ public class CPEAnalyzer implements Analyzer {
//</editor-fold> //</editor-fold>
//TODO - likely need to change the split... not sure if this will work for CPE with special chars //TODO - likely need to change the split... not sure if this will work for CPE with special chars
if (text == null) {
return false;
}
final String[] words = text.split("[\\s_-]"); final String[] words = text.split("[\\s_-]");
final List<String> list = new ArrayList<String>(); final List<String> list = new ArrayList<String>();
String tempWord = null; String tempWord = null;

View File

@@ -0,0 +1,44 @@
/*
* This file is part of dependency-check-core.
*
* Dependency-check-core is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Dependency-check-core is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* dependency-check-core. If not, see http://www.gnu.org/licenses/.
*
* Copyright (c) 2013 Jeremy Long. All Rights Reserved.
*/
package org.owasp.dependencycheck.utils;
import java.util.logging.Filter;
import java.util.logging.LogRecord;
/**
* A simple log filter to limit the entries written to the verbose log file. The
* verbose log file uses the root logger as I couldn't get anything else to
* work; as such, this filter limits the log entries to specific classes.
*
* @author Jeremy Long (jeremy.long@owasp.org)
*/
public class LogFilter implements Filter {
/**
* Determines if the record should be logged.
*
* @param record a log record to examine
* @return true if the record should be logged, otherwise false
*/
@Override
public boolean isLoggable(LogRecord record) {
final String name = record.getSourceClassName();
return name.startsWith("org.owasp.dependencycheck") && !name.contains("generated") && !name.contains("VelocityLoggerRedirect");
}
}

View File

@@ -0,0 +1,75 @@
/*
* This file is part of dependency-check-core.
*
* Dependency-check-core is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Dependency-check-core is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* dependency-check-core. If not, see http://www.gnu.org/licenses/.
*
* Copyright (c) 2013 Jeremy Long. All Rights Reserved.
*/
package org.owasp.dependencycheck.utils;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
/**
* A utility class to aide in the setup of the logging mechanism.
*
* @author Jeremy Long (jeremy.long@owasp.org)
*/
public final class LogUtils {
/**
* Private constructor for a utility class.
*/
private LogUtils() {
}
/**
* Configures the logger for use by the application.
*
* @param in the input stream to read the log settings from
* @param verboseLogFile the file path for the verbose log
*/
public static void prepareLogger(InputStream in, String verboseLogFile) {
try {
LogManager.getLogManager().reset();
LogManager.getLogManager().readConfiguration(in);
if (verboseLogFile != null && !verboseLogFile.isEmpty()) {
final Logger logger = Logger.getLogger("");
final FileHandler handler = new FileHandler(verboseLogFile, true);
handler.setFormatter(new SimpleFormatter());
handler.setLevel(Level.FINE);
handler.setFilter(new LogFilter());
logger.addHandler(handler);
logger.setLevel(Level.FINE);
}
} catch (IOException ex) {
Logger.getLogger(LogUtils.class.getName()).log(Level.FINE, "IO Error preparing the logger", ex);
} catch (SecurityException ex) {
Logger.getLogger(LogUtils.class.getName()).log(Level.FINE, "Error preparing the logger", ex);
} finally {
if (in != null) {
try {
in.close();
} catch (Exception ex) {
Logger.getLogger(LogUtils.class.getName()).log(Level.FINEST, "Error closing resource stream", ex);
}
}
}
}
}

View File

@@ -195,6 +195,23 @@ public final class Settings {
} }
} }
/**
* Merges a new properties file into the current properties. This method
* allows for the loading of a user provided properties file.<br/><br/>
* Note: even if using this method - system properties will be loaded before
* properties loaded from files.
*
* @param filePath the path to the properties file to merge.
* @throws FileNotFoundException is thrown when the filePath points to a
* non-existent file
* @throws IOException is thrown when there is an exception loading/merging
* the properties
*/
public static void mergeProperties(File filePath) throws FileNotFoundException, IOException {
final FileInputStream fis = new FileInputStream(filePath);
mergeProperties(fis);
}
/** /**
* Merges a new properties file into the current properties. This method * Merges a new properties file into the current properties. This method
* allows for the loading of a user provided properties file.<br/><br/> * allows for the loading of a user provided properties file.<br/><br/>

View File

@@ -26,7 +26,7 @@ cve.url.modified.validfordays=7
# the path to the modified nvd cve xml file. # the path to the modified nvd cve xml file.
cve.url-1.2.modified=http://nvd.nist.gov/download/nvdcve-modified.xml cve.url-1.2.modified=http://nvd.nist.gov/download/nvdcve-modified.xml
cve.url-2.0.modified=http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-modified.xml cve.url-2.0.modified=http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-modified.xml
cve.startyear=2002 cve.startyear=2013
cve.url-2.0.base=http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-%d.xml cve.url-2.0.base=http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-%d.xml
cve.url-1.2.base=http://nvd.nist.gov/download/nvdcve-%d.xml cve.url-1.2.base=http://nvd.nist.gov/download/nvdcve-%d.xml
#cve.url-2.0.base=file:///C:/data/xml/nvdcve-2.0-%d.xml #cve.url-2.0.base=file:///C:/data/xml/nvdcve-2.0-%d.xml

View File

@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>org.owasp</groupId> <groupId>org.owasp</groupId>
<artifactId>dependency-check-parent</artifactId> <artifactId>dependency-check-parent</artifactId>
<version>1.0.3</version> <version>1.0.4</version>
</parent> </parent>
<groupId>org.owasp</groupId> <groupId>org.owasp</groupId>

View File

@@ -24,7 +24,7 @@ Copyright (c) 2013 Jeremy Long. All Rights Reserved.
<parent> <parent>
<groupId>org.owasp</groupId> <groupId>org.owasp</groupId>
<artifactId>dependency-check-parent</artifactId> <artifactId>dependency-check-parent</artifactId>
<version>1.0.3</version> <version>1.0.4</version>
</parent> </parent>
<artifactId>dependency-check-maven</artifactId> <artifactId>dependency-check-maven</artifactId>

View File

@@ -34,7 +34,6 @@ import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import java.util.Set; import java.util.Set;
import java.util.logging.LogManager;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -54,6 +53,7 @@ import org.owasp.dependencycheck.dependency.Reference;
import org.owasp.dependencycheck.dependency.Vulnerability; import org.owasp.dependencycheck.dependency.Vulnerability;
import org.owasp.dependencycheck.dependency.VulnerableSoftware; import org.owasp.dependencycheck.dependency.VulnerableSoftware;
import org.owasp.dependencycheck.reporting.ReportGenerator; import org.owasp.dependencycheck.reporting.ReportGenerator;
import org.owasp.dependencycheck.utils.LogUtils;
import org.owasp.dependencycheck.utils.Settings; import org.owasp.dependencycheck.utils.Settings;
/** /**
@@ -90,6 +90,11 @@ public class DependencyCheckMojo extends AbstractMojo implements MavenMultiPageR
*/ */
@Parameter(property = "report-name", defaultValue = "dependency-check-report") @Parameter(property = "report-name", defaultValue = "dependency-check-report")
private String reportName; private String reportName;
/**
* The path to the verbose log
*/
@Parameter(property = "logfile", defaultValue = "")
private String logFile;
/** /**
* The name of the report to be displayed in the Maven Generated Reports * The name of the report to be displayed in the Maven Generated Reports
* page * page
@@ -163,44 +168,16 @@ public class DependencyCheckMojo extends AbstractMojo implements MavenMultiPageR
private String connectionTimeout = null; private String connectionTimeout = null;
// </editor-fold> // </editor-fold>
/**
* Configures the logger for use by the application.
*/
private static void prepareLogger() {
InputStream in = null;
try {
in = DependencyCheckMojo.class.getClassLoader().getResourceAsStream(LOG_PROPERTIES_FILE);
LogManager.getLogManager().reset();
LogManager.getLogManager().readConfiguration(in);
//TODO add code to disable fine grained log file.
// Logger logger = LogManager.getLogManager().getLogger("");
// for (Handler h : logger.getHandlers()) {
// if (h.getFormatter(). h.toString());
// }
} catch (IOException ex) {
System.err.println(ex.toString());
Logger.getLogger(DependencyCheckMojo.class.getName()).log(Level.SEVERE, null, ex);
} catch (SecurityException ex) {
Logger.getLogger(DependencyCheckMojo.class.getName()).log(Level.SEVERE, null, ex);
} finally {
if (in != null) {
try {
in.close();
} catch (Exception ex) {
//noinspection UnusedAssignment
in = null;
}
}
}
}
/** /**
* Executes the Dependency-Check on the dependent libraries. * Executes the Dependency-Check on the dependent libraries.
* *
* @return the Engine used to scan the dependencies. * @return the Engine used to scan the dependencies.
*/ */
private Engine executeDependencyCheck() { private Engine executeDependencyCheck() {
prepareLogger();
final InputStream in = DependencyCheckMojo.class.getClassLoader().getResourceAsStream(LOG_PROPERTIES_FILE);
LogUtils.prepareLogger(in, logFile);
populateSettings(); populateSettings();
final Engine engine = new Engine(); final Engine engine = new Engine();
final Set<Artifact> artifacts = project.getArtifacts(); final Set<Artifact> artifacts = project.getArtifacts();

View File

@@ -22,7 +22,7 @@ along with Dependency-Check. If not, see <http://www.gnu.org/licenses />.
<groupId>org.owasp</groupId> <groupId>org.owasp</groupId>
<artifactId>dependency-check-parent</artifactId> <artifactId>dependency-check-parent</artifactId>
<version>1.0.3</version> <version>1.0.4</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<parent> <parent>