mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-21 00:29:21 +01:00
reformated and changed isEnabled to a getter by adding checkEnabled that is called during initialization
Former-commit-id: 3bfb0dd2da37d718708d047e425fb8b125dddf34
This commit is contained in:
@@ -24,7 +24,6 @@ import java.net.URL;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.owasp.dependencycheck.Engine;
|
import org.owasp.dependencycheck.Engine;
|
||||||
import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
|
import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
|
||||||
import org.owasp.dependencycheck.data.nexus.MavenArtifact;
|
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.InvalidSettingException;
|
||||||
import org.owasp.dependencycheck.utils.Settings;
|
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.
|
* 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
|
* @author colezlaw
|
||||||
*/
|
*/
|
||||||
public class NexusAnalyzer extends AbstractFileTypeAnalyzer {
|
public class NexusAnalyzer extends AbstractFileTypeAnalyzer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default URL - this will be used by the CentralAnalyzer to determine whether to enable this.
|
* 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;
|
private NexusSearch searcher;
|
||||||
|
|
||||||
/**
|
private boolean enabled = checkEnabled();
|
||||||
* Determine whether to enable this analyzer or not.
|
|
||||||
*
|
private boolean checkEnabled() {
|
||||||
* @return whether the analyzer should be enabled
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean isEnabled() {
|
|
||||||
/* Enable this analyzer ONLY if the Nexus URL has been set to something
|
/* 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
|
other than the default one (if it's the default one, we'll use the
|
||||||
central one) and it's enabled by the user.
|
central one) and it's enabled by the user.
|
||||||
*/
|
*/
|
||||||
boolean retval = false;
|
boolean retval = false;
|
||||||
try {
|
try {
|
||||||
if ((! DEFAULT_URL.equals(Settings.getString(Settings.KEYS.ANALYZER_NEXUS_URL)))
|
if ((!DEFAULT_URL.equals(Settings.getString(Settings.KEYS.ANALYZER_NEXUS_URL)))
|
||||||
&& Settings.getBoolean(Settings.KEYS.ANALYZER_NEXUS_ENABLED)) {
|
&& Settings.getBoolean(Settings.KEYS.ANALYZER_NEXUS_ENABLED)) {
|
||||||
LOGGER.info("Enabling Nexus analyzer");
|
LOGGER.info("Enabling Nexus analyzer");
|
||||||
retval = true;
|
retval = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -108,6 +102,16 @@ public class NexusAnalyzer extends AbstractFileTypeAnalyzer {
|
|||||||
return retval;
|
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.
|
* Initializes the analyzer once before any analysis is performed.
|
||||||
*
|
*
|
||||||
@@ -184,7 +188,7 @@ public class NexusAnalyzer extends AbstractFileTypeAnalyzer {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void analyzeFileType(Dependency dependency, Engine engine) throws AnalysisException {
|
public void analyzeFileType(Dependency dependency, Engine engine) throws AnalysisException {
|
||||||
if (! isEnabled()) {
|
if (!isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user