checkstyle updates

This commit is contained in:
Jeremy Long
2017-07-22 18:20:11 -04:00
parent db2a0abcb6
commit 176363492e
9 changed files with 61 additions and 35 deletions

View File

@@ -62,39 +62,53 @@ public class Engine implements FileFilter, AutoCloseable {
*/
public enum Mode {
/**
* In evidence collection mode the {@link Engine} only collects evidence from the scan targets,
* and doesn't require a database.
* In evidence collection mode the {@link Engine} only collects evidence
* from the scan targets, and doesn't require a database.
*/
EVIDENCE_COLLECTION(
false,
INITIAL,
PRE_INFORMATION_COLLECTION,
INFORMATION_COLLECTION,
POST_INFORMATION_COLLECTION
false,
INITIAL,
PRE_INFORMATION_COLLECTION,
INFORMATION_COLLECTION,
POST_INFORMATION_COLLECTION
),
/**
* In evidence processing mode the {@link Engine} processes the evidence collected using the
* {@link #EVIDENCE_COLLECTION} mode. Dependencies should be injected into the {@link Engine}
* using {@link Engine#setDependencies(List)}.
* In evidence processing mode the {@link Engine} processes the evidence
* collected using the {@link #EVIDENCE_COLLECTION} mode. Dependencies
* should be injected into the {@link Engine} using
* {@link Engine#setDependencies(List)}.
*/
EVIDENCE_PROCESSING(
true,
PRE_IDENTIFIER_ANALYSIS,
IDENTIFIER_ANALYSIS,
POST_IDENTIFIER_ANALYSIS,
PRE_FINDING_ANALYSIS,
FINDING_ANALYSIS,
POST_FINDING_ANALYSIS,
FINAL
true,
PRE_IDENTIFIER_ANALYSIS,
IDENTIFIER_ANALYSIS,
POST_IDENTIFIER_ANALYSIS,
PRE_FINDING_ANALYSIS,
FINDING_ANALYSIS,
POST_FINDING_ANALYSIS,
FINAL
),
/**
* In standalone mode the {@link Engine} will collect and process evidence in a single execution.
* In standalone mode the {@link Engine} will collect and process
* evidence in a single execution.
*/
STANDALONE(true, AnalysisPhase.values());
/**
* Whether the database is required in this mode.
*/
public final boolean requiresDatabase;
/**
* The analysis phases included in the mode.
*/
public final AnalysisPhase[] phases;
/**
* Constructs a new mode.
*
* @param requiresDatabase if the database is required for the mode
* @param phases the analysis phases to include in the mode
*/
Mode(boolean requiresDatabase, AnalysisPhase... phases) {
this.requiresDatabase = requiresDatabase;
this.phases = phases;
@@ -116,7 +130,8 @@ public class Engine implements FileFilter, AutoCloseable {
private final Set<FileTypeAnalyzer> fileTypeAnalyzers = new HashSet<>();
/**
* The engine execution mode indicating it will either collect evidence or process evidence or both.
* The engine execution mode indicating it will either collect evidence or
* process evidence or both.
*/
private final Mode mode;
@@ -143,9 +158,11 @@ public class Engine implements FileFilter, AutoCloseable {
/**
* Creates a new Engine.
*
* @param mode the mode of operation
*/
public Engine(Mode mode) {
this(Thread.currentThread().getContextClassLoader(), mode);
this(Thread.currentThread().getContextClassLoader(), mode);
}
/**

View File

@@ -32,6 +32,7 @@ import static java.util.Arrays.asList;
* @author Jeremy Long
*/
public class AnalyzerService {
/**
* The Logger for use throughout the class.
*/
@@ -45,7 +46,8 @@ public class AnalyzerService {
/**
* Creates a new instance of AnalyzerService.
*
* @param classLoader the ClassLoader to use when dynamically loading Analyzer and Update services
* @param classLoader the ClassLoader to use when dynamically loading
* Analyzer and Update services
*/
public AnalyzerService(ClassLoader classLoader) {
service = ServiceLoader.load(Analyzer.class, classLoader);
@@ -61,8 +63,10 @@ public class AnalyzerService {
}
/**
* Returns a list of all instances of the Analyzer interface that are bound to one of the given phases.
* Returns a list of all instances of the Analyzer interface that are bound
* to one of the given phases.
*
* @param phases the phases to obtain analyzers for
* @return a list of Analyzers.
*/
public List<Analyzer> getAnalyzers(AnalysisPhase... phases) {
@@ -70,9 +74,11 @@ public class AnalyzerService {
}
/**
* Returns a list of all instances of the Analyzer interface that are bound to one of the given phases.
* Returns a list of all instances of the Analyzer interface that are bound
* to one of the given phases.
*
* @return a list of Analyzers.
* @param phases the phases to obtain analyzers for
* @return a list of Analyzers
*/
private List<Analyzer> getAnalyzers(List<AnalysisPhase> phases) {
final List<Analyzer> analyzers = new ArrayList<>();

View File

@@ -114,7 +114,7 @@ public class AssemblyAnalyzer extends AbstractFileTypeAnalyzer {
public void analyzeDependency(Dependency dependency, Engine engine)
throws AnalysisException {
File test = new File(dependency.getActualFilePath());
final File test = new File(dependency.getActualFilePath());
if (!test.isFile()) {
throw new AnalysisException(String.format("%s does not exist and cannot be analyzed by dependency-check",
dependency.getActualFilePath()));

View File

@@ -150,7 +150,7 @@ public class NspAnalyzer extends AbstractFileTypeAnalyzer {
try (JsonReader jsonReader = Json.createReader(FileUtils.openInputStream(file))) {
// Do not scan the node_modules directory
if (file.getCanonicalPath().contains(File.separator + "node_modules" + File.separator )) {
if (file.getCanonicalPath().contains(File.separator + "node_modules" + File.separator)) {
LOGGER.debug("Skipping analysis of node module: " + file.getCanonicalPath());
return;
}

View File

@@ -128,7 +128,7 @@ public class RubyBundleAuditAnalyzer extends AbstractFileTypeAnalyzer {
final ProcessBuilder builder = new ProcessBuilder(args);
builder.directory(folder);
try {
LOGGER.info("Launching: {} from {}",args, folder);
LOGGER.info("Launching: {} from {}", args, folder);
return builder.start();
} catch (IOException ioe) {
throw new AnalysisException("bundle-audit initialization failure; this error can be ignored if you are not analyzing Ruby. "
@@ -204,7 +204,7 @@ public class RubyBundleAuditAnalyzer extends AbstractFileTypeAnalyzer {
if (isEnabled()) {
LOGGER.info("{} is enabled. It is necessary to manually run \"bundle-audit update\" "
+ "occasionally to keep its database up to date.",ANALYZER_NAME);
+ "occasionally to keep its database up to date.", ANALYZER_NAME);
}
}
@@ -273,15 +273,15 @@ public class RubyBundleAuditAnalyzer extends AbstractFileTypeAnalyzer {
for (FileTypeAnalyzer analyzer : engine.getFileTypeAnalyzers()) {
if (analyzer instanceof RubyBundlerAnalyzer) {
((RubyBundlerAnalyzer) analyzer).setEnabled(false);
LOGGER.info("Disabled {} to avoid noisy duplicate results.",RubyBundlerAnalyzer.class.getName());
LOGGER.info("Disabled {} to avoid noisy duplicate results.", RubyBundlerAnalyzer.class.getName());
} else if (analyzer instanceof RubyGemspecAnalyzer) {
((RubyGemspecAnalyzer) analyzer).setEnabled(false);
LOGGER.info("Disabled {} to avoid noisy duplicate results.",className);
LOGGER.info("Disabled {} to avoid noisy duplicate results.", className);
failed = false;
}
}
if (failed) {
LOGGER.warn("Did not find {}.",className);
LOGGER.warn("Did not find {}.", className);
}
needToDisableGemspecAnalyzer = false;
}

View File

@@ -300,6 +300,9 @@ public final class CveDB implements AutoCloseable {
}
}
/**
* Releases the resources used by CveDB.
*/
private synchronized void releaseResources() {
instance.statementBundle = null;
instance.preparedStatements.clear();

View File

@@ -172,7 +172,7 @@ public class NvdCveUpdater implements CachedWebDataSource {
throw new UpdateException("Database Exception", ex);
} finally {
shutdownExecutorServices();
if(cveDb != null) {
if (cveDb != null) {
cveDb.close();
}
if (lock != null) {

View File

@@ -261,7 +261,7 @@ public class EvidenceCollection implements Serializable, Iterable<Evidence> {
for (Evidence e : EvidenceCollection.EVIDENCE_USED.filter(this)) {
//TODO consider changing the regex to only compare alpha-numeric (i.e. strip everything else)
String item = e.getValue();
final String item = e.getValue();
if (item != null) {
final String uc = urlCorrection(item.toLowerCase());
if (uc != null) {

View File

@@ -174,7 +174,7 @@ public final class Downloader {
} else {
reader = conn.getInputStream();
}
final byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = reader.read(buffer)) > 0) {