checkstyle corrections, minor restructuring, etc.

This commit is contained in:
Jeremy Long
2017-05-07 18:40:25 -04:00
parent 06d6fe4bd6
commit 8fc42078c7
4 changed files with 42 additions and 27 deletions

View File

@@ -24,8 +24,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* An extremely simple wrapper around various escape utils to perform URL and HTML encoding within the reports. This class was * An extremely simple wrapper around various escape utils to perform URL and
* created to simplify the velocity configuration and avoid using the "built-in" escape tool. * HTML encoding within the reports. This class was created to simplify the
* velocity configuration and avoid using the "built-in" escape tool.
* *
* @author Jeremy Long * @author Jeremy Long
*/ */
@@ -82,7 +83,8 @@ public class EscapeTool {
} }
/** /**
* JSON Encodes the provded text * JSON Encodes the provided text.
*
* @param text the text to encode * @param text the text to encode
* @return the JSON encoded text * @return the JSON encoded text
*/ */

View File

@@ -132,18 +132,19 @@ public class ReportGenerator {
* Constructs a new ReportGenerator. * Constructs a new ReportGenerator.
* *
* @param applicationName the application name being analyzed * @param applicationName the application name being analyzed
* @param applicationVersion the application version being analyzed * @param groupID the group id of the project being analyzed
* @param artifactID the application version being analyzed * @param artifactID the application id of the project being analyzed
* @param applicationVersion the application version being analyzed * @param version the application version of the project being analyzed
* @param dependencies the list of dependencies * @param dependencies the list of dependencies
* @param analyzers the list of analyzers used * @param analyzers the list of analyzers used
* @param properties the database properties (containing timestamps of the * @param properties the database properties (containing timestamps of the
* NVD CVE data) * NVD CVE data)
*/ */
public ReportGenerator(String applicationName, String applicationVersion, String artifactID, String groupID, List<Dependency> dependencies, List<Analyzer> analyzers, DatabaseProperties properties) { public ReportGenerator(String applicationName, String groupID, String artifactID, String version,
List<Dependency> dependencies, List<Analyzer> analyzers, DatabaseProperties properties) {
this(applicationName, dependencies, analyzers, properties); this(applicationName, dependencies, analyzers, properties);
context.put("applicationVersion", applicationVersion); context.put("applicationVersion", version);
context.put("artifactID", artifactID); context.put("artifactID", artifactID);
context.put("groupID", groupID); context.put("groupID", groupID);
} }
@@ -216,6 +217,12 @@ public class ReportGenerator {
} }
} }
/**
* Reformats the given JSON file.
*
* @param pathToJson the path to the JSON file to be reformatted
* @throws JsonSyntaxException thrown if the given JSON file is malformed
*/
private void pretifyJson(String pathToJson) throws JsonSyntaxException { private void pretifyJson(String pathToJson) throws JsonSyntaxException {
final String outputPath = pathToJson + ".pretty"; final String outputPath = pathToJson + ".pretty";
final File in = new File(pathToJson); final File in = new File(pathToJson);
@@ -248,7 +255,7 @@ public class ReportGenerator {
private static void prettyPrint(JsonReader reader, JsonWriter writer) throws IOException { private static void prettyPrint(JsonReader reader, JsonWriter writer) throws IOException {
writer.setIndent(" "); writer.setIndent(" ");
while (true) { while (true) {
JsonToken token = reader.peek(); final JsonToken token = reader.peek();
switch (token) { switch (token) {
case BEGIN_ARRAY: case BEGIN_ARRAY:
reader.beginArray(); reader.beginArray();
@@ -267,19 +274,19 @@ public class ReportGenerator {
writer.endObject(); writer.endObject();
break; break;
case NAME: case NAME:
String name = reader.nextName(); final String name = reader.nextName();
writer.name(name); writer.name(name);
break; break;
case STRING: case STRING:
String s = reader.nextString(); final String s = reader.nextString();
writer.value(s); writer.value(s);
break; break;
case NUMBER: case NUMBER:
String n = reader.nextString(); final String n = reader.nextString();
writer.value(new BigDecimal(n)); writer.value(new BigDecimal(n));
break; break;
case BOOLEAN: case BOOLEAN:
boolean b = reader.nextBoolean(); final boolean b = reader.nextBoolean();
writer.value(b); writer.value(b);
break; break;
case NULL: case NULL:
@@ -288,6 +295,9 @@ public class ReportGenerator {
break; break;
case END_DOCUMENT: case END_DOCUMENT:
return; return;
default:
LOGGER.debug("Unexpected JSON toekn {}", token.toString());
break;
} }
} }
} }

View File

@@ -109,8 +109,8 @@ public class ReportGeneratorIT extends BaseDBTestCase {
} }
/** /**
* Generates an XML report containing known vulnerabilities and realistic data and validates the generated XML document * Generates an XML report containing known vulnerabilities and realistic
* against the XSD. * data and validates the generated XML document against the XSD.
* *
* @throws Exception * @throws Exception
*/ */
@@ -148,7 +148,8 @@ public class ReportGeneratorIT extends BaseDBTestCase {
CveDB cveDB = CveDB.getInstance(); CveDB cveDB = CveDB.getInstance();
DatabaseProperties dbProp = cveDB.getDatabaseProperties(); DatabaseProperties dbProp = cveDB.getDatabaseProperties();
ReportGenerator generator = new ReportGenerator("Test Report","1.4.7","dependency-check-core","org.owasp", engine.getDependencies(), engine.getAnalyzers(), dbProp); ReportGenerator generator = new ReportGenerator("Test Report", "org.owasp", "dependency-check-core", "1.4.7",
engine.getDependencies(), engine.getAnalyzers(), dbProp);
generator.generateReport(templateName, writeTo); generator.generateReport(templateName, writeTo);
cveDB.close(); cveDB.close();

View File

@@ -117,7 +117,7 @@ public abstract class BaseDependencyCheckMojo extends AbstractMojo implements Ma
* The Maven Session. * The Maven Session.
*/ */
@Parameter(defaultValue = "${session}", readonly = true, required = true) @Parameter(defaultValue = "${session}", readonly = true, required = true)
protected MavenSession session; private MavenSession session;
/** /**
* Remote repositories which will be searched for artifacts. * Remote repositories which will be searched for artifacts.
@@ -627,7 +627,8 @@ public abstract class BaseDependencyCheckMojo extends AbstractMojo implements Ma
* @return a collection of exceptions that may have occurred while resolving * @return a collection of exceptions that may have occurred while resolving
* and scanning the dependencies * and scanning the dependencies
*/ */
private ExceptionCollection collectDependencies(Engine engine, MavenProject project, List<DependencyNode> nodes, ProjectBuildingRequest buildingRequest) { private ExceptionCollection collectDependencies(Engine engine, MavenProject project,
List<DependencyNode> nodes, ProjectBuildingRequest buildingRequest) {
ExceptionCollection exCol = null; ExceptionCollection exCol = null;
for (DependencyNode dependencyNode : nodes) { for (DependencyNode dependencyNode : nodes) {
exCol = collectDependencies(engine, project, dependencyNode.getChildren(), buildingRequest); exCol = collectDependencies(engine, project, dependencyNode.getChildren(), buildingRequest);
@@ -1015,7 +1016,8 @@ public abstract class BaseDependencyCheckMojo extends AbstractMojo implements Ma
getLog().debug("Unable to retrieve DB Properties", ex); getLog().debug("Unable to retrieve DB Properties", ex);
} }
} }
final ReportGenerator r = new ReportGenerator(p.getName(),p.getVersion(),p.getArtifactId(),p.getGroupId(), engine.getDependencies(), engine.getAnalyzers(), prop); final ReportGenerator r = new ReportGenerator(p.getName(), p.getGroupId(), p.getArtifactId(), p.getVersion(),
engine.getDependencies(), engine.getAnalyzers(), prop);
try { try {
r.generateReports(outputDir.getAbsolutePath(), format); r.generateReports(outputDir.getAbsolutePath(), format);
} catch (ReportException ex) { } catch (ReportException ex) {