various findbug, checkstyle, documentation fixes

Former-commit-id: 66fc0bbef000fc9e4210054f15ab973909fe919f
This commit is contained in:
Jeremy Long
2014-03-23 23:07:27 -04:00
parent 690192300f
commit 6c85e3502e
8 changed files with 42 additions and 37 deletions

View File

@@ -41,7 +41,7 @@ public abstract class AbstractFileTypeAnalyzer extends AbstractAnalyzer implemen
* enabled. * enabled.
*/ */
public AbstractFileTypeAnalyzer() { public AbstractFileTypeAnalyzer() {
String key = Settings.KEYS.getFileAnalyzerEnabledKey(getAnalyzerSettingKey()); final String key = getAnalyzerEnabledSettingKey();
try { try {
enabled = Settings.getBoolean(key, true); enabled = Settings.getBoolean(key, true);
} catch (InvalidSettingException ex) { } catch (InvalidSettingException ex) {
@@ -82,10 +82,13 @@ public abstract class AbstractFileTypeAnalyzer extends AbstractAnalyzer implemen
this.filesMatched = filesMatched; this.filesMatched = filesMatched;
} }
/**
* A flag indicating whether or not the analyzer is enabled.
*/
private boolean enabled = true; private boolean enabled = true;
/** /**
* Get the value of enabled * Get the value of enabled.
* *
* @return the value of enabled * @return the value of enabled
*/ */
@@ -94,7 +97,7 @@ public abstract class AbstractFileTypeAnalyzer extends AbstractAnalyzer implemen
} }
/** /**
* Set the value of enabled * Set the value of enabled.
* *
* @param enabled new value of enabled * @param enabled new value of enabled
*/ */
@@ -139,14 +142,13 @@ public abstract class AbstractFileTypeAnalyzer extends AbstractAnalyzer implemen
/** /**
* <p> * <p>
* Returns the key used in the properties file to reference the analyzer. An example would be the JarAnalyzer where * Returns the setting key to determine if the analyzer is enabled.</p>
* the key is "jar". One of the associated properties would be 'analyzer.jar.enabled.
* *
* @return a short string used to look up configuration properties * @return the key for the analyzer's enabled property
*/ */
protected abstract String getAnalyzerSettingKey(); protected abstract String getAnalyzerEnabledSettingKey();
//</editor-fold>
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Final implementations for the Analyzer interface"> //<editor-fold defaultstate="collapsed" desc="Final implementations for the Analyzer interface">
/** /**
* Initializes the analyzer. * Initializes the analyzer.
@@ -188,13 +190,14 @@ public abstract class AbstractFileTypeAnalyzer extends AbstractAnalyzer implemen
if (!enabled) { if (!enabled) {
return false; return false;
} }
Set<String> ext = getSupportedExtensions(); final Set<String> ext = getSupportedExtensions();
if (ext == null) { if (ext == null) {
String msg = String.format("The '%s%' analyzer is misconfigured and does not have any file extensions; it will be disabled", getName()); final String msg = String.format("The '%s' analyzer is misconfigured and does not have any file extensions;"
+ " it will be disabled", getName());
Logger.getLogger(AbstractFileTypeAnalyzer.class.getName()).log(Level.SEVERE, msg); Logger.getLogger(AbstractFileTypeAnalyzer.class.getName()).log(Level.SEVERE, msg);
return false; return false;
} else { } else {
boolean match = ext.contains(extension); final boolean match = ext.contains(extension);
if (match) { if (match) {
filesMatched = match; filesMatched = match;
} }

View File

@@ -140,13 +140,13 @@ public class ArchiveAnalyzer extends AbstractFileTypeAnalyzer {
//</editor-fold> //</editor-fold>
/** /**
* Returns the key used in the properties file to reference the analyzer. * Returns the key used in the properties file to reference the analyzer's enabled property.
* *
* @return a short string used to look up configuration properties * @return the analyzer's enabled property setting key
*/ */
@Override @Override
protected String getAnalyzerSettingKey() { protected String getAnalyzerEnabledSettingKey() {
return "archive"; return Settings.KEYS.ANALYZER_ARCHIVE_ENABLED;
} }
/** /**

View File

@@ -258,12 +258,12 @@ public class AssemblyAnalyzer extends AbstractFileTypeAnalyzer {
} }
/** /**
* Returns the key used in the properties file to reference the analyzer. * Returns the key used in the properties file to reference the analyzer's enabled property.
* *
* @return a short string used to look up configuration properties * @return the analyzer's enabled property setting key
*/ */
@Override @Override
protected String getAnalyzerSettingKey() { protected String getAnalyzerEnabledSettingKey() {
return "assembly"; return Settings.KEYS.ANALYZER_ASSEMBLY_ENABLED;
} }
} }

View File

