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

View File

@@ -28,7 +28,7 @@ import org.slf4j.Logger;
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.
*
* @author Jeremy Long
@@ -83,48 +83,43 @@ public abstract class AbstractAnalyzer implements Analyzer {
* @param settings the configured settings to use
*/
@Override
public void initializeSettings(Settings settings) {
public void initialize(Settings settings) {
this.settings = settings;
}
/**
* <p>
* Returns the setting key to determine if the analyzer is enabled.</p>
* Initialize the abstract analyzer.
*
* @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
* 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
* Prepares a given Analyzer. This will be skipped if the analyzer is
* disabled.
*
* @param engine a reference to the dependency-check engine
* @throws InitializationException thrown if there is an exception
*/
protected void initializeAnalyzer(Engine engine) throws InitializationException {
// Intentionally empty, analyzer will override this if they must initialize 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.
protected void prepareAnalyzer(Engine engine) throws InitializationException {
// Intentionally empty, analyzer will override this if they must prepare anything.
}
/**
@@ -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
* @throws InitializationException thrown if there is an exception
* @param dependency the dependency to analyze
* @param engine the engine scanning
* @throws AnalysisException thrown if there is an analysis exception
*/
@Override
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());
}
}
protected abstract void analyzeDependency(Dependency dependency, Engine engine) throws AnalysisException;
/**
* 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.
*
@@ -186,8 +178,15 @@ public abstract class AbstractAnalyzer implements Analyzer {
*/
@Override
public boolean supportsParallelProcessing() {
//temporarily removing parallel processing from all analyzders until further examination of thread safety occurs.
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;
/**
* Set the value of filesMatched. A flag indicating whether the scan
* included any file types this analyzer supports.
@@ -69,9 +68,9 @@ public abstract class AbstractFileTypeAnalyzer extends AbstractAnalyzer implemen
* initialization
*/
@Override
protected final void initializeAnalyzer(Engine engine) throws InitializationException {
protected final void prepareAnalyzer(Engine engine) throws InitializationException {
if (filesMatched) {
initializeFileTypeAnalyzer(engine);
prepareFileTypeAnalyzer(engine);
} else {
this.setEnabled(false);
}
@@ -94,13 +93,13 @@ public abstract class AbstractFileTypeAnalyzer extends AbstractAnalyzer implemen
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
* @throws InitializationException thrown if there is an exception during
* initialization
*/
protected abstract void initializeFileTypeAnalyzer(Engine engine) throws InitializationException;
protected abstract void prepareFileTypeAnalyzer(Engine engine) throws InitializationException;
//</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>
* <p>
* 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.
* @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
* @throws InitializationException thrown if there is an exception
*/
@Override
public synchronized void initializeAnalyzer(Engine engine) throws InitializationException {
public synchronized void prepareAnalyzer(Engine engine) throws InitializationException {
if (rules == null) {
try {
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
* analyzers and call the methods in the following order:</p>
* <ol>
* <li>{@link #initializeSettings(org.owasp.dependencycheck.utils.Settings)}</li>
* <li>{@link #initialize(org.owasp.dependencycheck.Engine)}</li>
* <li>{@link #initialize(org.owasp.dependencycheck.utils.Settings)}</li>
* <li>{@link #prepare(org.owasp.dependencycheck.Engine)}</li>
* <li>{@link #analyze(org.owasp.dependencycheck.dependency.Dependency, org.owasp.dependencycheck.Engine)}</li>
* <li>{@link #close()}</li>
* </ol>
@@ -75,17 +75,17 @@ public interface Analyzer {
*
* @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.
*
* @param engine a reference to the dependency-check engine
* @throws InitializationException is thrown if an exception occurs
* 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

View File

@@ -126,8 +126,8 @@ public class ArchiveAnalyzer extends AbstractFileTypeAnalyzer {
* @param settings the configured settings to use
*/
@Override
public void initializeSettings(Settings settings) {
super.initializeSettings(settings);
public void initialize(Settings settings) {
super.initialize(settings);
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
* @throws InitializationException is thrown if there is an exception
* deleting or creating temporary files
*/
@Override
public void initializeFileTypeAnalyzer(Engine engine) throws InitializationException {
public void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
try {
final File baseDir = getSettings().getTempDirectory();
tempFileLocation = File.createTempFile("check", "tmp", baseDir);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -85,7 +85,7 @@ public class ComposerLockAnalyzer extends AbstractFileTypeAnalyzer {
* instance of SHA1
*/
@Override
protected void initializeFileTypeAnalyzer(Engine engine) throws InitializationException {
protected void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
try {
getSha1MessageDigest();
} 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
* @throws InitializationException thrown if there is an exception
*/
@Override
public void initializeAnalyzer(Engine engine) throws InitializationException {
public void prepareAnalyzer(Engine engine) throws InitializationException {
try {
loadHintRules();
} catch (HintParseException ex) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -147,7 +147,7 @@ public class RubyBundleAuditAnalyzer extends AbstractFileTypeAnalyzer {
* @throws InitializationException if anything goes wrong
*/
@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.
if (engine != null) {
this.cvedb = engine.getDatabase();

View File

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

View File

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

View File

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

View File

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

View File

@@ -49,7 +49,7 @@ public class ArchiveAnalyzerTest extends BaseTest {
public void testZippableExtensions() throws Exception {
assumeFalse(isPreviouslyLoaded("org.owasp.dependencycheck.analyzer.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.z2")));
assertTrue(instance.getFileFilter().accept(new File("c:/test.z3")));

View File

@@ -72,9 +72,9 @@ public class AssemblyAnalyzerTest extends BaseTest {
super.setUp();
try {
analyzer = new AssemblyAnalyzer();
analyzer.initializeSettings(getSettings());
analyzer.initialize(getSettings());
analyzer.accept(new File("test.dll")); // trick into "thinking it is active"
analyzer.initialize(null);
analyzer.prepare(null);
assertGrokAssembly();
} catch (Exception e) {
if (e.getMessage().contains("Could not execute .NET AssemblyAnalyzer")) {
@@ -190,9 +190,9 @@ public class AssemblyAnalyzerTest extends BaseTest {
System.setProperty(LOG_KEY, "error");
// Have to make a NEW analyzer because during setUp, it would have gotten the correct one
AssemblyAnalyzer aanalyzer = new AssemblyAnalyzer();
aanalyzer.initializeSettings(getSettings());
aanalyzer.initialize(getSettings());
aanalyzer.accept(new File("test.dll")); // trick into "thinking it is active"
aanalyzer.initialize(null);
aanalyzer.prepare(null);
fail("Expected an InitializationException");
} catch (InitializationException ae) {
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 {
super.setUp();
analyzer = new AutoconfAnalyzer();
analyzer.initializeSettings(getSettings());
analyzer.initialize(getSettings());
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 {
super.setUp();
analyzer = new CMakeAnalyzer();
analyzer.initializeSettings(getSettings());
analyzer.initialize(getSettings());
analyzer.setFilesMatched(true);
analyzer.initialize(null);
analyzer.prepare(null);
}
/**
@@ -192,8 +192,8 @@ public class CMakeAnalyzerTest extends BaseDBTestCase {
analyzer = new CMakeAnalyzer();
analyzer.setFilesMatched(true);
assertTrue(analyzer.isEnabled());
analyzer.initializeSettings(getSettings());
analyzer.initialize(null);
analyzer.initialize(getSettings());
analyzer.prepare(null);
assertFalse(analyzer.isEnabled());
}

View File

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

View File

@@ -59,9 +59,9 @@ public class ComposerLockAnalyzerTest extends BaseDBTestCase {
public void setUp() throws Exception {
super.setUp();
analyzer = new ComposerLockAnalyzer();
analyzer.initializeSettings(getSettings());
analyzer.initialize(getSettings());
analyzer.setFilesMatched(true);
analyzer.initialize(null);
analyzer.prepare(null);
}
/**
@@ -116,9 +116,9 @@ public class ComposerLockAnalyzerTest extends BaseDBTestCase {
analyzer = new ComposerLockAnalyzer();
analyzer.setFilesMatched(true);
analyzer.initializeSettings(getSettings());
analyzer.initialize(getSettings());
assertTrue(analyzer.isEnabled());
analyzer.initialize(null);
analyzer.prepare(null);
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
public void testInitialize() {
FileNameAnalyzer instance = new FileNameAnalyzer();
try {
instance.initializeSettings(getSettings());
instance.initialize(null);
instance.initialize(getSettings());
instance.prepare(null);
} catch (InitializationException ex) {
fail(ex.getMessage());
}

View File

@@ -114,8 +114,8 @@ public class HintAnalyzerTest extends BaseDBTestCase {
File path = BaseTest.getResourceAsFile(this, "hints_12.xml");
getSettings().setString(Settings.KEYS.HINTS_FILE, path.getPath());
HintAnalyzer instance = new HintAnalyzer();
instance.initializeSettings(getSettings());
instance.initialize(null);
instance.initialize(getSettings());
instance.prepare(null);
Dependency d = new Dependency();
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);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -54,8 +54,8 @@ public class PythonPackageAnalyzerTest extends BaseTest {
super.setUp();
analyzer = new PythonPackageAnalyzer();
analyzer.setFilesMatched(true);
analyzer.initializeSettings(getSettings());
analyzer.initialize(null);
analyzer.initialize(getSettings());
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_CENTRAL_ENABLED, false);
analyzer = new RubyBundleAuditAnalyzer();
analyzer.initializeSettings(getSettings());
analyzer.initialize(getSettings());
analyzer.setFilesMatched(true);
}
@@ -119,7 +119,7 @@ public class RubyBundleAuditAnalyzerIT extends BaseDBTestCase {
public void testAnalysis() throws AnalysisException, DatabaseException {
try (Engine engine = new Engine(getSettings())) {
engine.openDatabase();
analyzer.initialize(engine);
analyzer.prepare(engine);
final String resource = "ruby/vulnerable/gems/rails-4.1.15/Gemfile.lock";
final Dependency result = new Dependency(BaseTest.getResourceAsFile(this, resource));
analyzer.analyze(result, engine);
@@ -151,7 +151,7 @@ public class RubyBundleAuditAnalyzerIT extends BaseDBTestCase {
public void testAddCriticalityToVulnerability() throws AnalysisException, DatabaseException {
try (Engine engine = new Engine(getSettings())) {
engine.doUpdates();
analyzer.initialize(engine);
analyzer.prepare(engine);
final Dependency result = new Dependency(BaseTest.getResourceAsFile(this,
"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.
//set a non-exist bundle-audit
// getSettings().setString(Settings.KEYS.ANALYZER_BUNDLE_AUDIT_PATH, "phantom-bundle-audit");
// analyzer.initializeSettings(getSettings());
// analyzer.initialize(getSettings());
// try {
// //initialize should fail.
// analyzer.initialize(null);
// analyzer.prepare(null);
// } catch (Exception e) {
// //expected, so ignore.
// assertNotNull(e);

View File

@@ -53,9 +53,9 @@ public class RubyBundlerAnalyzerTest extends BaseTest {
public void setUp() throws Exception {
super.setUp();
analyzer = new RubyBundlerAnalyzer();
analyzer.initializeSettings(getSettings());
analyzer.initialize(getSettings());
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 {
super.setUp();
analyzer = new RubyGemspecAnalyzer();
analyzer.initializeSettings(getSettings());
analyzer.initialize(getSettings());
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 {
super.setUp();
podsAnalyzer = new CocoaPodsAnalyzer();
podsAnalyzer.initializeSettings(getSettings());
podsAnalyzer.initialize(getSettings());
podsAnalyzer.setFilesMatched(true);
podsAnalyzer.initialize(null);
podsAnalyzer.prepare(null);
spmAnalyzer = new SwiftPackageManagerAnalyzer();
spmAnalyzer.initializeSettings(getSettings());
spmAnalyzer.initialize(getSettings());
spmAnalyzer.setFilesMatched(true);
spmAnalyzer.initialize(null);
spmAnalyzer.prepare(null);
}
/**

View File

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

View File

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