minor updates and addition of JavaDoc

Former-commit-id: ac465b9c252dec453f8528b7e466bd61f8d7adb4
This commit is contained in:
Jeremy Long
2014-12-03 15:53:22 -05:00
parent 78008330fe
commit d724855dfc

View File

@@ -22,6 +22,7 @@ import org.apache.maven.project.MavenProject;
import org.owasp.dependencycheck.analyzer.Analyzer; import org.owasp.dependencycheck.analyzer.Analyzer;
import org.owasp.dependencycheck.analyzer.CPEAnalyzer; import org.owasp.dependencycheck.analyzer.CPEAnalyzer;
import org.owasp.dependencycheck.data.nvdcve.DatabaseException; import org.owasp.dependencycheck.data.nvdcve.DatabaseException;
import org.owasp.dependencycheck.utils.Settings;
/** /**
* A modified version of the core engine specifically designed to persist some data between multiple executions of a * A modified version of the core engine specifically designed to persist some data between multiple executions of a
@@ -44,21 +45,40 @@ public class Engine extends org.owasp.dependencycheck.Engine {
*/ */
private MavenProject currentProject; private MavenProject currentProject;
private Engine() throws DatabaseException { /**
} * Creates a new Engine to perform anyalsis on dependencies.
*
* @param project the current Maven project
* @throws DatabaseException thrown if there is an issue connecting to the database
*/
public Engine(MavenProject project) throws DatabaseException { public Engine(MavenProject project) throws DatabaseException {
this.currentProject = project; this.currentProject = project;
MavenProject parent = getRootParent(); MavenProject parent = getRootParent();
if ((parent != null) && (parent.getContextValue("dependency-check-data-was-updated") != null)) { if (parent != null && parent.getContextValue("dependency-check-data-was-updated") != null) {
System.setProperty("autoupdate", Boolean.FALSE.toString()); System.setProperty(Settings.KEYS.AUTO_UPDATE, Boolean.FALSE.toString());
} }
initializeEngine(); initializeEngine();
if (getHasBeenUpdated()) { if (parent != null) {
getRootParent().setContextValue("dependency-check-data-was-updated", Boolean.valueOf(true)); parent.setContextValue("dependency-check-data-was-updated", Boolean.valueOf(true));
} }
} }
/**
* This constructor should not be called. Use Engine(MavenProject) instead.
*
* @throws DatabaseException thrown if there is an issue connecting to the database
*/
private Engine() throws DatabaseException {
}
/**
* Initializes the given analyzer. This skips the initialization of the CPEAnalyzer if it has been initialized by a
* previous execution.
*
* @param analyzer the analyzer to initialize
* @return the initialized analyzer
*/
@Override
protected Analyzer initializeAnalyzer(Analyzer analyzer) { protected Analyzer initializeAnalyzer(Analyzer analyzer) {
if ((analyzer instanceof CPEAnalyzer)) { if ((analyzer instanceof CPEAnalyzer)) {
CPEAnalyzer cpe = getPreviouslyLoadedAnalyzer(); CPEAnalyzer cpe = getPreviouslyLoadedAnalyzer();
@@ -71,6 +91,12 @@ public class Engine extends org.owasp.dependencycheck.Engine {
return super.initializeAnalyzer(analyzer); return super.initializeAnalyzer(analyzer);
} }
/**
* Closes the given analyzer. This skips closing the CPEAnalyzer.
*
* @param analyzer
*/
@Override
protected void closeAnalyzer(Analyzer analyzer) { protected void closeAnalyzer(Analyzer analyzer) {
if ((analyzer instanceof CPEAnalyzer)) { if ((analyzer instanceof CPEAnalyzer)) {
if (getPreviouslyLoadedAnalyzer() == null) { if (getPreviouslyLoadedAnalyzer() == null) {
@@ -81,10 +107,9 @@ public class Engine extends org.owasp.dependencycheck.Engine {
} }
} }
public void cleanup() { /**
super.cleanup(); * Closes the CPEAnalyzer if it has been created and persisted in the root parent MavenProject context.
} */
public void cleanupFinal() { public void cleanupFinal() {
CPEAnalyzer cpe = getPreviouslyLoadedAnalyzer(); CPEAnalyzer cpe = getPreviouslyLoadedAnalyzer();
if (cpe != null) { if (cpe != null) {
@@ -92,6 +117,11 @@ public class Engine extends org.owasp.dependencycheck.Engine {
} }
} }
/**
* Gets the CPEAnalyzer from the root Maven Project.
*
* @return an initialized CPEAnalyzer
*/
private CPEAnalyzer getPreviouslyLoadedAnalyzer() { private CPEAnalyzer getPreviouslyLoadedAnalyzer() {
CPEAnalyzer cpe = null; CPEAnalyzer cpe = null;
MavenProject project = getRootParent(); MavenProject project = getRootParent();
@@ -101,6 +131,11 @@ public class Engine extends org.owasp.dependencycheck.Engine {
return cpe; return cpe;
} }
/**
* Stores a CPEAnalyzer in the root Maven Project.
*
* @param cpe the CPEAnalyzer to store
*/
private void storeCPEAnalyzer(CPEAnalyzer cpe) { private void storeCPEAnalyzer(CPEAnalyzer cpe) {
MavenProject p = getRootParent(); MavenProject p = getRootParent();
if (p != null) { if (p != null) {
@@ -108,6 +143,11 @@ public class Engine extends org.owasp.dependencycheck.Engine {
} }
} }
/**
* Returns the root Maven Project.
*
* @return the root Maven Project
*/
private MavenProject getRootParent() { private MavenProject getRootParent() {
if (this.currentProject == null) { if (this.currentProject == null) {
return null; return null;