diff --git a/pmd-dist/src/test/java/net/sourceforge/pmd/it/AbstractBinaryDistributionTest.java b/pmd-dist/src/test/java/net/sourceforge/pmd/it/AbstractBinaryDistributionTest.java new file mode 100644 index 0000000000..692d40378a --- /dev/null +++ b/pmd-dist/src/test/java/net/sourceforge/pmd/it/AbstractBinaryDistributionTest.java @@ -0,0 +1,44 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.it; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.apache.commons.io.FileUtils; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +import net.sourceforge.pmd.PMDVersion; + +public abstract class AbstractBinaryDistributionTest { + + protected static File getBinaryDistribution() { + return new File(".", "target/pmd-bin-" + PMDVersion.VERSION + ".zip"); + } + + /** + * The temporary directory, to which the binary distribution will be extracted. + * It will be deleted again after the test. + */ + protected static Path tempDir; + + @BeforeClass + public static void setupTempDirectory() throws Exception { + tempDir = Files.createTempDirectory("pmd-it-test-"); + if (getBinaryDistribution().exists()) { + ZipFileExtractor.extractZipFile(getBinaryDistribution().toPath(), tempDir); + } + } + + @AfterClass + public static void cleanupTempDirectory() throws IOException { + if (tempDir != null && tempDir.toFile().exists()) { + FileUtils.forceDelete(tempDir.toFile()); + } + } +} diff --git a/pmd-dist/src/test/java/net/sourceforge/pmd/it/AllRulesIT.java b/pmd-dist/src/test/java/net/sourceforge/pmd/it/AllRulesIT.java new file mode 100644 index 0000000000..4819106502 --- /dev/null +++ b/pmd-dist/src/test/java/net/sourceforge/pmd/it/AllRulesIT.java @@ -0,0 +1,46 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.it; + +import java.io.File; +import java.util.Arrays; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +public class AllRulesIT extends AbstractBinaryDistributionTest { + + @Parameter + public String language; + + @Parameters + public static Iterable languagesToTest() { + // note: scala and wsdl have no rules + return Arrays.asList("java", "apex", "javascript", "jsp", "plsql", "pom", "visualforce", "velocitytemplate", "xml", "xsl"); + } + + @Test + public void runRuleTests() throws Exception { + String srcDir = new File(".", "src/test/resources/sample-source/" + language + "/").getAbsolutePath(); + + ExecutionResult result = PMDExecutor.runPMDRules(tempDir, srcDir, "src/test/resources/rulesets/all-" + + language + ".xml"); + assertDefaultExecutionResult(result); + } + + private static void assertDefaultExecutionResult(ExecutionResult result) { + result.assertExecutionResult(4, ""); + + result.assertNoError("Exception applying rule"); + result.assertNoError("Ruleset not found"); + result.assertNoError("Use of deprecated attribute"); + result.assertNoErrorInReport("Error while processing"); + result.assertNoErrorInReport("Error while parsing"); + } +} diff --git a/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java b/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java index 7eb1a92497..074bc85c81 100644 --- a/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java +++ b/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java @@ -9,47 +9,17 @@ import static org.junit.Assert.fail; import java.io.File; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.Enumeration; import java.util.HashSet; import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; -import org.apache.commons.io.FileUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.Test; import net.sourceforge.pmd.PMDVersion; -public class BinaryDistributionIT { - - private static File getBinaryDistribution() { - return new File(".", "target/pmd-bin-" + PMDVersion.VERSION + ".zip"); - } - - /** - * The temporary directory, to which the binary distribution will be extracted. - * It will be deleted again after the test. - */ - private static Path tempDir; - - @BeforeClass - public static void setupTempDirectory() throws Exception { - tempDir = Files.createTempDirectory("pmd-it-test-"); - if (getBinaryDistribution().exists()) { - ZipFileExtractor.extractZipFile(getBinaryDistribution().toPath(), tempDir); - } - } - - @AfterClass - public static void cleanupTempDirectory() throws IOException { - if (tempDir != null && tempDir.toFile().exists()) { - FileUtils.forceDelete(tempDir.toFile()); - } - } +public class BinaryDistributionIT extends AbstractBinaryDistributionTest { @Test public void testFileExistence() { @@ -104,32 +74,6 @@ public class BinaryDistributionIT { result.assertExecutionResult(4, ""); } - @Test - public void testAllJavaRules() throws Exception { - String srcDir = new File(".", "src/test/resources/sample-source/java/").getAbsolutePath(); - - ExecutionResult result = PMDExecutor.runPMDRules(tempDir, srcDir, "src/test/resources/rulesets/all-java.xml"); - assertDefaultExecutionResult(result); - } - - @Test - public void testAllApexRules() throws Exception { - String srcDir = new File(".", "src/test/resources/sample-source/apex/").getAbsolutePath(); - - ExecutionResult result = PMDExecutor.runPMDRules(tempDir, srcDir, "src/test/resources/rulesets/all-apex.xml"); - assertDefaultExecutionResult(result); - } - - private static void assertDefaultExecutionResult(ExecutionResult result) { - result.assertExecutionResult(4, ""); - - result.assertNoError("Exception applying rule"); - result.assertNoError("Ruleset not found"); - result.assertNoError("Use of deprecated attribute"); - result.assertNoErrorInReport("Error while processing"); - result.assertNoErrorInReport("Error while parsing"); - } - @Test public void runCPD() throws Exception { String srcDir = new File(".", "src/test/resources/sample-source-cpd/").getAbsolutePath(); diff --git a/pmd-dist/src/test/resources/rulesets/all-javascript.xml b/pmd-dist/src/test/resources/rulesets/all-javascript.xml new file mode 100644 index 0000000000..db9e425e76 --- /dev/null +++ b/pmd-dist/src/test/resources/rulesets/all-javascript.xml @@ -0,0 +1,18 @@ + + + + Every JavaScript Rule in PMD + + + + + + + + + + + diff --git a/pmd-dist/src/test/resources/rulesets/all-jsp.xml b/pmd-dist/src/test/resources/rulesets/all-jsp.xml new file mode 100644 index 0000000000..9b48bd0577 --- /dev/null +++ b/pmd-dist/src/test/resources/rulesets/all-jsp.xml @@ -0,0 +1,18 @@ + + + + Every JSP Rule in PMD + + + + + + + + + + + diff --git a/pmd-dist/src/test/resources/rulesets/all-plsql.xml b/pmd-dist/src/test/resources/rulesets/all-plsql.xml new file mode 100644 index 0000000000..ba43c139be --- /dev/null +++ b/pmd-dist/src/test/resources/rulesets/all-plsql.xml @@ -0,0 +1,18 @@ + + + + Every PLSQL Rule in PMD + + + + + + + + + + + diff --git a/pmd-dist/src/test/resources/rulesets/all-pom.xml b/pmd-dist/src/test/resources/rulesets/all-pom.xml new file mode 100644 index 0000000000..fe65645d55 --- /dev/null +++ b/pmd-dist/src/test/resources/rulesets/all-pom.xml @@ -0,0 +1,18 @@ + + + + Every Maven POM Rule in PMD + + + + + + + + + + + diff --git a/pmd-dist/src/test/resources/rulesets/all-velocitytemplate.xml b/pmd-dist/src/test/resources/rulesets/all-velocitytemplate.xml new file mode 100644 index 0000000000..7918dde8b7 --- /dev/null +++ b/pmd-dist/src/test/resources/rulesets/all-velocitytemplate.xml @@ -0,0 +1,18 @@ + + + + Every Velocity Template Language Rule in PMD + + + + + + + + + + + diff --git a/pmd-dist/src/test/resources/rulesets/all-visualforce.xml b/pmd-dist/src/test/resources/rulesets/all-visualforce.xml new file mode 100644 index 0000000000..ff68553962 --- /dev/null +++ b/pmd-dist/src/test/resources/rulesets/all-visualforce.xml @@ -0,0 +1,18 @@ + + + + Every Visualforce Rule in PMD + + + + + + + + + + + diff --git a/pmd-dist/src/test/resources/rulesets/all-xml.xml b/pmd-dist/src/test/resources/rulesets/all-xml.xml new file mode 100644 index 0000000000..6b230c138e --- /dev/null +++ b/pmd-dist/src/test/resources/rulesets/all-xml.xml @@ -0,0 +1,18 @@ + + + + Every XML Rule in PMD + + + + + + + + + + + diff --git a/pmd-dist/src/test/resources/rulesets/all-xsl.xml b/pmd-dist/src/test/resources/rulesets/all-xsl.xml new file mode 100644 index 0000000000..ced819fdce --- /dev/null +++ b/pmd-dist/src/test/resources/rulesets/all-xsl.xml @@ -0,0 +1,18 @@ + + + + Every XSL Rule in PMD + + + + + + + + + + + diff --git a/pmd-dist/src/test/resources/sample-source/javascript/SampleCode.js b/pmd-dist/src/test/resources/sample-source/javascript/SampleCode.js new file mode 100644 index 0000000000..fc36006b11 --- /dev/null +++ b/pmd-dist/src/test/resources/sample-source/javascript/SampleCode.js @@ -0,0 +1,7 @@ +(function() { + if (true) { + x=2; + } else { + x=4; + } +})(); diff --git a/pmd-dist/src/test/resources/sample-source/jsp/SampleCode.jsp b/pmd-dist/src/test/resources/sample-source/jsp/SampleCode.jsp new file mode 100644 index 0000000000..1a1c2508ce --- /dev/null +++ b/pmd-dist/src/test/resources/sample-source/jsp/SampleCode.jsp @@ -0,0 +1,12 @@ +<%@ page errorPage="error.jsp" %> +<%@ page import="com.foo.AClass"%> +<%@ page import="com.foo.MyClass"%> + + + + + xx + text + + + diff --git a/pmd-dist/src/test/resources/sample-source/plsql/SampleCode.pls b/pmd-dist/src/test/resources/sample-source/plsql/SampleCode.pls new file mode 100644 index 0000000000..137703c569 --- /dev/null +++ b/pmd-dist/src/test/resources/sample-source/plsql/SampleCode.pls @@ -0,0 +1,14 @@ +-- +-- Example 2-25 Assigning Value to Variable with SELECT INTO Statement +-- From: https://docs.oracle.com/en/database/oracle/oracle-database/18/lnpls/plsql-language-fundamentals.html#GUID-664BFFEA-063A-48B6-A65B-95225EDDED59 +-- +DECLARE + bonus NUMBER(8,2); +BEGIN + SELECT salary * 0.10 INTO bonus + FROM employees + WHERE employee_id = 100; +END; + +DBMS_OUTPUT.PUT_LINE('bonus = ' || TO_CHAR(bonus)); +/ \ No newline at end of file diff --git a/pmd-dist/src/test/resources/sample-source/pom/pom.xml.pom b/pmd-dist/src/test/resources/sample-source/pom/pom.xml.pom new file mode 100644 index 0000000000..291a0ad3e8 --- /dev/null +++ b/pmd-dist/src/test/resources/sample-source/pom/pom.xml.pom @@ -0,0 +1,17 @@ + + 4.0.0 + net.sourceforge.pmd + xml-pom + 1.0.0-SNAPSHOT + + + + org.jboss.arquillian + arquillian-bom + ${arquillian.version} + bom + import + + + + diff --git a/pmd-dist/src/test/resources/sample-source/velocitytemplate/helloworld.vm b/pmd-dist/src/test/resources/sample-source/velocitytemplate/helloworld.vm new file mode 100644 index 0000000000..e632d74a8d --- /dev/null +++ b/pmd-dist/src/test/resources/sample-source/velocitytemplate/helloworld.vm @@ -0,0 +1,8 @@ + + + #set( $foo = "Velocity" ) + Hello $foo World! + + + + diff --git a/pmd-dist/src/test/resources/sample-source/visualforce/SampleCode.page b/pmd-dist/src/test/resources/sample-source/visualforce/SampleCode.page new file mode 100644 index 0000000000..4bb5f988c9 --- /dev/null +++ b/pmd-dist/src/test/resources/sample-source/visualforce/SampleCode.page @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/pmd-dist/src/test/resources/sample-source/xml/samplecode.xml b/pmd-dist/src/test/resources/sample-source/xml/samplecode.xml new file mode 100644 index 0000000000..7db6211863 --- /dev/null +++ b/pmd-dist/src/test/resources/sample-source/xml/samplecode.xml @@ -0,0 +1,35 @@ + + + app + + + Application_Module_Web_ContextRoot + ikb.adf.kreda.abw.webapp-Abnahmetest-ohne-SSO + + + + ikb.adf.kreda.abw.ear + ear + + application + META-INF/application.xml + + Application_Module_Web_ContextRoot + /application/module/web/[context-root="ikb.adf.kreda.abw.webapp-Local-ohne-SSO"] + replace + + + + + + + + + + + diff --git a/pmd-dist/src/test/resources/sample-source/xsl/samplecode.xslt b/pmd-dist/src/test/resources/sample-source/xsl/samplecode.xslt new file mode 100644 index 0000000000..b4e1e7db8e --- /dev/null +++ b/pmd-dist/src/test/resources/sample-source/xsl/samplecode.xslt @@ -0,0 +1,4 @@ + + +