@@ -223,13 +223,13 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer {
//</editor-fold> //</editor-fold>
/** /**
* Returns the key used in the properties file to reference the analyzer. * Returns the key used in the properties file to reference the analyzer's enabled property.
* *
* @return a short string used to look up configuration properties * @return the analyzer's enabled property setting key
*/ */
@Override @Override
protected String getAnalyzerSettingKey() { protected String getAnalyzerEnabledSettingKey() {
return "jar"; return Settings.KEYS.ANALYZER_JAR_ENABLED;
} }
/** /**
@@ -1022,7 +1022,7 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer {
*/ */
private boolean isImportPackage(String key, String value) { private boolean isImportPackage(String key, String value) {
final Pattern packageRx = Pattern.compile("^([a-zA-Z0-9_#\\$\\*\\.]+\\s*[,;]\\s*)+([a-zA-Z0-9_#\\$\\*\\.]+\\s*)?$"); final Pattern packageRx = Pattern.compile("^([a-zA-Z0-9_#\\$\\*\\.]+\\s*[,;]\\s*)+([a-zA-Z0-9_#\\$\\*\\.]+\\s*)?$");
boolean matches = packageRx.matcher(value).matches(); final boolean matches = packageRx.matcher(value).matches();
return matches && (key.contains("import") || key.contains("include") || value.length() > 10); return matches && (key.contains("import") || key.contains("include") || value.length() > 10);
} }

View File

@@ -29,6 +29,7 @@ import java.util.regex.Pattern;
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.dependency.Dependency; import org.owasp.dependencycheck.dependency.Dependency;
import org.owasp.dependencycheck.utils.Settings;
/** /**
* *
@@ -88,13 +89,13 @@ public class JavaScriptAnalyzer extends AbstractFileTypeAnalyzer {
} }
//</editor-fold> //</editor-fold>
/** /**
* Returns the key used in the properties file to reference the analyzer. * Returns the key used in the properties file to reference the analyzer's enabled property.
* *
* @return a short string used to look up configuration properties * @return the analyzer's enabled property setting key
*/ */
@Override @Override
protected String getAnalyzerSettingKey() { protected String getAnalyzerEnabledSettingKey() {
return "javascript"; return Settings.KEYS.ANALYZER_JAVASCRIPT_ENABLED;
} }
/** /**

View File

@@ -111,13 +111,13 @@ public class NexusAnalyzer extends AbstractFileTypeAnalyzer {
} }
/** /**
* Returns the key used in the properties file to reference the analyzer. * Returns the key used in the properties file to reference the analyzer's enabled property.
* *
* @return a short string used to look up configuration properties * @return the analyzer's enabled property setting key
*/ */
@Override @Override
protected String getAnalyzerSettingKey() { protected String getAnalyzerEnabledSettingKey() {
return "nexus"; return Settings.KEYS.ANALYZER_NEXUS_ENABLED;
} }
/** /**

View File

@@ -31,6 +31,7 @@ import org.owasp.dependencycheck.data.nuget.NuspecParser;
import org.owasp.dependencycheck.data.nuget.XPathNuspecParser; import org.owasp.dependencycheck.data.nuget.XPathNuspecParser;
import org.owasp.dependencycheck.dependency.Confidence; import org.owasp.dependencycheck.dependency.Confidence;
import org.owasp.dependencycheck.dependency.Dependency; import org.owasp.dependencycheck.dependency.Dependency;
import org.owasp.dependencycheck.utils.Settings;
/** /**
* Analyzer which will parse a Nuspec file to gather module information. * Analyzer which will parse a Nuspec file to gather module information.
@@ -79,13 +80,13 @@ public class NuspecAnalyzer extends AbstractFileTypeAnalyzer {
} }
/** /**
* Returns the key used in the properties file to reference the analyzer. * Returns the key used in the properties file to reference the analyzer's enabled property.
* *
* @return a short string used to look up configuration properties * @return the analyzer's enabled property setting key
*/ */
@Override @Override
protected String getAnalyzerSettingKey() { protected String getAnalyzerEnabledSettingKey() {
return "nexus"; return Settings.KEYS.ANALYZER_NUSPEC_ENABLED;
} }
/** /**

View File

@@ -54,7 +54,7 @@ public class AssemblyAnalyzerTest {
public void setUp() { public void setUp() {
try { try {
analyzer = new AssemblyAnalyzer(); analyzer = new AssemblyAnalyzer();
analyzer.setEnabled(true); analyzer.supportsExtension("dll");
analyzer.initialize(); analyzer.initialize();
} catch (Exception e) { } catch (Exception e) {
LOGGER.log(Level.WARNING, "Exception setting up AssemblyAnalyzer. Tests will be incomplete", e); LOGGER.log(Level.WARNING, "Exception setting up AssemblyAnalyzer. Tests will be incomplete", e);