From baa2e2c6ffec1c426c8563d0a29fbae40994a68f Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Sun, 15 Jan 2017 12:18:01 -0500 Subject: [PATCH] updated archetype for new analyzers to be more complete --- .../META-INF/maven/archetype-metadata.xml | 17 +++ .../{NewPlugin.java => __analyzerName__.java} | 14 +- ...rg.owasp.dependencycheck.analyzer.Analyzer | 2 +- .../src/test/java/__analyzerName__Test.java | 143 ++++++++++++++++++ .../src/test/resources/test.file | 0 5 files changed, 168 insertions(+), 8 deletions(-) rename dependency-check-plugin/src/main/resources/archetype-resources/src/main/java/{NewPlugin.java => __analyzerName__.java} (92%) create mode 100644 dependency-check-plugin/src/main/resources/archetype-resources/src/test/java/__analyzerName__Test.java create mode 100644 dependency-check-plugin/src/main/resources/archetype-resources/src/test/resources/test.file diff --git a/dependency-check-plugin/src/main/resources/META-INF/maven/archetype-metadata.xml b/dependency-check-plugin/src/main/resources/META-INF/maven/archetype-metadata.xml index 98bb87fac..99d1a98a2 100644 --- a/dependency-check-plugin/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/dependency-check-plugin/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -3,6 +3,11 @@ xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + + CustomAnalyzer + + src/main/java @@ -15,6 +20,18 @@ **/* + + + src/test/java + + **/*.java + + + + src/test/resources + + **/* + diff --git a/dependency-check-plugin/src/main/resources/archetype-resources/src/main/java/NewPlugin.java b/dependency-check-plugin/src/main/resources/archetype-resources/src/main/java/__analyzerName__.java similarity index 92% rename from dependency-check-plugin/src/main/resources/archetype-resources/src/main/java/NewPlugin.java rename to dependency-check-plugin/src/main/resources/archetype-resources/src/main/java/__analyzerName__.java index b5a034803..ec758c587 100644 --- a/dependency-check-plugin/src/main/resources/archetype-resources/src/main/java/NewPlugin.java +++ b/dependency-check-plugin/src/main/resources/archetype-resources/src/main/java/__analyzerName__.java @@ -28,12 +28,12 @@ import org.owasp.dependencycheck.exception.InitializationException; * An OWASP dependency-check plug-in example. If you are not implementing a * FileTypeAnalyzer, simple remove the annotation and the accept() method. */ -public class NewPlugin implements Analyzer, FileTypeAnalyzer { +public class ${analyzerName} implements Analyzer, FileTypeAnalyzer { /** - * The Logger for use throughout the NewPlugin. + * The Logger for use throughout the ${analyzerName}. */ - private static final Logger LOGGER = LoggerFactory.getLogger(NewPlugin.class); + private static final Logger LOGGER = LoggerFactory.getLogger(${analyzerName}.class); /** *

@@ -48,7 +48,7 @@ public class NewPlugin implements Analyzer, FileTypeAnalyzer { */ @Override public boolean accept(File pathname) { - throw new UnsupportedOperationException("Not implemented yet."); + return true; } /** @@ -77,7 +77,7 @@ public class NewPlugin implements Analyzer, FileTypeAnalyzer { */ @Override public String getName() { - return "New Plugin"; + return "${analyzerName}"; } /** @@ -115,8 +115,8 @@ public class NewPlugin implements Analyzer, FileTypeAnalyzer { /** * Returns whether multiple instances of the same type of analyzer can run - * in parallel. Note that running analyzers of different types in parallel - * is not supported at all. + * in parallel. If the analyzer does not support parallel processing it is + * generally best to also mark the analyze(Dependency,Engine) as synchronized. * * @return {@code true} if the analyzer supports parallel processing, * {@code false} else diff --git a/dependency-check-plugin/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org.owasp.dependencycheck.analyzer.Analyzer b/dependency-check-plugin/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org.owasp.dependencycheck.analyzer.Analyzer index 92854d72b..2c7364177 100644 --- a/dependency-check-plugin/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org.owasp.dependencycheck.analyzer.Analyzer +++ b/dependency-check-plugin/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org.owasp.dependencycheck.analyzer.Analyzer @@ -1 +1 @@ -${package}.NewPlugin \ No newline at end of file +${package}.${analyzerName} \ No newline at end of file diff --git a/dependency-check-plugin/src/main/resources/archetype-resources/src/test/java/__analyzerName__Test.java b/dependency-check-plugin/src/main/resources/archetype-resources/src/test/java/__analyzerName__Test.java new file mode 100644 index 000000000..a0247207f --- /dev/null +++ b/dependency-check-plugin/src/main/resources/archetype-resources/src/test/java/__analyzerName__Test.java @@ -0,0 +1,143 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package ${package}; + +import java.io.File; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; +import org.owasp.dependencycheck.Engine; +import org.owasp.dependencycheck.analyzer.AnalysisPhase; +import org.owasp.dependencycheck.dependency.Dependency; +import org.owasp.dependencycheck.utils.Settings; + +/** + * Test cases for ${analyzerName} + */ +public class ${analyzerName}Test { + + public ${analyzerName}Test() { + } + + @BeforeClass + public static void setUpClass() { + Settings.initialize(); + } + + @AfterClass + public static void tearDownClass() { + Settings.cleanup(); + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of accept method, of class ${analyzerName}. + */ + @Test + public void testAccept() { + File pathname = new File("test.file"); + ${analyzerName} instance = new ${analyzerName}(); + boolean expResult = true; + boolean result = instance.accept(pathname); + assertEquals(expResult, result); + } + + /** + * Test of analyze method, of class ${analyzerName}. + */ + @Test + public void testAnalyze() throws Exception { + ${analyzerName} instance = new ${analyzerName}(); + instance.initialize(); + File file = new File(${analyzerName}.class.getClassLoader().getResource("test.file").toURI().getPath()); + Dependency dependency = new Dependency(file); + //The engine is generally null for most analyzer test cases. + Engine engine = null; + + //TODO uncomment the following line and add assertions against the dependency. + //instance.analyze(dependency, engine); + } + + /** + * Test of getName method, of class ${analyzerName}. + */ + @Test + public void testGetName() { + ${analyzerName} instance = new ${analyzerName}(); + String expResult = "${analyzerName}"; + String result = instance.getName(); + assertEquals(expResult, result); + } + + /** + * Test of getAnalysisPhase method, of class ${analyzerName}. + */ + @Test + public void testGetAnalysisPhase() { + ${analyzerName} instance = new ${analyzerName}(); + AnalysisPhase expResult = AnalysisPhase.INFORMATION_COLLECTION; + AnalysisPhase result = instance.getAnalysisPhase(); + assertEquals(expResult, result); + } + + /** + * Test of initialize method, of class ${analyzerName}. + */ + @Test + public void testInitialize() throws Exception { + ${analyzerName} instance = new ${analyzerName}(); + instance.initialize(); + } + + /** + * Test of close method, of class ${analyzerName}. + */ + @Test + public void testClose() throws Exception { + ${analyzerName} instance = new ${analyzerName}(); + instance.close(); + } + + /** + * Test of supportsParallelProcessing method, of class ${analyzerName}. + */ + @Test + public void testSupportsParallelProcessing() { + ${analyzerName} instance = new ${analyzerName}(); + boolean expResult = true; + boolean result = instance.supportsParallelProcessing(); + assertEquals(expResult, result); + } + + /** + * Test of isEnabled method, of class ${analyzerName}. + */ + @Test + public void testIsEnabled() { + ${analyzerName} instance = new ${analyzerName}(); + boolean expResult = true; + boolean result = instance.isEnabled(); + assertEquals(expResult, result); + } +} diff --git a/dependency-check-plugin/src/main/resources/archetype-resources/src/test/resources/test.file b/dependency-check-plugin/src/main/resources/archetype-resources/src/test/resources/test.file new file mode 100644 index 000000000..e69de29bb