New pmd-compat6 module

This makes it possible to use PMD7 with maven-pmd-plugin
This commit is contained in:
Andreas Dangel 2023-11-09 20:02:23 +01:00
parent c5503c938f
commit b5d0ffb02f
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3
57 changed files with 3695 additions and 0 deletions

35
pmd-compat6/README.md Normal file
View File

@ -0,0 +1,35 @@
# pmd-compat6
This module contains classes from PMD6, that have been removed in PMD7 and also restores
some removed methods.
The goal is, that PMD7 can be used with [Maven PMD Plugin](https://maven.apache.org/plugins/maven-pmd-plugin)
without any further changes to the plugin.
The plugin uses by default PMD Version 6.55.0, but it can be configured to
[Use a new PMD version at runtime](https://maven.apache.org/plugins/maven-pmd-plugin/examples/upgrading-PMD-at-runtime.html).
Since PMD7 introduces many incompatible changes, another module is needed to restore
compatibility. This is this module.
In order to use this compatibility module, it needs to be added as the _first_ dependency
when configuring maven-pmd-plugin.
It is as simple as adding:
```xml
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-compat6</artifactId>
<version>${pmdVersion}</version>
</dependency>
```
Note: The dependency "pmd-compat6" must be listed _first_ before pmd-core, pmd-java, and the others.
Once the default version of PMD is upgraded to PMD7 in maven-pmd-plugin
(see [MPMD-379](https://issues.apache.org/jira/projects/MPMD/issues/MPMD-379)), this
compatibility module is no longer needed.
The primary goal for this module is, to get maven-pmd-plugin working with PMD7. It might
be useful in other contexts, too, but no guarantee is given, that is works.

70
pmd-compat6/pom.xml Normal file
View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>7.0.0-rc4</version>
</parent>
<artifactId>pmd-compat6</artifactId>
<version>7.0.0-SNAPSHOT</version>
<name>PMD Compatibility Classes for PMD6</name>
<properties>
<pmd.version>7.0.0-rc4</pmd.version>
<pmd.version.for.integrationtest>7.0.0-rc4</pmd.version.for.integrationtest>
<maven-pmd-plugin.version.for.integrationtest>3.21.2</maven-pmd-plugin.version.for.integrationtest>
</properties>
<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
<version>${pmd.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>${pmd.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-javascript</artifactId>
<version>${pmd.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-jsp</artifactId>
<version>${pmd.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<settingsFile>src/it/settings.xml</settingsFile>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<postBuildHookScript>verify.bsh</postBuildHookScript>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>install</goal>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,2 @@
invoker.goals = verify
invoker.buildResult = failure

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.pmd-compat6.it</groupId>
<artifactId>cpd-for-java</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>@maven-pmd-plugin.version.for.integrationtest@</version>
<executions>
<execution>
<id>java-cpd-check</id>
<goals>
<goal>cpd-check</goal>
</goals>
</execution>
</executions>
<configuration>
<printFailingErrors>true</printFailingErrors>
<skipPmdError>false</skipPmdError>
<minimumTokens>5</minimumTokens>
</configuration>
<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-compat6</artifactId>
<version>@project.version@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-javascript</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-jsp</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,10 @@
package org.example;
public class ClassA {
public int method1(int a, int b, int c) {
int d = (a + b + c + 1) * 10;
int e = (a + b + c - 1) * 5;
int f = (a + b + c);
return d * e * f + d + e + f;
}
}

View File

@ -0,0 +1,10 @@
package org.example;
public class ClassB {
public int method1(int a, int b, int c) {
int d = (a + b + c + 1) * 10;
int e = (a + b + c - 1) * 5;
int f = (a + b + c);
return d * e * f + d + e + f;
}
}

View File

@ -0,0 +1,35 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
String readFile(File file) throws IOException {
StringBuilder content = new StringBuilder();
for (String line : Files.readAllLines(file.toPath(), StandardCharsets.UTF_8)) {
content.append(line).append(System.lineSeparator());
}
return content.toString();
}
File buildLogPath = new File(basedir, "build.log");
String buildLog = readFile(buildLogPath);
if (!buildLog.contains("[INFO] CPD Failure: Found 8 lines of duplicated code at locations:")) {
throw new RuntimeException("No CPD failures detected, did CPD run?");
}
if (!buildLog.contains("cpd-for-java/src/main/java/org/example/ClassA.java line 3")) {
throw new RuntimeException("No CPD failures detected, did CPD run?");
}
File cpdXmlReport = new File(basedir, "target/cpd.xml");
if(!cpdXmlReport.exists())
{
throw new FileNotFoundException("Could not find cpd xml report: " + cpdXmlReport);
}
String cpdXml = readFile(cpdXmlReport);
if (!cpdXml.contains("<duplication lines=\"8\" tokens=\"67\">")) {
throw new RuntimeException("Expected duplication has not been reported");
}
if (!cpdXml.contains("cpd-for-java/src/main/java/org/example/ClassA.java\"/>")) {
throw new RuntimeException("Expected duplication has not been reported");
}

View File

@ -0,0 +1,2 @@
invoker.goals = verify
invoker.buildResult = failure

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.pmd-compat6.it</groupId>
<artifactId>cpd-for-javascript</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>@maven-pmd-plugin.version.for.integrationtest@</version>
<executions>
<execution>
<id>javascript-cpd-check</id>
<goals>
<goal>cpd-check</goal>
</goals>
</execution>
</executions>
<configuration>
<printFailingErrors>true</printFailingErrors>
<skipPmdError>false</skipPmdError>
<minimumTokens>5</minimumTokens>
<language>javascript</language>
<rulesets>
<ruleset>/category/ecmascript/bestpractices.xml</ruleset>
</rulesets>
<includes>
<include>**/*.js</include>
</includes>
<compileSourceRoots>
<compileSourceRoot>${basedir}/src/main/js</compileSourceRoot>
</compileSourceRoots>
</configuration>
<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-compat6</artifactId>
<version>@project.version@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-javascript</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-jsp</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,7 @@
function(arg) {
notDeclaredVariable = 1; // this will create a global variable and trigger the rule
var someVar = 1; // this is a local variable, that's ok
window.otherGlobal = 2; // this will not trigger the rule, although it is a global variable.
}

View File

@ -0,0 +1,7 @@
function(arg) {
notDeclaredVariable = 1; // this will create a global variable and trigger the rule
var someVar = 1; // this is a local variable, that's ok
window.otherGlobal = 2; // this will not trigger the rule, although it is a global variable.
}

View File

@ -0,0 +1,35 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
String readFile(File file) throws IOException {
StringBuilder content = new StringBuilder();
for (String line : Files.readAllLines(file.toPath(), StandardCharsets.UTF_8)) {
content.append(line).append(System.lineSeparator());
}
return content.toString();
}
File buildLogPath = new File(basedir, "build.log");
String buildLog = readFile(buildLogPath);
if (!buildLog.contains("[INFO] CPD Failure: Found 7 lines of duplicated code at locations:")) {
throw new RuntimeException("No CPD failures detected, did CPD run?");
}
if (!buildLog.contains("cpd-for-javascript/src/main/js/globalVariable.js line 1")) {
throw new RuntimeException("No CPD failures detected, did CPD run?");
}
File cpdXmlReport = new File(basedir, "target/cpd.xml");
if(!cpdXmlReport.exists())
{
throw new FileNotFoundException("Could not find cpd xml report: " + cpdXmlReport);
}
String cpdXml = readFile(cpdXmlReport);
if (!cpdXml.contains("<duplication lines=\"7\" tokens=\"21\">")) {
throw new RuntimeException("Expected duplication has not been reported");
}
if (!cpdXml.contains("cpd-for-javascript/src/main/js/globalVariable.js\"/>")) {
throw new RuntimeException("Expected duplication has not been reported");
}

View File

@ -0,0 +1,2 @@
invoker.goals = verify
invoker.buildResult = failure

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.pmd-compat6.it</groupId>
<artifactId>cpd-for-jsp</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>@maven-pmd-plugin.version.for.integrationtest@</version>
<executions>
<execution>
<id>jsp-cpd-check</id>
<goals>
<goal>cpd-check</goal>
</goals>
</execution>
</executions>
<configuration>
<printFailingErrors>true</printFailingErrors>
<skipPmdError>false</skipPmdError>
<minimumTokens>5</minimumTokens>
<language>jsp</language>
<rulesets>
<ruleset>/category/jsp/bestpractices.xml</ruleset>
</rulesets>
<includes>
<include>**/*.jsp</include>
</includes>
<compileSourceRoots>
<compileSourceRoot>${basedir}/src/main/jsp</compileSourceRoot>
</compileSourceRoots>
</configuration>
<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-compat6</artifactId>
<version>@project.version@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-javascript</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-jsp</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,3 @@
<HTML> <BODY>
<P class="MajorHeading">Some text</P>
</BODY> </HTML>

View File

@ -0,0 +1,3 @@
<HTML> <BODY>
<P class="MajorHeading">Some text</P>
</BODY> </HTML>

View File

@ -0,0 +1,35 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
String readFile(File file) throws IOException {
StringBuilder content = new StringBuilder();
for (String line : Files.readAllLines(file.toPath(), StandardCharsets.UTF_8)) {
content.append(line).append(System.lineSeparator());
}
return content.toString();
}
File buildLogPath = new File(basedir, "build.log");
String buildLog = readFile(buildLogPath);
if (!buildLog.contains("[INFO] CPD Failure: Found 3 lines of duplicated code at locations:")) {
throw new RuntimeException("No CPD failures detected, did CPD run?");
}
if (!buildLog.contains("cpd-for-jsp/src/main/jsp/classAttribute.jsp line 1")) {
throw new RuntimeException("No CPD failures detected, did CPD run?");
}
File cpdXmlReport = new File(basedir, "target/cpd.xml");
if(!cpdXmlReport.exists())
{
throw new FileNotFoundException("Could not find cpd xml report: " + cpdXmlReport);
}
String cpdXml = readFile(cpdXmlReport);
if (!cpdXml.contains("<duplication lines=\"3\" tokens=\"24\">")) {
throw new RuntimeException("Expected duplication has not been reported");
}
if (!cpdXml.contains("cpd-for-jsp/src/main/jsp/classAttribute.jsp\"/>")) {
throw new RuntimeException("Expected duplication has not been reported");
}

View File

@ -0,0 +1,2 @@
invoker.goals = verify
invoker.buildResult = failure

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.pmd-compat6.it</groupId>
<artifactId>pmd-for-java</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>@maven-pmd-plugin.version.for.integrationtest@</version>
<executions>
<execution>
<id>java-check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<printFailingErrors>true</printFailingErrors>
<skipPmdError>false</skipPmdError>
<minimumTokens>5</minimumTokens>
</configuration>
<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-compat6</artifactId>
<version>@project.version@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-javascript</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-jsp</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,8 @@
package org.example;
public class Main {
public static void main(String[] args) {
String thisIsAUnusedLocalVar = "a";
System.out.println("Hello world!");
}
}

View File

@ -0,0 +1,32 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
String readFile(File file) throws IOException {
StringBuilder content = new StringBuilder();
for (String line : Files.readAllLines(file.toPath(), StandardCharsets.UTF_8)) {
content.append(line).append(System.lineSeparator());
}
return content.toString();
}
File buildLogPath = new File(basedir, "build.log");
String buildLog = readFile(buildLogPath);
if (!buildLog.contains("[INFO] PMD Failure: org.example.Main:5 Rule:UnusedLocalVariable")) {
throw new RuntimeException("No pmd violation detected, did PMD run?");
}
File pmdXmlReport = new File(basedir, "target/pmd.xml");
if(!pmdXmlReport.exists())
{
throw new FileNotFoundException("Could not find pmd xml report: " + pmdXmlReport);
}
String pmdXml = readFile(pmdXmlReport);
if (!pmdXml.contains("<violation beginline=\"5\" endline=\"5\" begincolumn=\"16\" endcolumn=\"37\" rule=\"UnusedLocalVariable\" ruleset=\"Best Practices\" package=\"org.example\" class=\"Main\" method=\"main\" variable=\"thisIsAUnusedLocalVar\"")) {
throw new RuntimeException("Expected violation has not been reported");
}
if (!pmdXml.contains("pmd-for-java/src/main/java/org/example/Main.java\">")) {
throw new RuntimeException("Expected violation has not been reported");
}

View File

@ -0,0 +1,2 @@
invoker.goals = verify
invoker.buildResult = failure

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.pmd-compat6.it</groupId>
<artifactId>pmd-for-javascript</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>@maven-pmd-plugin.version.for.integrationtest@</version>
<executions>
<execution>
<id>javascript-check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<printFailingErrors>true</printFailingErrors>
<skipPmdError>false</skipPmdError>
<minimumTokens>5</minimumTokens>
<language>javascript</language>
<rulesets>
<ruleset>/category/ecmascript/bestpractices.xml</ruleset>
</rulesets>
<includes>
<include>**/*.js</include>
</includes>
<compileSourceRoots>
<compileSourceRoot>${basedir}/src/main/js</compileSourceRoot>
</compileSourceRoots>
</configuration>
<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-compat6</artifactId>
<version>@project.version@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-javascript</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-jsp</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,7 @@
function(arg) {
notDeclaredVariable = 1; // this will create a global variable and trigger the rule
var someVar = 1; // this is a local variable, that's ok
window.otherGlobal = 2; // this will not trigger the rule, although it is a global variable.
}

View File

@ -0,0 +1,32 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
String readFile(File file) throws IOException {
StringBuilder content = new StringBuilder();
for (String line : Files.readAllLines(file.toPath(), StandardCharsets.UTF_8)) {
content.append(line).append(System.lineSeparator());
}
return content.toString();
}
File buildLogPath = new File(basedir, "build.log");
String buildLog = readFile(buildLogPath);
if (!buildLog.contains("[INFO] PMD Failure: globalVariable.js:2 Rule:GlobalVariable")) {
throw new RuntimeException("No pmd violation detected, did PMD run?");
}
File pmdXmlReport = new File(basedir, "target/pmd.xml");
if(!pmdXmlReport.exists())
{
throw new FileNotFoundException("Could not find pmd xml report: " + pmdXmlReport);
}
String pmdXml = readFile(pmdXmlReport);
if (!pmdXml.contains("<violation beginline=\"2\" endline=\"2\" begincolumn=\"5\" endcolumn=\"28\" rule=\"GlobalVariable\" ruleset=\"Best Practices\"")) {
throw new RuntimeException("Expected violation has not been reported");
}
if (!pmdXml.contains("pmd-for-javascript/src/main/js/globalVariable.js\">")) {
throw new RuntimeException("Expected violation has not been reported");
}

View File

@ -0,0 +1,2 @@
invoker.goals = verify
invoker.buildResult = failure

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.pmd-compat6.it</groupId>
<artifactId>pmd-for-jsp</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>@maven-pmd-plugin.version.for.integrationtest@</version>
<executions>
<execution>
<id>jsp-check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<printFailingErrors>true</printFailingErrors>
<skipPmdError>false</skipPmdError>
<minimumTokens>5</minimumTokens>
<language>jsp</language>
<rulesets>
<ruleset>/category/jsp/bestpractices.xml</ruleset>
</rulesets>
<includes>
<include>**/*.jsp</include>
</includes>
<compileSourceRoots>
<compileSourceRoot>${basedir}/src/main/jsp</compileSourceRoot>
</compileSourceRoots>
</configuration>
<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-compat6</artifactId>
<version>@project.version@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-javascript</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-jsp</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,3 @@
<HTML> <BODY>
<P class="MajorHeading">Some text</P>
</BODY> </HTML>

View File

@ -0,0 +1,32 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
String readFile(File file) throws IOException {
StringBuilder content = new StringBuilder();
for (String line : Files.readAllLines(file.toPath(), StandardCharsets.UTF_8)) {
content.append(line).append(System.lineSeparator());
}
return content.toString();
}
File buildLogPath = new File(basedir, "build.log");
String buildLog = readFile(buildLogPath);
if (!buildLog.contains("[INFO] PMD Failure: classAttribute.jsp:2 Rule:NoClassAttribute")) {
throw new RuntimeException("No pmd violation detected, did PMD run?");
}
File pmdXmlReport = new File(basedir, "target/pmd.xml");
if(!pmdXmlReport.exists())
{
throw new FileNotFoundException("Could not find pmd xml report: " + pmdXmlReport);
}
String pmdXml = readFile(pmdXmlReport);
if (!pmdXml.contains("<violation beginline=\"2\" endline=\"2\" begincolumn=\"4\" endcolumn=\"24\" rule=\"NoClassAttribute\" ruleset=\"Best Practices\"")) {
throw new RuntimeException("Expected violation has not been reported");
}
if (!pmdXml.contains("pmd-for-jsp/src/main/jsp/classAttribute.jsp\">")) {
throw new RuntimeException("Expected violation has not been reported");
}

View File

@ -0,0 +1,35 @@
<?xml version="1.0"?>
<settings>
<profiles>
<profile>
<id>it-repo</id>
<repositories>
<repository>
<id>local.central</id>
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>local.central</id>
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>it-repo</activeProfile>
</activeProfiles>
</settings>

Some files were not shown because too many files have changed in this diff Show More