From e662041d066c378d7384953f013732608955e2e1 Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Tue, 11 Nov 2014 14:41:08 -0500 Subject: [PATCH] reformated and changed isEnabled to a getter by adding checkEnabled that is called during initialization Former-commit-id: 3bfb0dd2da37d718708d047e425fb8b125dddf34 --- .../analyzer/NexusAnalyzer.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/NexusAnalyzer.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/NexusAnalyzer.java index 22db369ad..d6324d11e 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/NexusAnalyzer.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/NexusAnalyzer.java @@ -24,7 +24,6 @@ import java.net.URL; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; - import org.owasp.dependencycheck.Engine; import org.owasp.dependencycheck.analyzer.exception.AnalysisException; import org.owasp.dependencycheck.data.nexus.MavenArtifact; @@ -34,8 +33,6 @@ import org.owasp.dependencycheck.dependency.Dependency; import org.owasp.dependencycheck.utils.InvalidSettingException; import org.owasp.dependencycheck.utils.Settings; -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; - /** * Analyzer which will attempt to locate a dependency on a Nexus service by SHA-1 digest of the dependency. * @@ -51,6 +48,7 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; * @author colezlaw */ public class NexusAnalyzer extends AbstractFileTypeAnalyzer { + /** * The default URL - this will be used by the CentralAnalyzer to determine whether to enable this. */ @@ -81,21 +79,17 @@ public class NexusAnalyzer extends AbstractFileTypeAnalyzer { */ private NexusSearch searcher; - /** - * Determine whether to enable this analyzer or not. - * - * @return whether the analyzer should be enabled - */ - @Override - public boolean isEnabled() { + private boolean enabled = checkEnabled(); + + private boolean checkEnabled() { /* Enable this analyzer ONLY if the Nexus URL has been set to something - other than the default one (if it's the default one, we'll use the - central one) and it's enabled by the user. + other than the default one (if it's the default one, we'll use the + central one) and it's enabled by the user. */ boolean retval = false; try { - if ((! DEFAULT_URL.equals(Settings.getString(Settings.KEYS.ANALYZER_NEXUS_URL))) - && Settings.getBoolean(Settings.KEYS.ANALYZER_NEXUS_ENABLED)) { + if ((!DEFAULT_URL.equals(Settings.getString(Settings.KEYS.ANALYZER_NEXUS_URL))) + && Settings.getBoolean(Settings.KEYS.ANALYZER_NEXUS_ENABLED)) { LOGGER.info("Enabling Nexus analyzer"); retval = true; } else { @@ -108,6 +102,16 @@ public class NexusAnalyzer extends AbstractFileTypeAnalyzer { return retval; } + /** + * Determine whether to enable this analyzer or not. + * + * @return whether the analyzer should be enabled + */ + @Override + public boolean isEnabled() { + return enabled; + } + /** * Initializes the analyzer once before any analysis is performed. * @@ -184,7 +188,7 @@ public class NexusAnalyzer extends AbstractFileTypeAnalyzer { */ @Override public void analyzeFileType(Dependency dependency, Engine engine) throws AnalysisException { - if (! isEnabled()) { + if (!isEnabled()) { return; } try {