Remove pmd-compat6 (breaking change) (#5076)

Merge pull request #5076 from adangel:remove-compat6
This commit is contained in:
Andreas Dangel
2024-06-27 14:45:44 +02:00
91 changed files with 40 additions and 6877 deletions

View File

@ -4,6 +4,7 @@ tags: [pmd, userdocs]
summary: "Migrating to PMD 7 from PMD 6.x"
permalink: pmd_userdocs_migrating_to_pmd7.html
author: Andreas Dangel <andreas.dangel@pmd-code.org>
last_updated: June 2024 (7.3.0)
---
{% include important.html content="
@ -3363,8 +3364,9 @@ See the use case [I'm using only built-in rules](#im-using-only-built-in-rules)
#### Maven
* Due to some changes in PMD's API, you can't simply pull in the new PMD 7 dependency.
* See [Using PMD 7 with maven-pmd-plugin](pmd_userdocs_tools_maven.html#using-pmd-7-with-maven-pmd-plugin).
* Since maven-pmd-plugin 3.22.0, PMD 7 is supported directly.
* See [MPMD-379](https://issues.apache.org/jira/browse/MPMD-379)
* See [Using PMD 7 with maven-pmd-plugin](pmd_userdocs_tools_maven.html#using-pmd-7-with-maven-pmd-plugin)
#### Gradle

View File

@ -2,8 +2,8 @@
title: Maven PMD Plugin
tags: [userdocs, tools]
permalink: pmd_userdocs_tools_maven.html
last_updated: February 2024
mpmd_version: 3.21.2
last_updated: June 2024 (7.3.0)
mpmd_version: 3.23.0
author: >
Miguel Griffa <mikkey@users.sourceforge.net>,
Romain PELISSE <belaran@gmail.com>,
@ -72,7 +72,7 @@ This will add an entry to the 'project reports' section with the PMD report when
To run PMD on a Maven project without adding it as a report, simply run
mvn pmd:pmd
mvn complile pmd:pmd
The PMD plugin writes the report in XML which will then be formatted into more readable HTML.
@ -241,47 +241,25 @@ Maven plugin will use and benefit from the latest bugfixes and enhancements:
#### Using PMD 7 with maven-pmd-plugin
The Maven PMD plugin comes with a specific PMD version, which is documented on the
Since version 3.22.0 ([MPMD-379](https://issues.apache.org/jira/browse/MPMD-379)), maven-pmd-plugin uses
by default now PMD 7.0.0 and no extra configuration is required.
The specific PMD version used by maven-pmd-plugin might change. The exact version is documented on the
[plugin project page](https://maven.apache.org/plugins/maven-pmd-plugin/index.html).
This might not support PMD 7 out of the box.
Since PMD 7 is a major release which breaks compatibility in various ways, the solution described
above in [Upgrading the PMD version at runtime](#upgrading-the-pmd-version-at-runtime) doesn't work
directly.
In order to use newer versions of PMD 7, you can simply follow the guide
[Upgrading PMD at Runtime](https://maven.apache.org/plugins/maven-pmd-plugin/examples/upgrading-PMD-at-runtime.html).
In order to use PMD 7 with [maven-pmd-plugin](https://maven.apache.org/plugins/maven-pmd-plugin/) a new
compatibility module has been created. This allows to use PMD 7 by simply adding one additional dependency:
1. Follow the guide [Upgrading PMD at Runtime](https://maven.apache.org/plugins/maven-pmd-plugin/examples/upgrading-PMD-at-runtime.html)
2. Add additionally the following dependency:
```xml
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-compat6</artifactId>
<version>${pmdVersion}</version>
</dependency>
```
It is important to add this dependency as the **first** in the list, so that maven-pmd-plugin sees the (old)
compatible versions of some classes.
This module is available beginning with version 7.0.0-rc4 and will be there at least for the first
final version PMD 7 (7.0.0). It's not decided yet, whether we will keep updating it, after PMD 7 is finally
released.
Note: This compatibility module only works for the built-in rules, that are still available in PMD 7. E.g. you need
to review your rulesets and look out for deprecated rules and such. See the use case
[I'm using only built-in rules](pmd_userdocs_migrating_to_pmd7.html#im-using-only-built-in-rules)
in the [Migration Guide for PMD 7](pmd_userdocs_migrating_to_pmd7.html).
Note: If you upgrade from Maven PMD Plugin before 3.22.0 you are most likely updating from PMD 6 to PMD 7.
This upgrade is a major version change. If you use the default ruleset from Maven PMD Plugin, then everything should
just work. But if you use a custom ruleset, you most likely need to review your ruleset and migrate it to PMD 7.
Rules might have been renamed or replaced. See [Detailed Release Notes for PMD 7](pmd_release_notes_pmd7.html)
and [Migration Guide for PMD 7](pmd_userdocs_migrating_to_pmd7.html).
As PMD 7 revamped the Java module, if you have custom rules, you need to migrate these rules.
See the use case [I'm using custom rules](pmd_userdocs_migrating_to_pmd7.html#im-using-custom-rules)
in the Migration Guide.
### Reference
For more information, please see the well documented PMD plugin project page here:

View File

@ -4,6 +4,12 @@ permalink: pmd_release_notes.html
keywords: changelog, release notes
---
{% if is_release_notes_processor %}
{% capture baseurl %}https://docs.pmd-code.org/pmd-doc-{{ site.pmd.version }}/{% endcapture %}
{% else %}
{% assign baseurl = "" %}
{% endif %}
## {{ site.pmd.date | date: "%d-%B-%Y" }} - {{ site.pmd.version }}
The PMD team is pleased to announce PMD {{ site.pmd.version }}.
@ -18,6 +24,17 @@ This is a {{ site.pmd.release_type }} release.
* The new Java rule {%rule java/bestpractices/UseEnumCollections %} reports usages for `HashSet` and `HashMap`
when the keys are of an enum type. The specialized enum collections are more space- and time-efficient.
#### 💥 pmd-compat6 removed (breaking)
The already deprecated PMD 6 compatibility module (pmd-compat6) has been removed. It was intended to be used with
older versions of the maven-pmd-plugin, but since maven-pmd-plugin 3.22.0, PMD 7 is supported directly and this
module is not needed anymore.
If you currently use this dependency (`net.sourceforge.pmd:pmd-compat6`), remove it and upgrade maven-pmd-plugin
to the latest version (3.23.0 or newer).
See also [Maven PMD Plugin]({{ baseurl }}pmd_userdocs_tools_maven.html).
### 🐛 Fixed Issues
* cli
* [#2827](https://github.com/pmd/pmd/issues/2827): \[cli] Consider processing errors in exit status
@ -100,6 +117,11 @@ read the XML format should be updated.
patterns don't declare a pattern variable for the whole pattern, but rather for individual record
components, which can be accessed via {%jdoc java::lang.java.ast.ASTRecordPattern#getComponentPatterns() %}.
#### Breaking changes: pmd-compat6 removed
The already deprecated PMD 6 compatibility module (pmd-compat6) has been removed.
See above for details.
### ✨ External Contributions
{% endtocmaker %}

View File

@ -1,39 +0,0 @@
# 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 maven-pmd-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.
Note: 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 module pmd-compat6 might not be maintaned then
any further, hence it is already declared as deprecated.
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.
No guarantee is given, that the (deprecated) module pmd-compat6 is being maintained over the
whole lifetime of PMD 7.

View File

@ -1,88 +0,0 @@
<?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.3.0-SNAPSHOT</version>
</parent>
<artifactId>pmd-compat6</artifactId>
<name>PMD Compatibility Classes for PMD6 (deprecated)</name>
<properties>
<pmd.version.for.integrationtest>${project.version}</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>${project.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-javascript</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-jsp</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-cs</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jboss.bridger</groupId>
<artifactId>bridger</artifactId>
<version>1.6.Final</version>
<executions>
<execution>
<id>weave</id>
<phase>process-classes</phase>
<goals>
<goal>transform</goal>
</goals>
</execution>
</executions>
</plugin>
<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>
<streamLogsOnFailures>true</streamLogsOnFailures>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>install</goal>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

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

View File

@ -1,78 +0,0 @@
<?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-csharp</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</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>csharp-cpd-check</id>
<goals>
<goal>cpd-check</goal>
</goals>
</execution>
</executions>
<configuration>
<language>cs</language>
<minimumTokens>10</minimumTokens>
<includes>
<include>**/*.cs</include>
</includes>
<compileSourceRoots>
<compileSourceRoot>${basedir}/src/main/cs</compileSourceRoot>
</compileSourceRoots>
<printFailingErrors>true</printFailingErrors>
<skipPmdError>false</skipPmdError>
</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>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-cs</artifactId>
<version>@pmd.version.for.integrationtest@</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,12 +0,0 @@
class Foo {
void bar() {
var test = $@"test";
var test2 = @$"test";
String query =
@"SELECT foo, bar
FROM table
WHERE id = 42";
}
}

View File

@ -1,12 +0,0 @@
class Foo {
void bar() {
var test = $@"test";
var test2 = @$"test";
String query =
@"SELECT foo, bar
FROM table
WHERE id = 42";
}
}

View File

@ -1,46 +0,0 @@
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("An API incompatibility was encountered while")) {
throw new RuntimeException("Executing failed due to API incompatibility");
}
if (!buildLog.contains("[INFO] CPD Failure: Found 12 lines of duplicated code at locations:")) {
throw new RuntimeException("No CPD failures detected, did CPD run?");
}
File classA = new File("cpd-for-csharp/src/main/cs/strings1.cs");
if (!buildLog.contains(classA + " line 1")) {
throw new RuntimeException("No CPD failures detected, did CPD run?");
}
File classB = new File("cpd-for-csharp/src/main/cs/strings2.cs");
if (!buildLog.contains(classA + " 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=\"12\" tokens=\"29\">")) {
throw new RuntimeException("Expected duplication has not been reported");
}
if (!cpdXml.contains(classA + "\"/>")) {
throw new RuntimeException("Expected duplication has not been reported");
}
if (!cpdXml.contains(classB + "\"/>")) {
throw new RuntimeException("Expected duplication has not been reported");
}

View File

@ -1,4 +0,0 @@
invoker.goals.1 = verify
invoker.goals.2 = pmd:cpd-check -Dformat=csv
invoker.goals.3 = pmd:cpd-check -Dformat=txt
invoker.buildResult = failure

View File

@ -1,66 +0,0 @@
<?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>11</maven.compiler.source>
<maven.compiler.target>11</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

@ -1,10 +0,0 @@
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

@ -1,10 +0,0 @@
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

@ -1,62 +0,0 @@
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("An API incompatibility was encountered while")) {
throw new RuntimeException("Executing failed due to API incompatibility");
}
if (!buildLog.contains("[INFO] CPD Failure: Found 8 lines of duplicated code at locations:")) {
throw new RuntimeException("No CPD failures detected, did CPD run?");
}
File classA = new File("cpd-for-java/src/main/java/org/example/ClassA.java");
if (!buildLog.contains(classA + " 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(classA + "\"/>")) {
throw new RuntimeException("Expected duplication has not been reported");
}
File csvReport = new File(basedir, "target/cpd.csv");
if (!csvReport.exists()) {
throw new FileNotFoundException("Could not find cpd csv report: " + csvReport);
}
String csv = readFile(csvReport);
if (!csv.contains("8,67,2,3,")) {
throw new RuntimeException("Expected duplication in CSV has not been reported");
}
if (!csv.contains(classA + ",")) {
throw new RuntimeException("Expected duplication in CSV has not been reported");
}
File textReport = new File(basedir, "target/cpd.txt");
if (!textReport.exists()) {
throw new FileNotFoundException("Could not find cpd text report: " + textReport);
}
String text = readFile(textReport);
if (!text.contains("Found a 8 line (67 tokens) duplication in the following files:")) {
throw new RuntimeException("Expected duplication in TXT has not been reported");
}
if (!text.contains("Starting at line 3 of ") && !text.contains(classA.toString())) {
throw new RuntimeException("Expected duplication in TXT has not been reported");
}

View File

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

View File

@ -1,74 +0,0 @@
<?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

@ -1,7 +0,0 @@
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

@ -1,7 +0,0 @@
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

@ -1,36 +0,0 @@
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?");
}
File globalVariable = new File("cpd-for-javascript/src/main/js/globalVariable.js");
if (!buildLog.contains(globalVariable + " 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(globalVariable + "\"/>")) {
throw new RuntimeException("Expected duplication has not been reported");
}

View File

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

View File

@ -1,74 +0,0 @@
<?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

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

View File

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

View File

@ -1,36 +0,0 @@
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?");
}
File classAttribute = new File("cpd-for-jsp/src/main/jsp/classAttribute.jsp");
if (!buildLog.contains(classAttribute + " 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(classAttribute + "\"/>")) {
throw new RuntimeException("Expected duplication has not been reported");
}

View File

@ -1,5 +0,0 @@
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" name="RuleSet that creates a config error">
<description/>
<!-- Rule LoosePackageCoupling is enabled, but not configured -->
<rule ref="category/java/design.xml/LoosePackageCoupling" />
</ruleset>

View File

@ -1,16 +0,0 @@
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" name="Exception throwing ruleset">
<description/>
<rule name="ExceptionThrowingRule"
language="java"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
<description>Use this rule to produce a processing error.</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
error()
]]></value></property>
</properties>
</rule>
</ruleset>

View File

@ -1,4 +0,0 @@
invoker.goals.1 = verify -e
invoker.goals.2 = pmd:check -Dformat=csv
invoker.goals.3 = pmd:check -Dformat=txt
invoker.buildResult = failure

View File

@ -1,72 +0,0 @@
<?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>11</maven.compiler.source>
<maven.compiler.target>11</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>true</skipPmdError> <!-- we want to capture processing errors -->
<minimumTokens>5</minimumTokens>
<analysisCache>true</analysisCache>
<rulesets>
<ruleset>/rulesets/java/maven-pmd-plugin-default.xml</ruleset>
<ruleset>${project.basedir}/exception_ruleset.xml</ruleset>
<ruleset>${project.basedir}/config_error_ruleset.xml</ruleset>
</rulesets>
</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

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

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