Add rule integration tests for all other supported languages
This commit is contained in:
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
@ -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<String> 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");
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
18
pmd-dist/src/test/resources/rulesets/all-javascript.xml
Normal file
18
pmd-dist/src/test/resources/rulesets/all-javascript.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="All JavaScript Rules"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||
<description>Every JavaScript Rule in PMD</description>
|
||||
|
||||
<rule ref="category/ecmascript/bestpractices.xml" />
|
||||
<rule ref="category/ecmascript/codestyle.xml" />
|
||||
<rule ref="category/ecmascript/design.xml" />
|
||||
<rule ref="category/ecmascript/documentation.xml" />
|
||||
<rule ref="category/ecmascript/errorprone.xml" />
|
||||
<rule ref="category/ecmascript/multithreading.xml" />
|
||||
<rule ref="category/ecmascript/performance.xml" />
|
||||
<rule ref="category/ecmascript/security.xml" />
|
||||
|
||||
</ruleset>
|
18
pmd-dist/src/test/resources/rulesets/all-jsp.xml
Normal file
18
pmd-dist/src/test/resources/rulesets/all-jsp.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="All JSP Rules"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||
<description>Every JSP Rule in PMD</description>
|
||||
|
||||
<rule ref="category/jsp/bestpractices.xml" />
|
||||
<rule ref="category/jsp/codestyle.xml" />
|
||||
<rule ref="category/jsp/design.xml" />
|
||||
<rule ref="category/jsp/documentation.xml" />
|
||||
<rule ref="category/jsp/errorprone.xml" />
|
||||
<rule ref="category/jsp/multithreading.xml" />
|
||||
<rule ref="category/jsp/performance.xml" />
|
||||
<rule ref="category/jsp/security.xml" />
|
||||
|
||||
</ruleset>
|
18
pmd-dist/src/test/resources/rulesets/all-plsql.xml
Normal file
18
pmd-dist/src/test/resources/rulesets/all-plsql.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="All PLSQL Rules"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||
<description>Every PLSQL Rule in PMD</description>
|
||||
|
||||
<rule ref="category/plsql/bestpractices.xml" />
|
||||
<rule ref="category/plsql/codestyle.xml" />
|
||||
<rule ref="category/plsql/design.xml" />
|
||||
<rule ref="category/plsql/documentation.xml" />
|
||||
<rule ref="category/plsql/errorprone.xml" />
|
||||
<rule ref="category/plsql/multithreading.xml" />
|
||||
<rule ref="category/plsql/performance.xml" />
|
||||
<rule ref="category/plsql/security.xml" />
|
||||
|
||||
</ruleset>
|
18
pmd-dist/src/test/resources/rulesets/all-pom.xml
Normal file
18
pmd-dist/src/test/resources/rulesets/all-pom.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="All Maven POM Rules"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||
<description>Every Maven POM Rule in PMD</description>
|
||||
|
||||
<rule ref="category/pom/bestpractices.xml" />
|
||||
<rule ref="category/pom/codestyle.xml" />
|
||||
<rule ref="category/pom/design.xml" />
|
||||
<rule ref="category/pom/documentation.xml" />
|
||||
<rule ref="category/pom/errorprone.xml" />
|
||||
<rule ref="category/pom/multithreading.xml" />
|
||||
<rule ref="category/pom/performance.xml" />
|
||||
<rule ref="category/pom/security.xml" />
|
||||
|
||||
</ruleset>
|
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="All Velocity Template Language Rules"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||
<description>Every Velocity Template Language Rule in PMD</description>
|
||||
|
||||
<rule ref="category/vm/bestpractices.xml" />
|
||||
<rule ref="category/vm/codestyle.xml" />
|
||||
<rule ref="category/vm/design.xml" />
|
||||
<rule ref="category/vm/documentation.xml" />
|
||||
<rule ref="category/vm/errorprone.xml" />
|
||||
<rule ref="category/vm/multithreading.xml" />
|
||||
<rule ref="category/vm/performance.xml" />
|
||||
<rule ref="category/vm/security.xml" />
|
||||
|
||||
</ruleset>
|
18
pmd-dist/src/test/resources/rulesets/all-visualforce.xml
Normal file
18
pmd-dist/src/test/resources/rulesets/all-visualforce.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="All Visualforce Rules"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||
<description>Every Visualforce Rule in PMD</description>
|
||||
|
||||
<rule ref="category/vf/bestpractices.xml" />
|
||||
<rule ref="category/vf/codestyle.xml" />
|
||||
<rule ref="category/vf/design.xml" />
|
||||
<rule ref="category/vf/documentation.xml" />
|
||||
<rule ref="category/vf/errorprone.xml" />
|
||||
<rule ref="category/vf/multithreading.xml" />
|
||||
<rule ref="category/vf/performance.xml" />
|
||||
<rule ref="category/vf/security.xml" />
|
||||
|
||||
</ruleset>
|
18
pmd-dist/src/test/resources/rulesets/all-xml.xml
Normal file
18
pmd-dist/src/test/resources/rulesets/all-xml.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="All XML Rules"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||
<description>Every XML Rule in PMD</description>
|
||||
|
||||
<rule ref="category/xml/bestpractices.xml" />
|
||||
<rule ref="category/xml/codestyle.xml" />
|
||||
<rule ref="category/xml/design.xml" />
|
||||
<rule ref="category/xml/documentation.xml" />
|
||||
<rule ref="category/xml/errorprone.xml" />
|
||||
<rule ref="category/xml/multithreading.xml" />
|
||||
<rule ref="category/xml/performance.xml" />
|
||||
<rule ref="category/xml/security.xml" />
|
||||
|
||||
</ruleset>
|
18
pmd-dist/src/test/resources/rulesets/all-xsl.xml
Normal file
18
pmd-dist/src/test/resources/rulesets/all-xsl.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xsl version="1.0"?>
|
||||
|
||||
<ruleset name="All XSL Rules"
|
||||
xslns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xslns:xsi="http://www.w3.org/2001/xslSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||
<description>Every XSL Rule in PMD</description>
|
||||
|
||||
<rule ref="category/xsl/bestpractices.xml" />
|
||||
<rule ref="category/xsl/codestyle.xml" />
|
||||
<rule ref="category/xsl/design.xml" />
|
||||
<rule ref="category/xsl/documentation.xml" />
|
||||
<rule ref="category/xsl/errorprone.xml" />
|
||||
<rule ref="category/xsl/multithreading.xml" />
|
||||
<rule ref="category/xsl/performance.xml" />
|
||||
<rule ref="category/xsl/security.xml" />
|
||||
|
||||
</ruleset>
|
@ -0,0 +1,7 @@
|
||||
(function() {
|
||||
if (true) {
|
||||
x=2;
|
||||
} else {
|
||||
x=4;
|
||||
}
|
||||
})();
|
12
pmd-dist/src/test/resources/sample-source/jsp/SampleCode.jsp
Normal file
12
pmd-dist/src/test/resources/sample-source/jsp/SampleCode.jsp
Normal file
@ -0,0 +1,12 @@
|
||||
<%@ page errorPage="error.jsp" %>
|
||||
<%@ page import="com.foo.AClass"%>
|
||||
<%@ page import="com.foo.MyClass"%>
|
||||
|
||||
<html>
|
||||
<body>
|
||||
<b>
|
||||
<img src="<%=Some.get()%>/foo">xx</img>
|
||||
text
|
||||
</b>
|
||||
</body>
|
||||
</html>
|
@ -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));
|
||||
/
|
17
pmd-dist/src/test/resources/sample-source/pom/pom.xml.pom
Normal file
17
pmd-dist/src/test/resources/sample-source/pom/pom.xml.pom
Normal file
@ -0,0 +1,17 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>xml-pom</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependency>
|
||||
<groupId>org.jboss.arquillian</groupId>
|
||||
<artifactId>arquillian-bom</artifactId>
|
||||
<version>${arquillian.version}</version>
|
||||
<type>bom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencyManagement>
|
||||
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<body>
|
||||
#set( $foo = "Velocity" )
|
||||
Hello $foo World!
|
||||
|
||||
<script type= "text/javascript"> alert("hello"); </script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1 @@
|
||||
<apex:page controller="AcRestActionsController" action="{!csrfInitMethod}" >
|
35
pmd-dist/src/test/resources/sample-source/xml/samplecode.xml
Normal file
35
pmd-dist/src/test/resources/sample-source/xml/samplecode.xml
Normal file
@ -0,0 +1,35 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<deployment-plan xmlns="http://xmlns.oracle.com/weblogic/deployment-plan"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.oracle.com/weblogic/deployment-plan http://xmlns.oracle.com/weblogic/deployment-plan/1.0/deployment-plan.xsd"
|
||||
global-variables="false">
|
||||
<application-name>app</application-name>
|
||||
<variable-definition>
|
||||
<variable>
|
||||
<name>Application_Module_Web_ContextRoot</name>
|
||||
<value xsi:nil="false">ikb.adf.kreda.abw.webapp-Abnahmetest-ohne-SSO</value>
|
||||
</variable>
|
||||
</variable-definition>
|
||||
<module-override>
|
||||
<module-name>ikb.adf.kreda.abw.ear</module-name>
|
||||
<module-type>ear</module-type>
|
||||
<module-descriptor external="false">
|
||||
<root-element>application</root-element>
|
||||
<uri>META-INF/application.xml</uri>
|
||||
<variable-assignment>
|
||||
<name>Application_Module_Web_ContextRoot</name>
|
||||
<xpath>/application/module/web/[context-root="ikb.adf.kreda.abw.webapp-Local-ohne-SSO"]</xpath>
|
||||
<operation>replace</operation>
|
||||
</variable-assignment>
|
||||
</module-descriptor>
|
||||
</module-override>
|
||||
|
||||
<root>
|
||||
<child>
|
||||
<![CDATA[
|
||||
some text data
|
||||
]]]>
|
||||
</child>
|
||||
</root>
|
||||
|
||||
</deployment-plan>
|
@ -0,0 +1,4 @@
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
<xsl:variable name="var" select="concat('abc',concat('cd','ef'))"/>
|
||||
</xsl:stylesheet>
|
Reference in New Issue
Block a user