updated method names to better state what is happening

This commit is contained in:
Jeremy Long
2017-09-11 12:55:08 -04:00
parent e5eb056324
commit e45a5a99c3
48 changed files with 206 additions and 208 deletions

View File

@@ -277,7 +277,7 @@ public class Engine implements FileFilter, AutoCloseable {
final AnalyzerService service = new AnalyzerService(serviceClassLoader, loadExperimental); final AnalyzerService service = new AnalyzerService(serviceClassLoader, loadExperimental);
final List<Analyzer> iterator = service.getAnalyzers(mode.getPhases()); final List<Analyzer> iterator = service.getAnalyzers(mode.getPhases());
for (Analyzer a : iterator) { for (Analyzer a : iterator) {
a.initializeSettings(this.settings); a.initialize(this.settings);
analyzers.get(a.getAnalysisPhase()).add(a); analyzers.get(a.getAnalysisPhase()).add(a);
if (a instanceof FileTypeAnalyzer) { if (a instanceof FileTypeAnalyzer) {
this.fileTypeAnalyzers.add((FileTypeAnalyzer) a); this.fileTypeAnalyzers.add((FileTypeAnalyzer) a);
@@ -804,14 +804,14 @@ public class Engine implements FileFilter, AutoCloseable {
/** /**
* Initializes the given analyzer. * Initializes the given analyzer.
* *
* @param analyzer the analyzer to initialize * @param analyzer the analyzer to prepare
* @throws InitializationException thrown when there is a problem * @throws InitializationException thrown when there is a problem
* initializing the analyzer * initializing the analyzer
*/ */
protected void initializeAnalyzer(Analyzer analyzer) throws InitializationException { protected void initializeAnalyzer(Analyzer analyzer) throws InitializationException {
try { try {
LOGGER.debug("Initializing {}", analyzer.getName()); LOGGER.debug("Initializing {}", analyzer.getName());
analyzer.initialize(this); analyzer.prepare(this);
} catch (InitializationException ex) { } catch (InitializationException ex) {
LOGGER.error("Exception occurred initializing {}.", analyzer.getName()); LOGGER.error("Exception occurred initializing {}.", analyzer.getName());
LOGGER.debug("", ex); LOGGER.debug("", ex);

View File

@@ -28,7 +28,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* Base class for analyzers to avoid code duplication of initialize and close as * Base class for analyzers to avoid code duplication of prepare and close as
* most analyzers do not need these methods. * most analyzers do not need these methods.
* *
* @author Jeremy Long * @author Jeremy Long
@@ -83,48 +83,43 @@ public abstract class AbstractAnalyzer implements Analyzer {
* @param settings the configured settings to use * @param settings the configured settings to use
*/ */
@Override @Override
public void initializeSettings(Settings settings) { public void initialize(Settings settings) {
this.settings = settings; this.settings = settings;
} }
/** /**
* <p> * Initialize the abstract analyzer.
* Returns the setting key to determine if the analyzer is enabled.</p>
* *
* @return the key for the analyzer's enabled property * @param engine a reference to the dependency-check engine
* @throws InitializationException thrown if there is an exception
*/ */
protected abstract String getAnalyzerEnabledSettingKey(); @Override
public final void prepare(Engine engine) throws InitializationException {
final String key = getAnalyzerEnabledSettingKey();
try {
this.setEnabled(settings.getBoolean(key, true));
} catch (InvalidSettingException ex) {
final String msg = String.format("Invalid setting for property '%s'", key);
LOGGER.warn(msg);
LOGGER.debug(msg, ex);
}
if (isEnabled()) {
prepareAnalyzer(engine);
} else {
LOGGER.debug("{} has been disabled", getName());
}
}
/** /**
* Analyzes a given dependency. If the dependency is an archive, such as a * Prepares a given Analyzer. This will be skipped if the analyzer is
* WAR or EAR, the contents are extracted, scanned, and added to the list of
* dependencies within the engine.
*
* @param dependency the dependency to analyze
* @param engine the engine scanning
* @throws AnalysisException thrown if there is an analysis exception
*/
protected abstract void analyzeDependency(Dependency dependency, Engine engine) throws AnalysisException;
/**
* Initializes a given Analyzer. This will be skipped if the analyzer is
* disabled. * disabled.
* *
* @param engine a reference to the dependency-check engine * @param engine a reference to the dependency-check engine
* @throws InitializationException thrown if there is an exception * @throws InitializationException thrown if there is an exception
*/ */
protected void initializeAnalyzer(Engine engine) throws InitializationException { protected void prepareAnalyzer(Engine engine) throws InitializationException {
// Intentionally empty, analyzer will override this if they must initialize anything. // Intentionally empty, analyzer will override this if they must prepare anything.
}
/**
* Closes a given Analyzer. This will be skipped if the analyzer is
* disabled.
*
* @throws Exception thrown if there is an exception
*/
protected void closeAnalyzer() throws Exception {
// Intentionally empty, analyzer will override this if they must close a resource.
} }
/** /**
@@ -144,28 +139,15 @@ public abstract class AbstractAnalyzer implements Analyzer {
} }
/** /**
* Initialize the abstract analyzer. * Analyzes a given dependency. If the dependency is an archive, such as a
* WAR or EAR, the contents are extracted, scanned, and added to the list of
* dependencies within the engine.
* *
* @param engine a reference to the dependency-check engine * @param dependency the dependency to analyze
* @throws InitializationException thrown if there is an exception * @param engine the engine scanning
* @throws AnalysisException thrown if there is an analysis exception
*/ */
@Override protected abstract void analyzeDependency(Dependency dependency, Engine engine) throws AnalysisException;
public final void initialize(Engine engine) throws InitializationException {
final String key = getAnalyzerEnabledSettingKey();
try {
this.setEnabled(settings.getBoolean(key, true));
} catch (InvalidSettingException ex) {
final String msg = String.format("Invalid setting for property '%s'", key);
LOGGER.warn(msg);
LOGGER.debug(msg, ex);
}
if (isEnabled()) {
initializeAnalyzer(engine);
} else {
LOGGER.debug("{} has been disabled", getName());
}
}
/** /**
* The close method does nothing for this Analyzer. * The close method does nothing for this Analyzer.
@@ -179,6 +161,16 @@ public abstract class AbstractAnalyzer implements Analyzer {
} }
} }
/**
* Closes a given Analyzer. This will be skipped if the analyzer is
* disabled.
*
* @throws Exception thrown if there is an exception
*/
protected void closeAnalyzer() throws Exception {
// Intentionally empty, analyzer will override this if they must close a resource.
}
/** /**
* The default is to support parallel processing. * The default is to support parallel processing.
* *
@@ -186,8 +178,15 @@ public abstract class AbstractAnalyzer implements Analyzer {
*/ */
@Override @Override
public boolean supportsParallelProcessing() { public boolean supportsParallelProcessing() {
//temporarily removing parallel processing from all analyzders until further examination of thread safety occurs.
return true; return true;
//return false;
} }
/**
* <p>
* Returns the setting key to determine if the analyzer is enabled.</p>
*
* @return the key for the analyzer's enabled property
*/
protected abstract String getAnalyzerEnabledSettingKey();
} }

View File

@@ -48,7 +48,6 @@ public abstract class AbstractFileTypeAnalyzer extends AbstractAnalyzer implemen
*/ */
private boolean filesMatched = false; private boolean filesMatched = false;
/** /**
* Set the value of filesMatched. A flag indicating whether the scan * Set the value of filesMatched. A flag indicating whether the scan
* included any file types this analyzer supports. * included any file types this analyzer supports.
@@ -69,9 +68,9 @@ public abstract class AbstractFileTypeAnalyzer extends AbstractAnalyzer implemen
* initialization * initialization
*/ */
@Override @Override
protected final void initializeAnalyzer(Engine engine) throws InitializationException { protected final void prepareAnalyzer(Engine engine) throws InitializationException {
if (filesMatched) { if (filesMatched) {
initializeFileTypeAnalyzer(engine); prepareFileTypeAnalyzer(engine);
} else { } else {
this.setEnabled(false); this.setEnabled(false);
} }
@@ -94,13 +93,13 @@ public abstract class AbstractFileTypeAnalyzer extends AbstractAnalyzer implemen
protected abstract FileFilter getFileFilter(); protected abstract FileFilter getFileFilter();
/** /**
* Initializes the file type analyzer. * Prepares the file type analyzer for dependency analysis.
* *
* @param engine a reference to the dependency-check engine * @param engine a reference to the dependency-check engine
* @throws InitializationException thrown if there is an exception during * @throws InitializationException thrown if there is an exception during
* initialization * initialization
*/ */
protected abstract void initializeFileTypeAnalyzer(Engine engine) throws InitializationException; protected abstract void prepareFileTypeAnalyzer(Engine engine) throws InitializationException;
//</editor-fold> //</editor-fold>
/** /**
@@ -131,7 +130,7 @@ public abstract class AbstractFileTypeAnalyzer extends AbstractAnalyzer implemen
* constructs a new Set that can be used in a final static declaration.</p> * constructs a new Set that can be used in a final static declaration.</p>
* <p> * <p>
* This implementation was copied from * This implementation was copied from
* http://stackoverflow.com/questions/2041778/initialize-java-hashset-values-by-construction</p> * http://stackoverflow.com/questions/2041778/prepare-java-hashset-values-by-construction</p>
* *
* @param strings a list of strings to add to the set. * @param strings a list of strings to add to the set.
* @return a Set of strings. * @return a Set of strings.

View File

@@ -79,13 +79,13 @@ public abstract class AbstractSuppressionAnalyzer extends AbstractAnalyzer {
} }
/** /**
* The initialize method loads the suppression XML file. * The prepare method loads the suppression XML file.
* *
* @param engine a reference the dependency-check engine * @param engine a reference the dependency-check engine
* @throws InitializationException thrown if there is an exception * @throws InitializationException thrown if there is an exception
*/ */
@Override @Override
public synchronized void initializeAnalyzer(Engine engine) throws InitializationException { public synchronized void prepareAnalyzer(Engine engine) throws InitializationException {
if (rules == null) { if (rules == null) {
try { try {
rules = loadSuppressionData(); rules = loadSuppressionData();

View File

@@ -32,8 +32,8 @@ import org.owasp.dependencycheck.utils.Settings;
* When the {@link org.owasp.dependencycheck.Engine} executes it will load the * When the {@link org.owasp.dependencycheck.Engine} executes it will load the
* analyzers and call the methods in the following order:</p> * analyzers and call the methods in the following order:</p>
* <ol> * <ol>
* <li>{@link #initializeSettings(org.owasp.dependencycheck.utils.Settings)}</li> * <li>{@link #initialize(org.owasp.dependencycheck.utils.Settings)}</li>
* <li>{@link #initialize(org.owasp.dependencycheck.Engine)}</li> * <li>{@link #prepare(org.owasp.dependencycheck.Engine)}</li>
* <li>{@link #analyze(org.owasp.dependencycheck.dependency.Dependency, org.owasp.dependencycheck.Engine)}</li> * <li>{@link #analyze(org.owasp.dependencycheck.dependency.Dependency, org.owasp.dependencycheck.Engine)}</li>
* <li>{@link #close()}</li> * <li>{@link #close()}</li>
* </ol> * </ol>
@@ -75,17 +75,17 @@ public interface Analyzer {
* *
* @param settings the configured settings * @param settings the configured settings
*/ */
void initializeSettings(Settings settings); void initialize(Settings settings);
/** /**
* The initialize method is called (once) prior to the analyze method being * The prepare method is called (once) prior to the analyze method being
* called on all of the dependencies. * called on all of the dependencies.
* *
* @param engine a reference to the dependency-check engine * @param engine a reference to the dependency-check engine
* @throws InitializationException is thrown if an exception occurs * @throws InitializationException is thrown if an exception occurs
* initializing the analyzer. * initializing the analyzer.
*/ */
void initialize(Engine engine) throws InitializationException; void prepare(Engine engine) throws InitializationException;
/** /**
* The close method is called after all of the dependencies have been * The close method is called after all of the dependencies have been

View File

@@ -126,8 +126,8 @@ public class ArchiveAnalyzer extends AbstractFileTypeAnalyzer {
* @param settings the configured settings to use * @param settings the configured settings to use
*/ */
@Override @Override
public void initializeSettings(Settings settings) { public void initialize(Settings settings) {
super.initializeSettings(settings); super.initialize(settings);
initializeSettings(); initializeSettings();
} }
@@ -169,14 +169,14 @@ public class ArchiveAnalyzer extends AbstractFileTypeAnalyzer {
} }
/** /**
* The initialize method does nothing for this Analyzer. * The prepare method does nothing for this Analyzer.
* *
* @param engine a reference to the dependency-check engine * @param engine a reference to the dependency-check engine
* @throws InitializationException is thrown if there is an exception * @throws InitializationException is thrown if there is an exception
* deleting or creating temporary files * deleting or creating temporary files
*/ */
@Override @Override
public void initializeFileTypeAnalyzer(Engine engine) throws InitializationException { public void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
try { try {
final File baseDir = getSettings().getTempDirectory(); final File baseDir = getSettings().getTempDirectory();
tempFileLocation = File.createTempFile("check", "tmp", baseDir); tempFileLocation = File.createTempFile("check", "tmp", baseDir);

View File

@@ -205,7 +205,7 @@ public class AssemblyAnalyzer extends AbstractFileTypeAnalyzer {
* @throws InitializationException thrown if anything goes wrong * @throws InitializationException thrown if anything goes wrong
*/ */
@Override @Override
public void initializeFileTypeAnalyzer(Engine engine) throws InitializationException { public void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
final File tempFile; final File tempFile;
final File cfgFile; final File cfgFile;
try { try {

View File

@@ -260,7 +260,7 @@ public class AutoconfAnalyzer extends AbstractFileTypeAnalyzer {
* initialization * initialization
*/ */
@Override @Override
protected void initializeFileTypeAnalyzer(Engine engine) throws InitializationException { protected void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
// No initialization needed. // No initialization needed.
} }
} }

View File

@@ -131,7 +131,7 @@ public class CMakeAnalyzer extends AbstractFileTypeAnalyzer {
* instance of SHA1 * instance of SHA1
*/ */
@Override @Override
protected void initializeFileTypeAnalyzer(Engine engine) throws InitializationException { protected void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
try { try {
getSha1MessageDigest(); getSha1MessageDigest();
} catch (IllegalStateException ex) { } catch (IllegalStateException ex) {

View File

@@ -135,7 +135,7 @@ public class CPEAnalyzer extends AbstractAnalyzer {
* the index. * the index.
*/ */
@Override @Override
public void initializeAnalyzer(Engine engine) throws InitializationException { public void prepareAnalyzer(Engine engine) throws InitializationException {
try { try {
this.open(engine.getDatabase()); this.open(engine.getDatabase());
} catch (IOException ex) { } catch (IOException ex) {

View File

@@ -95,8 +95,8 @@ public class CentralAnalyzer extends AbstractFileTypeAnalyzer {
* @param settings the configured settings to use * @param settings the configured settings to use
*/ */
@Override @Override
public void initializeSettings(Settings settings) { public void initialize(Settings settings) {
super.initializeSettings(settings); super.initialize(settings);
enabled = checkEnabled(); enabled = checkEnabled();
} }
@@ -144,7 +144,7 @@ public class CentralAnalyzer extends AbstractFileTypeAnalyzer {
* @throws InitializationException if there's an error during initialization * @throws InitializationException if there's an error during initialization
*/ */
@Override @Override
public void initializeFileTypeAnalyzer(Engine engine) throws InitializationException { public void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
LOGGER.debug("Initializing Central analyzer"); LOGGER.debug("Initializing Central analyzer");
LOGGER.debug("Central analyzer enabled: {}", isEnabled()); LOGGER.debug("Central analyzer enabled: {}", isEnabled());
if (isEnabled()) { if (isEnabled()) {

View File

@@ -85,7 +85,7 @@ public class CocoaPodsAnalyzer extends AbstractFileTypeAnalyzer {
} }
@Override @Override
protected void initializeFileTypeAnalyzer(Engine engine) { protected void prepareFileTypeAnalyzer(Engine engine) {
// NO-OP // NO-OP
} }

View File

@@ -85,7 +85,7 @@ public class ComposerLockAnalyzer extends AbstractFileTypeAnalyzer {
* instance of SHA1 * instance of SHA1
*/ */
@Override @Override
protected void initializeFileTypeAnalyzer(Engine engine) throws InitializationException { protected void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
try { try {
getSha1MessageDigest(); getSha1MessageDigest();
} catch (IllegalStateException ex) { } catch (IllegalStateException ex) {

View File

@@ -112,13 +112,13 @@ public class HintAnalyzer extends AbstractAnalyzer {
} }
/** /**
* The initialize method does nothing for this Analyzer. * The prepare method does nothing for this Analyzer.
* *
* @param engine a reference the dependency-check engine * @param engine a reference the dependency-check engine
* @throws InitializationException thrown if there is an exception * @throws InitializationException thrown if there is an exception
*/ */
@Override @Override
public void initializeAnalyzer(Engine engine) throws InitializationException { public void prepareAnalyzer(Engine engine) throws InitializationException {
try { try {
loadHintRules(); loadHintRules();
} catch (HintParseException ex) { } catch (HintParseException ex) {

View File

@@ -920,7 +920,7 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer {
* creating a temporary directory * creating a temporary directory
*/ */
@Override @Override
public void initializeFileTypeAnalyzer(Engine engine) throws InitializationException { public void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
try { try {
final File baseDir = getSettings().getTempDirectory(); final File baseDir = getSettings().getTempDirectory();
tempFileLocation = File.createTempFile("check", "tmp", baseDir); tempFileLocation = File.createTempFile("check", "tmp", baseDir);

View File

@@ -106,8 +106,8 @@ public class NexusAnalyzer extends AbstractFileTypeAnalyzer {
* @param settings the configured settings to use * @param settings the configured settings to use
*/ */
@Override @Override
public void initializeSettings(Settings settings) { public void initialize(Settings settings) {
super.initializeSettings(settings); super.initialize(settings);
enabled = checkEnabled(); enabled = checkEnabled();
} }
@@ -155,7 +155,7 @@ public class NexusAnalyzer extends AbstractFileTypeAnalyzer {
* @throws InitializationException if there's an error during initialization * @throws InitializationException if there's an error during initialization
*/ */
@Override @Override
public void initializeFileTypeAnalyzer(Engine engine) throws InitializationException { public void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
LOGGER.debug("Initializing Nexus Analyzer"); LOGGER.debug("Initializing Nexus Analyzer");
LOGGER.debug("Nexus Analyzer enabled: {}", isEnabled()); LOGGER.debug("Nexus Analyzer enabled: {}", isEnabled());
if (isEnabled()) { if (isEnabled()) {

View File

@@ -87,7 +87,7 @@ public class NodePackageAnalyzer extends AbstractFileTypeAnalyzer {
} }
@Override @Override
protected void initializeFileTypeAnalyzer(Engine engine) throws InitializationException { protected void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
// NO-OP // NO-OP
} }

View File

@@ -105,7 +105,7 @@ public class NspAnalyzer extends AbstractFileTypeAnalyzer {
* @throws InitializationException if there's an error during initialization * @throws InitializationException if there's an error during initialization
*/ */
@Override @Override
public void initializeFileTypeAnalyzer(Engine engine) throws InitializationException { public void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
LOGGER.debug("Initializing {}", getName()); LOGGER.debug("Initializing {}", getName());
try { try {
searcher = new NspSearch(getSettings()); searcher = new NspSearch(getSettings());

View File

@@ -76,7 +76,7 @@ public class NuspecAnalyzer extends AbstractFileTypeAnalyzer {
* @throws InitializationException if there's an error during initialization * @throws InitializationException if there's an error during initialization
*/ */
@Override @Override
public void initializeFileTypeAnalyzer(Engine engine) throws InitializationException { public void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
//nothing to initialize //nothing to initialize
} }

View File

@@ -163,7 +163,7 @@ public class OpenSSLAnalyzer extends AbstractFileTypeAnalyzer {
* @throws InitializationException never thrown * @throws InitializationException never thrown
*/ */
@Override @Override
protected void initializeFileTypeAnalyzer(Engine engine) throws InitializationException { protected void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
// Nothing to do here. // Nothing to do here.
} }

View File

@@ -230,7 +230,7 @@ public class PythonDistributionAnalyzer extends AbstractFileTypeAnalyzer {
* temp directory cannot be created * temp directory cannot be created
*/ */
@Override @Override
protected void initializeFileTypeAnalyzer(Engine engine) throws InitializationException { protected void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
try { try {
final File baseDir = getSettings().getTempDirectory(); final File baseDir = getSettings().getTempDirectory();
tempFileLocation = File.createTempFile("check", "tmp", baseDir); tempFileLocation = File.createTempFile("check", "tmp", baseDir);

View File

@@ -156,7 +156,7 @@ public class PythonPackageAnalyzer extends AbstractFileTypeAnalyzer {
* @throws InitializationException never thrown * @throws InitializationException never thrown
*/ */
@Override @Override
protected void initializeFileTypeAnalyzer(Engine engine) throws InitializationException { protected void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
// Nothing to do here. // Nothing to do here.
} }

View File

@@ -147,7 +147,7 @@ public class RubyBundleAuditAnalyzer extends AbstractFileTypeAnalyzer {
* @throws InitializationException if anything goes wrong * @throws InitializationException if anything goes wrong
*/ */
@Override @Override
public void initializeFileTypeAnalyzer(Engine engine) throws InitializationException { public void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
// Now, need to see if bundle-audit actually runs from this location. // Now, need to see if bundle-audit actually runs from this location.
if (engine != null) { if (engine != null) {
this.cvedb = engine.getDatabase(); this.cvedb = engine.getDatabase();

View File

@@ -91,7 +91,7 @@ public class RubyGemspecAnalyzer extends AbstractFileTypeAnalyzer {
} }
@Override @Override
protected void initializeFileTypeAnalyzer(Engine engine) throws InitializationException { protected void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
// NO-OP // NO-OP
} }

View File

@@ -82,7 +82,7 @@ public class SwiftPackageManagerAnalyzer extends AbstractFileTypeAnalyzer {
} }
@Override @Override
protected void initializeFileTypeAnalyzer(Engine engine) { protected void prepareFileTypeAnalyzer(Engine engine) {
// NO-OP // NO-OP
} }

View File

@@ -104,8 +104,8 @@ public class AbstractSuppressionAnalyzerTest extends BaseTest {
// WHEN initializing with both suppression files // WHEN initializing with both suppression files
final String[] suppressionFiles = {SUPPRESSIONS_FILE, OTHER_SUPPRESSIONS_FILE}; final String[] suppressionFiles = {SUPPRESSIONS_FILE, OTHER_SUPPRESSIONS_FILE};
getSettings().setArrayIfNotEmpty(KEYS.SUPPRESSION_FILE, suppressionFiles); getSettings().setArrayIfNotEmpty(KEYS.SUPPRESSION_FILE, suppressionFiles);
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
instance.initialize(null); instance.prepare(null);
// THEN rules from both files were loaded // THEN rules from both files were loaded
final int expectedSize = rulesInFirstFile + rulesInSecondFile + rulesInCoreFile; final int expectedSize = rulesInFirstFile + rulesInSecondFile + rulesInCoreFile;
@@ -115,8 +115,8 @@ public class AbstractSuppressionAnalyzerTest extends BaseTest {
@Test(expected = InitializationException.class) @Test(expected = InitializationException.class)
public void testFailureToLocateSuppressionFileAnywhere() throws Exception { public void testFailureToLocateSuppressionFileAnywhere() throws Exception {
getSettings().setString(Settings.KEYS.SUPPRESSION_FILE, "doesnotexist.xml"); getSettings().setString(Settings.KEYS.SUPPRESSION_FILE, "doesnotexist.xml");
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
instance.initialize(null); instance.prepare(null);
} }
/** /**
@@ -129,8 +129,8 @@ public class AbstractSuppressionAnalyzerTest extends BaseTest {
private int getNumberOfRulesLoadedInCoreFile() throws Exception { private int getNumberOfRulesLoadedInCoreFile() throws Exception {
getSettings().removeProperty(KEYS.SUPPRESSION_FILE); getSettings().removeProperty(KEYS.SUPPRESSION_FILE);
final AbstractSuppressionAnalyzerImpl coreFileAnalyzer = new AbstractSuppressionAnalyzerImpl(); final AbstractSuppressionAnalyzerImpl coreFileAnalyzer = new AbstractSuppressionAnalyzerImpl();
coreFileAnalyzer.initializeSettings(getSettings()); coreFileAnalyzer.initialize(getSettings());
coreFileAnalyzer.initialize(null); coreFileAnalyzer.prepare(null);
return coreFileAnalyzer.getRuleCount(); return coreFileAnalyzer.getRuleCount();
} }
@@ -145,8 +145,8 @@ public class AbstractSuppressionAnalyzerTest extends BaseTest {
private int getNumberOfRulesLoadedFromPath(final String path) throws Exception { private int getNumberOfRulesLoadedFromPath(final String path) throws Exception {
getSettings().setString(KEYS.SUPPRESSION_FILE, path); getSettings().setString(KEYS.SUPPRESSION_FILE, path);
final AbstractSuppressionAnalyzerImpl fileAnalyzer = new AbstractSuppressionAnalyzerImpl(); final AbstractSuppressionAnalyzerImpl fileAnalyzer = new AbstractSuppressionAnalyzerImpl();
fileAnalyzer.initializeSettings(getSettings()); fileAnalyzer.initialize(getSettings());
fileAnalyzer.initialize(null); fileAnalyzer.prepare(null);
return fileAnalyzer.getRuleCount(); return fileAnalyzer.getRuleCount();
} }

View File

@@ -41,7 +41,7 @@ public class ArchiveAnalyzerIT extends BaseDBTestCase {
@Test @Test
public void testSupportsExtensions() { public void testSupportsExtensions() {
ArchiveAnalyzer instance = new ArchiveAnalyzer(); ArchiveAnalyzer instance = new ArchiveAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
Set<String> expResult = new HashSet<>(); Set<String> expResult = new HashSet<>();
expResult.add("zip"); expResult.add("zip");
expResult.add("war"); expResult.add("war");
@@ -66,7 +66,7 @@ public class ArchiveAnalyzerIT extends BaseDBTestCase {
@Test @Test
public void testGetName() { public void testGetName() {
ArchiveAnalyzer instance = new ArchiveAnalyzer(); ArchiveAnalyzer instance = new ArchiveAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
String expResult = "Archive Analyzer"; String expResult = "Archive Analyzer";
String result = instance.getName(); String result = instance.getName();
assertEquals(expResult, result); assertEquals(expResult, result);
@@ -79,7 +79,7 @@ public class ArchiveAnalyzerIT extends BaseDBTestCase {
public void testSupportsExtension() { public void testSupportsExtension() {
String extension = "test.7z"; //not supported String extension = "test.7z"; //not supported
ArchiveAnalyzer instance = new ArchiveAnalyzer(); ArchiveAnalyzer instance = new ArchiveAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
assertFalse(extension, instance.accept(new File(extension))); assertFalse(extension, instance.accept(new File(extension)));
} }
@@ -89,23 +89,23 @@ public class ArchiveAnalyzerIT extends BaseDBTestCase {
@Test @Test
public void testGetAnalysisPhase() { public void testGetAnalysisPhase() {
ArchiveAnalyzer instance = new ArchiveAnalyzer(); ArchiveAnalyzer instance = new ArchiveAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
AnalysisPhase expResult = AnalysisPhase.INITIAL; AnalysisPhase expResult = AnalysisPhase.INITIAL;
AnalysisPhase result = instance.getAnalysisPhase(); AnalysisPhase result = instance.getAnalysisPhase();
assertEquals(expResult, result); assertEquals(expResult, result);
} }
/** /**
* Test of initialize and close methods, of class ArchiveAnalyzer. * Test of prepare and close methods, of class ArchiveAnalyzer.
*/ */
@Test @Test
public void testInitialize() { public void testInitialize() {
ArchiveAnalyzer instance = new ArchiveAnalyzer(); ArchiveAnalyzer instance = new ArchiveAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
try { try {
instance.setEnabled(true); instance.setEnabled(true);
instance.setFilesMatched(true); instance.setFilesMatched(true);
instance.initialize(null); instance.prepare(null);
} catch (InitializationException ex) { } catch (InitializationException ex) {
fail(ex.getMessage()); fail(ex.getMessage());
} finally { } finally {
@@ -125,7 +125,7 @@ public class ArchiveAnalyzerIT extends BaseDBTestCase {
@Test @Test
public void testAnalyze() throws Exception { public void testAnalyze() throws Exception {
ArchiveAnalyzer instance = new ArchiveAnalyzer(); ArchiveAnalyzer instance = new ArchiveAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
//trick the analyzer into thinking it is active. //trick the analyzer into thinking it is active.
instance.accept(new File("test.ear")); instance.accept(new File("test.ear"));
try { try {
@@ -134,7 +134,7 @@ public class ArchiveAnalyzerIT extends BaseDBTestCase {
getSettings().setBoolean(Settings.KEYS.ANALYZER_CENTRAL_ENABLED, false); getSettings().setBoolean(Settings.KEYS.ANALYZER_CENTRAL_ENABLED, false);
Engine engine = new Engine(getSettings()); Engine engine = new Engine(getSettings());
instance.initialize(engine); instance.prepare(engine);
File file = BaseTest.getResourceAsFile(this, "daytrader-ear-2.1.7.ear"); File file = BaseTest.getResourceAsFile(this, "daytrader-ear-2.1.7.ear");
Dependency dependency = new Dependency(file); Dependency dependency = new Dependency(file);
@@ -157,11 +157,11 @@ public class ArchiveAnalyzerIT extends BaseDBTestCase {
@Test @Test
public void testAnalyzeExecutableJar() throws Exception { public void testAnalyzeExecutableJar() throws Exception {
ArchiveAnalyzer instance = new ArchiveAnalyzer(); ArchiveAnalyzer instance = new ArchiveAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
//trick the analyzer into thinking it is active. //trick the analyzer into thinking it is active.
instance.accept(new File("test.ear")); instance.accept(new File("test.ear"));
try { try {
instance.initialize(null); instance.prepare(null);
File file = BaseTest.getResourceAsFile(this, "bootable-0.1.0.jar"); File file = BaseTest.getResourceAsFile(this, "bootable-0.1.0.jar");
Dependency dependency = new Dependency(file); Dependency dependency = new Dependency(file);
getSettings().setBoolean(Settings.KEYS.AUTO_UPDATE, false); getSettings().setBoolean(Settings.KEYS.AUTO_UPDATE, false);
@@ -188,11 +188,11 @@ public class ArchiveAnalyzerIT extends BaseDBTestCase {
@Test @Test
public void testAnalyzeTar() throws Exception { public void testAnalyzeTar() throws Exception {
ArchiveAnalyzer instance = new ArchiveAnalyzer(); ArchiveAnalyzer instance = new ArchiveAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
//trick the analyzer into thinking it is active so that it will initialize //trick the analyzer into thinking it is active so that it will prepare
instance.accept(new File("test.tar")); instance.accept(new File("test.tar"));
try { try {
instance.initialize(null); instance.prepare(null);
//File file = new File(this.getClass().getClassLoader().getResource("file.tar").getPath()); //File file = new File(this.getClass().getClassLoader().getResource("file.tar").getPath());
//File file = new File(this.getClass().getClassLoader().getResource("stagedhttp-modified.tar").getPath()); //File file = new File(this.getClass().getClassLoader().getResource("stagedhttp-modified.tar").getPath());
@@ -221,10 +221,10 @@ public class ArchiveAnalyzerIT extends BaseDBTestCase {
@Test @Test
public void testAnalyzeTarGz() throws Exception { public void testAnalyzeTarGz() throws Exception {
ArchiveAnalyzer instance = new ArchiveAnalyzer(); ArchiveAnalyzer instance = new ArchiveAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
instance.accept(new File("zip")); //ensure analyzer is "enabled" instance.accept(new File("zip")); //ensure analyzer is "enabled"
try { try {
instance.initialize(null); instance.prepare(null);
//File file = new File(this.getClass().getClassLoader().getResource("file.tar.gz").getPath()); //File file = new File(this.getClass().getClassLoader().getResource("file.tar.gz").getPath());
File file = BaseTest.getResourceAsFile(this, "file.tar.gz"); File file = BaseTest.getResourceAsFile(this, "file.tar.gz");
@@ -253,10 +253,10 @@ public class ArchiveAnalyzerIT extends BaseDBTestCase {
@Test @Test
public void testAnalyzeTarBz2() throws Exception { public void testAnalyzeTarBz2() throws Exception {
ArchiveAnalyzer instance = new ArchiveAnalyzer(); ArchiveAnalyzer instance = new ArchiveAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
instance.accept(new File("zip")); //ensure analyzer is "enabled" instance.accept(new File("zip")); //ensure analyzer is "enabled"
try { try {
instance.initialize(null); instance.prepare(null);
File file = BaseTest.getResourceAsFile(this, "file.tar.bz2"); File file = BaseTest.getResourceAsFile(this, "file.tar.bz2");
getSettings().setBoolean(Settings.KEYS.AUTO_UPDATE, false); getSettings().setBoolean(Settings.KEYS.AUTO_UPDATE, false);
getSettings().setBoolean(Settings.KEYS.ANALYZER_NEXUS_ENABLED, false); getSettings().setBoolean(Settings.KEYS.ANALYZER_NEXUS_ENABLED, false);
@@ -279,10 +279,10 @@ public class ArchiveAnalyzerIT extends BaseDBTestCase {
@Test @Test
public void testAnalyzeTgz() throws Exception { public void testAnalyzeTgz() throws Exception {
ArchiveAnalyzer instance = new ArchiveAnalyzer(); ArchiveAnalyzer instance = new ArchiveAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
instance.accept(new File("zip")); //ensure analyzer is "enabled" instance.accept(new File("zip")); //ensure analyzer is "enabled"
try { try {
instance.initialize(null); instance.prepare(null);
//File file = new File(this.getClass().getClassLoader().getResource("file.tgz").getPath()); //File file = new File(this.getClass().getClassLoader().getResource("file.tgz").getPath());
File file = BaseTest.getResourceAsFile(this, "file.tgz"); File file = BaseTest.getResourceAsFile(this, "file.tgz");
@@ -309,10 +309,10 @@ public class ArchiveAnalyzerIT extends BaseDBTestCase {
@Test @Test
public void testAnalyzeTbz2() throws Exception { public void testAnalyzeTbz2() throws Exception {
ArchiveAnalyzer instance = new ArchiveAnalyzer(); ArchiveAnalyzer instance = new ArchiveAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
instance.accept(new File("zip")); //ensure analyzer is "enabled" instance.accept(new File("zip")); //ensure analyzer is "enabled"
try { try {
instance.initialize(null); instance.prepare(null);
File file = BaseTest.getResourceAsFile(this, "file.tbz2"); File file = BaseTest.getResourceAsFile(this, "file.tbz2");
getSettings().setBoolean(Settings.KEYS.AUTO_UPDATE, false); getSettings().setBoolean(Settings.KEYS.AUTO_UPDATE, false);
getSettings().setBoolean(Settings.KEYS.ANALYZER_NEXUS_ENABLED, false); getSettings().setBoolean(Settings.KEYS.ANALYZER_NEXUS_ENABLED, false);
@@ -335,9 +335,9 @@ public class ArchiveAnalyzerIT extends BaseDBTestCase {
@Test @Test
public void testAnalyze_badZip() throws Exception { public void testAnalyze_badZip() throws Exception {
ArchiveAnalyzer instance = new ArchiveAnalyzer(); ArchiveAnalyzer instance = new ArchiveAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
try { try {
instance.initialize(null); instance.prepare(null);
//File file = new File(this.getClass().getClassLoader().getResource("test.zip").getPath()); //File file = new File(this.getClass().getClassLoader().getResource("test.zip").getPath());
File file = BaseTest.getResourceAsFile(this, "test.zip"); File file = BaseTest.getResourceAsFile(this, "test.zip");

View File

@@ -49,7 +49,7 @@ public class ArchiveAnalyzerTest extends BaseTest {
public void testZippableExtensions() throws Exception { public void testZippableExtensions() throws Exception {
assumeFalse(isPreviouslyLoaded("org.owasp.dependencycheck.analyzer.ArchiveAnalyzer")); assumeFalse(isPreviouslyLoaded("org.owasp.dependencycheck.analyzer.ArchiveAnalyzer"));
ArchiveAnalyzer instance = new ArchiveAnalyzer(); ArchiveAnalyzer instance = new ArchiveAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
assertTrue(instance.getFileFilter().accept(new File("c:/test.zip"))); assertTrue(instance.getFileFilter().accept(new File("c:/test.zip")));
assertTrue(instance.getFileFilter().accept(new File("c:/test.z2"))); assertTrue(instance.getFileFilter().accept(new File("c:/test.z2")));
assertTrue(instance.getFileFilter().accept(new File("c:/test.z3"))); assertTrue(instance.getFileFilter().accept(new File("c:/test.z3")));

View File

@@ -72,9 +72,9 @@ public class AssemblyAnalyzerTest extends BaseTest {
super.setUp(); super.setUp();
try { try {
analyzer = new AssemblyAnalyzer(); analyzer = new AssemblyAnalyzer();
analyzer.initializeSettings(getSettings()); analyzer.initialize(getSettings());
analyzer.accept(new File("test.dll")); // trick into "thinking it is active" analyzer.accept(new File("test.dll")); // trick into "thinking it is active"
analyzer.initialize(null); analyzer.prepare(null);
assertGrokAssembly(); assertGrokAssembly();
} catch (Exception e) { } catch (Exception e) {
if (e.getMessage().contains("Could not execute .NET AssemblyAnalyzer")) { if (e.getMessage().contains("Could not execute .NET AssemblyAnalyzer")) {
@@ -190,9 +190,9 @@ public class AssemblyAnalyzerTest extends BaseTest {
System.setProperty(LOG_KEY, "error"); System.setProperty(LOG_KEY, "error");
// Have to make a NEW analyzer because during setUp, it would have gotten the correct one // Have to make a NEW analyzer because during setUp, it would have gotten the correct one
AssemblyAnalyzer aanalyzer = new AssemblyAnalyzer(); AssemblyAnalyzer aanalyzer = new AssemblyAnalyzer();
aanalyzer.initializeSettings(getSettings()); aanalyzer.initialize(getSettings());
aanalyzer.accept(new File("test.dll")); // trick into "thinking it is active" aanalyzer.accept(new File("test.dll")); // trick into "thinking it is active"
aanalyzer.initialize(null); aanalyzer.prepare(null);
fail("Expected an InitializationException"); fail("Expected an InitializationException");
} catch (InitializationException ae) { } catch (InitializationException ae) {
assertEquals("An error occurred with the .NET AssemblyAnalyzer", ae.getMessage()); assertEquals("An error occurred with the .NET AssemblyAnalyzer", ae.getMessage());

View File

@@ -60,9 +60,9 @@ public class AutoconfAnalyzerTest extends BaseTest {
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
analyzer = new AutoconfAnalyzer(); analyzer = new AutoconfAnalyzer();
analyzer.initializeSettings(getSettings()); analyzer.initialize(getSettings());
analyzer.setFilesMatched(true); analyzer.setFilesMatched(true);
analyzer.initialize(null); analyzer.prepare(null);
} }
/** /**

View File

@@ -67,9 +67,9 @@ public class CMakeAnalyzerTest extends BaseDBTestCase {
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
analyzer = new CMakeAnalyzer(); analyzer = new CMakeAnalyzer();
analyzer.initializeSettings(getSettings()); analyzer.initialize(getSettings());
analyzer.setFilesMatched(true); analyzer.setFilesMatched(true);
analyzer.initialize(null); analyzer.prepare(null);
} }
/** /**
@@ -192,8 +192,8 @@ public class CMakeAnalyzerTest extends BaseDBTestCase {
analyzer = new CMakeAnalyzer(); analyzer = new CMakeAnalyzer();
analyzer.setFilesMatched(true); analyzer.setFilesMatched(true);
assertTrue(analyzer.isEnabled()); assertTrue(analyzer.isEnabled());
analyzer.initializeSettings(getSettings()); analyzer.initialize(getSettings());
analyzer.initialize(null); analyzer.prepare(null);
assertFalse(analyzer.isEnabled()); assertFalse(analyzer.isEnabled());
} }

View File

@@ -59,7 +59,7 @@ public class CPEAnalyzerIT extends BaseDBTestCase {
String product = "struts 2 core"; String product = "struts 2 core";
CPEAnalyzer instance = new CPEAnalyzer(); CPEAnalyzer instance = new CPEAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
String queryText = instance.buildSearch(vendor, product, null, null); String queryText = instance.buildSearch(vendor, product, null, null);
String expResult = " product:( struts 2 core ) AND vendor:( apache software foundation ) "; String expResult = " product:( struts 2 core ) AND vendor:( apache software foundation ) ";
assertTrue(expResult.equals(queryText)); assertTrue(expResult.equals(queryText));
@@ -90,21 +90,21 @@ public class CPEAnalyzerIT extends BaseDBTestCase {
CPEAnalyzer cpeAnalyzer = new CPEAnalyzer(); CPEAnalyzer cpeAnalyzer = new CPEAnalyzer();
try { try {
cpeAnalyzer.initializeSettings(getSettings()); cpeAnalyzer.initialize(getSettings());
cpeAnalyzer.initialize(e); cpeAnalyzer.prepare(e);
FileNameAnalyzer fnAnalyzer = new FileNameAnalyzer(); FileNameAnalyzer fnAnalyzer = new FileNameAnalyzer();
fnAnalyzer.initializeSettings(getSettings()); fnAnalyzer.initialize(getSettings());
fnAnalyzer.initialize(e); fnAnalyzer.prepare(e);
JarAnalyzer jarAnalyzer = new JarAnalyzer(); JarAnalyzer jarAnalyzer = new JarAnalyzer();
jarAnalyzer.initializeSettings(getSettings()); jarAnalyzer.initialize(getSettings());
jarAnalyzer.accept(new File("test.jar"));//trick analyzer into "thinking it is active" jarAnalyzer.accept(new File("test.jar"));//trick analyzer into "thinking it is active"
jarAnalyzer.initialize(e); jarAnalyzer.prepare(e);
HintAnalyzer hAnalyzer = new HintAnalyzer(); HintAnalyzer hAnalyzer = new HintAnalyzer();
hAnalyzer.initializeSettings(getSettings()); hAnalyzer.initialize(getSettings());
hAnalyzer.initialize(e); hAnalyzer.prepare(e);
FalsePositiveAnalyzer fp = new FalsePositiveAnalyzer(); FalsePositiveAnalyzer fp = new FalsePositiveAnalyzer();
fp.initializeSettings(getSettings()); fp.initialize(getSettings());
fp.initialize(e); fp.prepare(e);
callDetermineCPE_full("hazelcast-2.5.jar", null, cpeAnalyzer, fnAnalyzer, jarAnalyzer, hAnalyzer, fp); callDetermineCPE_full("hazelcast-2.5.jar", null, cpeAnalyzer, fnAnalyzer, jarAnalyzer, hAnalyzer, fp);
callDetermineCPE_full("spring-context-support-2.5.5.jar", "cpe:/a:springsource:spring_framework:2.5.5", cpeAnalyzer, fnAnalyzer, jarAnalyzer, hAnalyzer, fp); callDetermineCPE_full("spring-context-support-2.5.5.jar", "cpe:/a:springsource:spring_framework:2.5.5", cpeAnalyzer, fnAnalyzer, jarAnalyzer, hAnalyzer, fp);
@@ -169,12 +169,12 @@ public class CPEAnalyzerIT extends BaseDBTestCase {
fnAnalyzer.analyze(struts, null); fnAnalyzer.analyze(struts, null);
HintAnalyzer hintAnalyzer = new HintAnalyzer(); HintAnalyzer hintAnalyzer = new HintAnalyzer();
hintAnalyzer.initializeSettings(getSettings()); hintAnalyzer.initialize(getSettings());
hintAnalyzer.initialize(null); hintAnalyzer.prepare(null);
JarAnalyzer jarAnalyzer = new JarAnalyzer(); JarAnalyzer jarAnalyzer = new JarAnalyzer();
jarAnalyzer.initializeSettings(getSettings()); jarAnalyzer.initialize(getSettings());
jarAnalyzer.accept(new File("test.jar"));//trick analyzer into "thinking it is active" jarAnalyzer.accept(new File("test.jar"));//trick analyzer into "thinking it is active"
jarAnalyzer.initialize(null); jarAnalyzer.prepare(null);
jarAnalyzer.analyze(struts, null); jarAnalyzer.analyze(struts, null);
hintAnalyzer.analyze(struts, null); hintAnalyzer.analyze(struts, null);
@@ -199,8 +199,8 @@ public class CPEAnalyzerIT extends BaseDBTestCase {
CPEAnalyzer instance = new CPEAnalyzer(); CPEAnalyzer instance = new CPEAnalyzer();
Engine engine = new Engine(getSettings()); Engine engine = new Engine(getSettings());
engine.openDatabase(); engine.openDatabase();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
instance.initialize(engine); instance.prepare(engine);
instance.determineCPE(commonValidator); instance.determineCPE(commonValidator);
instance.determineCPE(struts); instance.determineCPE(struts);
instance.determineCPE(spring); instance.determineCPE(spring);
@@ -243,8 +243,8 @@ public class CPEAnalyzerIT extends BaseDBTestCase {
CPEAnalyzer instance = new CPEAnalyzer(); CPEAnalyzer instance = new CPEAnalyzer();
Engine engine = new Engine(getSettings()); Engine engine = new Engine(getSettings());
engine.openDatabase(); engine.openDatabase();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
instance.initialize(engine); instance.prepare(engine);
instance.determineIdentifiers(openssl, "openssl", "openssl", Confidence.HIGHEST); instance.determineIdentifiers(openssl, "openssl", "openssl", Confidence.HIGHEST);
instance.close(); instance.close();
engine.close(); engine.close();
@@ -277,8 +277,8 @@ public class CPEAnalyzerIT extends BaseDBTestCase {
CPEAnalyzer instance = new CPEAnalyzer(); CPEAnalyzer instance = new CPEAnalyzer();
Engine engine = new Engine(getSettings()); Engine engine = new Engine(getSettings());
engine.openDatabase(); engine.openDatabase();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
instance.initialize(engine); instance.prepare(engine);
Set<String> productWeightings = Collections.singleton("struts2"); Set<String> productWeightings = Collections.singleton("struts2");
Set<String> vendorWeightings = Collections.singleton("apache"); Set<String> vendorWeightings = Collections.singleton("apache");

View File

@@ -59,9 +59,9 @@ public class ComposerLockAnalyzerTest extends BaseDBTestCase {
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
analyzer = new ComposerLockAnalyzer(); analyzer = new ComposerLockAnalyzer();
analyzer.initializeSettings(getSettings()); analyzer.initialize(getSettings());
analyzer.setFilesMatched(true); analyzer.setFilesMatched(true);
analyzer.initialize(null); analyzer.prepare(null);
} }
/** /**
@@ -116,9 +116,9 @@ public class ComposerLockAnalyzerTest extends BaseDBTestCase {
analyzer = new ComposerLockAnalyzer(); analyzer = new ComposerLockAnalyzer();
analyzer.setFilesMatched(true); analyzer.setFilesMatched(true);
analyzer.initializeSettings(getSettings()); analyzer.initialize(getSettings());
assertTrue(analyzer.isEnabled()); assertTrue(analyzer.isEnabled());
analyzer.initialize(null); analyzer.prepare(null);
assertFalse(analyzer.isEnabled()); assertFalse(analyzer.isEnabled());
} }

View File

@@ -76,14 +76,14 @@ public class FileNameAnalyzerTest extends BaseTest {
} }
/** /**
* Test of initialize method, of class FileNameAnalyzer. * Test of prepare method, of class FileNameAnalyzer.
*/ */
@Test @Test
public void testInitialize() { public void testInitialize() {
FileNameAnalyzer instance = new FileNameAnalyzer(); FileNameAnalyzer instance = new FileNameAnalyzer();
try { try {
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
instance.initialize(null); instance.prepare(null);
} catch (InitializationException ex) { } catch (InitializationException ex) {
fail(ex.getMessage()); fail(ex.getMessage());
} }

View File

@@ -114,8 +114,8 @@ public class HintAnalyzerTest extends BaseDBTestCase {
File path = BaseTest.getResourceAsFile(this, "hints_12.xml"); File path = BaseTest.getResourceAsFile(this, "hints_12.xml");
getSettings().setString(Settings.KEYS.HINTS_FILE, path.getPath()); getSettings().setString(Settings.KEYS.HINTS_FILE, path.getPath());
HintAnalyzer instance = new HintAnalyzer(); HintAnalyzer instance = new HintAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
instance.initialize(null); instance.prepare(null);
Dependency d = new Dependency(); Dependency d = new Dependency();
d.addEvidence(EvidenceType.VERSION, "version source", "given version name", "1.2.3", Confidence.HIGH); d.addEvidence(EvidenceType.VERSION, "version source", "given version name", "1.2.3", Confidence.HIGH);
d.addEvidence(EvidenceType.VERSION, "hint analyzer", "remove version name", "value", Confidence.HIGH); d.addEvidence(EvidenceType.VERSION, "hint analyzer", "remove version name", "value", Confidence.HIGH);

View File

@@ -51,8 +51,8 @@ public class JarAnalyzerTest extends BaseTest {
File file = BaseTest.getResourceAsFile(this, "struts2-core-2.1.2.jar"); File file = BaseTest.getResourceAsFile(this, "struts2-core-2.1.2.jar");
Dependency result = new Dependency(file); Dependency result = new Dependency(file);
JarAnalyzer instance = new JarAnalyzer(); JarAnalyzer instance = new JarAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
instance.initializeFileTypeAnalyzer(null); instance.prepareFileTypeAnalyzer(null);
instance.analyze(result, null); instance.analyze(result, null);
assertTrue(result.getEvidence(EvidenceType.VENDOR).toString().toLowerCase().contains("apache")); assertTrue(result.getEvidence(EvidenceType.VENDOR).toString().toLowerCase().contains("apache"));
assertTrue(result.getVendorWeightings().contains("apache")); assertTrue(result.getVendorWeightings().contains("apache"));
@@ -117,8 +117,8 @@ public class JarAnalyzerTest extends BaseTest {
@Test @Test
public void testAcceptSupportedExtensions() throws Exception { public void testAcceptSupportedExtensions() throws Exception {
JarAnalyzer instance = new JarAnalyzer(); JarAnalyzer instance = new JarAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
instance.initialize(null); instance.prepare(null);
instance.setEnabled(true); instance.setEnabled(true);
String[] files = {"test.jar", "test.war"}; String[] files = {"test.jar", "test.war"};
for (String name : files) { for (String name : files) {

View File

@@ -54,8 +54,8 @@ public class NodePackageAnalyzerTest extends BaseTest {
super.setUp(); super.setUp();
analyzer = new NodePackageAnalyzer(); analyzer = new NodePackageAnalyzer();
analyzer.setFilesMatched(true); analyzer.setFilesMatched(true);
analyzer.initializeSettings(getSettings()); analyzer.initialize(getSettings());
analyzer.initialize(null); analyzer.prepare(null);
} }
/** /**

View File

@@ -23,8 +23,8 @@ public class NspAnalyzerTest extends BaseTest {
super.setUp(); super.setUp();
analyzer = new NspAnalyzer(); analyzer = new NspAnalyzer();
analyzer.setFilesMatched(true); analyzer.setFilesMatched(true);
analyzer.initializeSettings(getSettings()); analyzer.initialize(getSettings());
analyzer.initialize(null); analyzer.prepare(null);
} }
@After @After

View File

@@ -35,8 +35,8 @@ public class NuspecAnalyzerTest extends BaseTest {
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
instance = new NuspecAnalyzer(); instance = new NuspecAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
instance.initialize(null); instance.prepare(null);
instance.setEnabled(true); instance.setEnabled(true);
} }

View File

@@ -53,8 +53,8 @@ public class OpenSSLAnalyzerTest extends BaseTest {
super.setUp(); super.setUp();
analyzer = new OpenSSLAnalyzer(); analyzer = new OpenSSLAnalyzer();
analyzer.setFilesMatched(true); analyzer.setFilesMatched(true);
analyzer.initializeSettings(getSettings()); analyzer.initialize(getSettings());
analyzer.initialize(null); analyzer.prepare(null);
} }
/** /**

View File

@@ -55,8 +55,8 @@ public class PythonDistributionAnalyzerTest extends BaseTest {
super.setUp(); super.setUp();
analyzer = new PythonDistributionAnalyzer(); analyzer = new PythonDistributionAnalyzer();
analyzer.setFilesMatched(true); analyzer.setFilesMatched(true);
analyzer.initializeSettings(getSettings()); analyzer.initialize(getSettings());
analyzer.initialize(null); analyzer.prepare(null);
} }
/** /**

View File

@@ -54,8 +54,8 @@ public class PythonPackageAnalyzerTest extends BaseTest {
super.setUp(); super.setUp();
analyzer = new PythonPackageAnalyzer(); analyzer = new PythonPackageAnalyzer();
analyzer.setFilesMatched(true); analyzer.setFilesMatched(true);
analyzer.initializeSettings(getSettings()); analyzer.initialize(getSettings());
analyzer.initialize(null); analyzer.prepare(null);
} }
/** /**

View File

@@ -75,7 +75,7 @@ public class RubyBundleAuditAnalyzerIT extends BaseDBTestCase {
getSettings().setBoolean(Settings.KEYS.ANALYZER_NEXUS_ENABLED, false); getSettings().setBoolean(Settings.KEYS.ANALYZER_NEXUS_ENABLED, false);
getSettings().setBoolean(Settings.KEYS.ANALYZER_CENTRAL_ENABLED, false); getSettings().setBoolean(Settings.KEYS.ANALYZER_CENTRAL_ENABLED, false);
analyzer = new RubyBundleAuditAnalyzer(); analyzer = new RubyBundleAuditAnalyzer();
analyzer.initializeSettings(getSettings()); analyzer.initialize(getSettings());
analyzer.setFilesMatched(true); analyzer.setFilesMatched(true);
} }
@@ -119,7 +119,7 @@ public class RubyBundleAuditAnalyzerIT extends BaseDBTestCase {
public void testAnalysis() throws AnalysisException, DatabaseException { public void testAnalysis() throws AnalysisException, DatabaseException {
try (Engine engine = new Engine(getSettings())) { try (Engine engine = new Engine(getSettings())) {
engine.openDatabase(); engine.openDatabase();
analyzer.initialize(engine); analyzer.prepare(engine);
final String resource = "ruby/vulnerable/gems/rails-4.1.15/Gemfile.lock"; final String resource = "ruby/vulnerable/gems/rails-4.1.15/Gemfile.lock";
final Dependency result = new Dependency(BaseTest.getResourceAsFile(this, resource)); final Dependency result = new Dependency(BaseTest.getResourceAsFile(this, resource));
analyzer.analyze(result, engine); analyzer.analyze(result, engine);
@@ -151,7 +151,7 @@ public class RubyBundleAuditAnalyzerIT extends BaseDBTestCase {
public void testAddCriticalityToVulnerability() throws AnalysisException, DatabaseException { public void testAddCriticalityToVulnerability() throws AnalysisException, DatabaseException {
try (Engine engine = new Engine(getSettings())) { try (Engine engine = new Engine(getSettings())) {
engine.doUpdates(); engine.doUpdates();
analyzer.initialize(engine); analyzer.prepare(engine);
final Dependency result = new Dependency(BaseTest.getResourceAsFile(this, final Dependency result = new Dependency(BaseTest.getResourceAsFile(this,
"ruby/vulnerable/gems/sinatra/Gemfile.lock")); "ruby/vulnerable/gems/sinatra/Gemfile.lock"));
@@ -177,10 +177,10 @@ public class RubyBundleAuditAnalyzerIT extends BaseDBTestCase {
// is still on the path then initialization works and the bundle-audit on the path works. // is still on the path then initialization works and the bundle-audit on the path works.
//set a non-exist bundle-audit //set a non-exist bundle-audit
// getSettings().setString(Settings.KEYS.ANALYZER_BUNDLE_AUDIT_PATH, "phantom-bundle-audit"); // getSettings().setString(Settings.KEYS.ANALYZER_BUNDLE_AUDIT_PATH, "phantom-bundle-audit");
// analyzer.initializeSettings(getSettings()); // analyzer.initialize(getSettings());
// try { // try {
// //initialize should fail. // //initialize should fail.
// analyzer.initialize(null); // analyzer.prepare(null);
// } catch (Exception e) { // } catch (Exception e) {
// //expected, so ignore. // //expected, so ignore.
// assertNotNull(e); // assertNotNull(e);

View File

@@ -53,9 +53,9 @@ public class RubyBundlerAnalyzerTest extends BaseTest {
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
analyzer = new RubyBundlerAnalyzer(); analyzer = new RubyBundlerAnalyzer();
analyzer.initializeSettings(getSettings()); analyzer.initialize(getSettings());
analyzer.setFilesMatched(true); analyzer.setFilesMatched(true);
analyzer.initialize(null); analyzer.prepare(null);
} }
/** /**

View File

@@ -53,9 +53,9 @@ public class RubyGemspecAnalyzerTest extends BaseTest {
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
analyzer = new RubyGemspecAnalyzer(); analyzer = new RubyGemspecAnalyzer();
analyzer.initializeSettings(getSettings()); analyzer.initialize(getSettings());
analyzer.setFilesMatched(true); analyzer.setFilesMatched(true);
analyzer.initialize(null); analyzer.prepare(null);
} }
/** /**

View File

@@ -37,14 +37,14 @@ public class SwiftAnalyzersTest extends BaseTest {
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
podsAnalyzer = new CocoaPodsAnalyzer(); podsAnalyzer = new CocoaPodsAnalyzer();
podsAnalyzer.initializeSettings(getSettings()); podsAnalyzer.initialize(getSettings());
podsAnalyzer.setFilesMatched(true); podsAnalyzer.setFilesMatched(true);
podsAnalyzer.initialize(null); podsAnalyzer.prepare(null);
spmAnalyzer = new SwiftPackageManagerAnalyzer(); spmAnalyzer = new SwiftPackageManagerAnalyzer();
spmAnalyzer.initializeSettings(getSettings()); spmAnalyzer.initialize(getSettings());
spmAnalyzer.setFilesMatched(true); spmAnalyzer.setFilesMatched(true);
spmAnalyzer.initialize(null); spmAnalyzer.prepare(null);
} }
/** /**

View File

@@ -48,7 +48,7 @@ public class VersionFilterAnalyzerTest extends BaseTest {
@Test @Test
public void testGetAnalysisPhase() { public void testGetAnalysisPhase() {
VersionFilterAnalyzer instance = new VersionFilterAnalyzer(); VersionFilterAnalyzer instance = new VersionFilterAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
AnalysisPhase expResult = AnalysisPhase.POST_INFORMATION_COLLECTION; AnalysisPhase expResult = AnalysisPhase.POST_INFORMATION_COLLECTION;
AnalysisPhase result = instance.getAnalysisPhase(); AnalysisPhase result = instance.getAnalysisPhase();
assertEquals(expResult, result); assertEquals(expResult, result);
@@ -61,7 +61,7 @@ public class VersionFilterAnalyzerTest extends BaseTest {
@Test @Test
public void testGetAnalyzerEnabledSettingKey() { public void testGetAnalyzerEnabledSettingKey() {
VersionFilterAnalyzer instance = new VersionFilterAnalyzer(); VersionFilterAnalyzer instance = new VersionFilterAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
String expResult = Settings.KEYS.ANALYZER_VERSION_FILTER_ENABLED; String expResult = Settings.KEYS.ANALYZER_VERSION_FILTER_ENABLED;
String result = instance.getAnalyzerEnabledSettingKey(); String result = instance.getAnalyzerEnabledSettingKey();
assertEquals(expResult, result); assertEquals(expResult, result);
@@ -79,7 +79,7 @@ public class VersionFilterAnalyzerTest extends BaseTest {
dependency.addEvidence(EvidenceType.VERSION, "other", "Implementation-Version", "1.2.3", Confidence.HIGHEST); dependency.addEvidence(EvidenceType.VERSION, "other", "Implementation-Version", "1.2.3", Confidence.HIGHEST);
VersionFilterAnalyzer instance = new VersionFilterAnalyzer(); VersionFilterAnalyzer instance = new VersionFilterAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
instance.analyzeDependency(dependency, null); instance.analyzeDependency(dependency, null);
assertEquals(3, dependency.getEvidence(EvidenceType.VERSION).size()); assertEquals(3, dependency.getEvidence(EvidenceType.VERSION).size());
@@ -120,7 +120,7 @@ public class VersionFilterAnalyzerTest extends BaseTest {
dependency.addEvidence(EvidenceType.VERSION, "other", "Implementation-Version", "1.2.3", Confidence.HIGHEST); dependency.addEvidence(EvidenceType.VERSION, "other", "Implementation-Version", "1.2.3", Confidence.HIGHEST);
VersionFilterAnalyzer instance = new VersionFilterAnalyzer(); VersionFilterAnalyzer instance = new VersionFilterAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
instance.analyzeDependency(dependency, null); instance.analyzeDependency(dependency, null);
assertEquals(3, dependency.getEvidence(EvidenceType.VERSION).size()); assertEquals(3, dependency.getEvidence(EvidenceType.VERSION).size());
@@ -157,7 +157,7 @@ public class VersionFilterAnalyzerTest extends BaseTest {
dependency.addEvidence(EvidenceType.VERSION, "other", "Implementation-Version", "1.2.3", Confidence.HIGHEST); dependency.addEvidence(EvidenceType.VERSION, "other", "Implementation-Version", "1.2.3", Confidence.HIGHEST);
VersionFilterAnalyzer instance = new VersionFilterAnalyzer(); VersionFilterAnalyzer instance = new VersionFilterAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
instance.analyzeDependency(dependency, null); instance.analyzeDependency(dependency, null);
assertEquals(3, dependency.getEvidence(EvidenceType.VERSION).size()); assertEquals(3, dependency.getEvidence(EvidenceType.VERSION).size());
@@ -184,7 +184,7 @@ public class VersionFilterAnalyzerTest extends BaseTest {
dependency.addEvidence(EvidenceType.VERSION, "other", "Implementation-Version", "1.2.3", Confidence.HIGHEST); dependency.addEvidence(EvidenceType.VERSION, "other", "Implementation-Version", "1.2.3", Confidence.HIGHEST);
VersionFilterAnalyzer instance = new VersionFilterAnalyzer(); VersionFilterAnalyzer instance = new VersionFilterAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
instance.analyzeDependency(dependency, null); instance.analyzeDependency(dependency, null);
assertEquals(3, dependency.getEvidence(EvidenceType.VERSION).size()); assertEquals(3, dependency.getEvidence(EvidenceType.VERSION).size());

View File

@@ -42,7 +42,7 @@ public class VulnerabilitySuppressionAnalyzerIT extends BaseDBTestCase {
@Test @Test
public void testGetName() { public void testGetName() {
VulnerabilitySuppressionAnalyzer instance = new VulnerabilitySuppressionAnalyzer(); VulnerabilitySuppressionAnalyzer instance = new VulnerabilitySuppressionAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
String expResult = "Vulnerability Suppression Analyzer"; String expResult = "Vulnerability Suppression Analyzer";
String result = instance.getName(); String result = instance.getName();
assertEquals(expResult, result); assertEquals(expResult, result);
@@ -55,7 +55,7 @@ public class VulnerabilitySuppressionAnalyzerIT extends BaseDBTestCase {
@Test @Test
public void testGetAnalysisPhase() { public void testGetAnalysisPhase() {
VulnerabilitySuppressionAnalyzer instance = new VulnerabilitySuppressionAnalyzer(); VulnerabilitySuppressionAnalyzer instance = new VulnerabilitySuppressionAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
AnalysisPhase expResult = AnalysisPhase.POST_FINDING_ANALYSIS; AnalysisPhase expResult = AnalysisPhase.POST_FINDING_ANALYSIS;
AnalysisPhase result = instance.getAnalysisPhase(); AnalysisPhase result = instance.getAnalysisPhase();
assertEquals(expResult, result); assertEquals(expResult, result);
@@ -84,8 +84,8 @@ public class VulnerabilitySuppressionAnalyzerIT extends BaseDBTestCase {
assertTrue(cpeSize > 0); assertTrue(cpeSize > 0);
getSettings().setString(Settings.KEYS.SUPPRESSION_FILE, suppression.getAbsolutePath()); getSettings().setString(Settings.KEYS.SUPPRESSION_FILE, suppression.getAbsolutePath());
VulnerabilitySuppressionAnalyzer instance = new VulnerabilitySuppressionAnalyzer(); VulnerabilitySuppressionAnalyzer instance = new VulnerabilitySuppressionAnalyzer();
instance.initializeSettings(getSettings()); instance.initialize(getSettings());
instance.initialize(engine); instance.prepare(engine);
instance.analyze(dependency, engine); instance.analyze(dependency, engine);
cveSize = cveSize > 1 ? cveSize - 2 : 0; cveSize = cveSize > 1 ? cveSize - 2 : 0;
cpeSize = cpeSize > 0 ? cpeSize - 1 : 0; cpeSize = cpeSize > 0 ? cpeSize - 1 : 0;