mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-01-14 07:43:40 +01:00
updated archetype for new analyzers to be more complete
This commit is contained in:
@@ -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">
|
||||
<requiredProperties>
|
||||
<requiredProperty key="analyzerName">
|
||||
<defaultValue>CustomAnalyzer</defaultValue>
|
||||
</requiredProperty>
|
||||
</requiredProperties>
|
||||
<fileSets>
|
||||
<fileSet filtered="true" packaged="true" encoding="UTF-8">
|
||||
<directory>src/main/java</directory>
|
||||
@@ -15,6 +20,18 @@
|
||||
<includes>
|
||||
<include>**/*</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet filtered="true" packaged="true" encoding="UTF-8">
|
||||
<directory>src/test/java</directory>
|
||||
<includes>
|
||||
<include>**/*.java</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet filtered="true" encoding="UTF-8">
|
||||
<directory>src/test/resources</directory>
|
||||
<includes>
|
||||
<include>**/*</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</archetype-descriptor>
|
||||
|
||||
@@ -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);
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -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
|
||||
@@ -1 +1 @@
|
||||
${package}.NewPlugin
|
||||
${package}.${analyzerName}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user