Merge branch 'experimental-apex-parser' into issue-4722-apex-fixes

This commit is contained in:
Andreas Dangel committed 2023-11-23 17:35:47 +01:00
commit 556644a136
66 files changed
+4073 -86

No files matched your search

-4
View File
@@ -323,10 +323,6 @@ function pmd_ci_dogfood() {
local mpmdVersion=()
./mvnw versions:set -DnewVersion="${PMD_CI_MAVEN_PROJECT_VERSION}-dogfood" -DgenerateBackupPoms=false
sed -i 's/<version>[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}.*<\/version>\( *<!-- pmd.dogfood.version -->\)/<version>'"${PMD_CI_MAVEN_PROJECT_VERSION}"'<\/version>\1/' pom.xml
if [ "${PMD_CI_MAVEN_PROJECT_VERSION}" = "7.0.0-SNAPSHOT" ]; then
sed -i 's/pmd-dogfood-config\.xml/pmd-dogfood-config7.xml/' pom.xml
mpmdVersion=(-Denforcer.skip=true -Dpmd.plugin.version=3.21.1-pmd-7.0.0-SNAPSHOT)
fi
./mvnw verify --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}" \
"${mpmdVersion[@]}" \
-DskipTests \
+10 -10
View File
@@ -3,7 +3,7 @@ GEM
specs:
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
base64 (0.1.1)
base64 (0.2.0)
claide (1.1.0)
claide-plugins (0.9.2)
cork
@@ -13,7 +13,7 @@ GEM
concurrent-ruby (1.2.2)
cork (0.3.0)
colored2 (~> 3.1)
danger (9.3.2)
danger (9.4.0)
claide (~> 1.0)
claide-plugins (>= 0.9.2)
colored2 (~> 3.1)
@@ -24,7 +24,7 @@ GEM
kramdown (~> 2.3)
kramdown-parser-gfm (~> 1.0)
no_proxy_fix
octokit (~> 6.0)
octokit (>= 6.0, < 8.0)
terminal-table (>= 1, < 4)
differ (0.1.2)
et-orbi (1.2.7)
@@ -36,7 +36,7 @@ GEM
faraday-http-cache (2.5.0)
faraday (>= 0.8)
faraday-net_http (3.0.2)
fugit (1.8.1)
fugit (1.9.0)
et-orbi (~> 1, >= 1.2.7)
raabro (~> 1.4)
git (1.18.0)
@@ -48,17 +48,17 @@ GEM
kramdown (~> 2.0)
liquid (5.4.0)
logger-colors (1.0.0)
mini_portile2 (2.8.4)
mini_portile2 (2.8.5)
nap (1.1.0)
no_proxy_fix (0.1.2)
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
octokit (6.1.1)
octokit (7.2.0)
faraday (>= 1, < 3)
sawyer (~> 0.9)
open4 (1.3.4)
pmdtester (1.5.4)
pmdtester (1.5.5)
differ (~> 0.1)
liquid (~> 5.4)
logger-colors (~> 1.0)
@@ -67,10 +67,10 @@ GEM
slop (~> 4.9)
public_suffix (5.0.3)
raabro (1.4.0)
racc (1.7.1)
racc (1.7.3)
rchardet (1.8.0)
rexml (3.2.6)
rouge (4.1.3)
rouge (4.2.0)
ruby2_keywords (0.0.5)
rufus-scheduler (3.9.1)
fugit (~> 1.1, >= 1.1.6)
@@ -83,7 +83,7 @@ GEM
unicode-display_width (>= 1.1.1, < 3)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.4.2)
unicode-display_width (2.5.0)
PLATFORMS
ruby
+27 -65
View File
@@ -3124,7 +3124,7 @@ This is only relevant, if you are maintaining a CPD language module for a custom
{% include note.html content="
When you switch from PMD 6.x to PMD 7 in your build tools, you most likely need to review your
ruleset(s) as well and check for removed rules.
See the use case[I'm using only built-in rules](#im-using-only-built-in-rules) above.
See the use case [I'm using only built-in rules](#im-using-only-built-in-rules) above.
" %}
#### Ant
@@ -3138,70 +3138,32 @@ See the use case[I'm using only built-in rules](#im-using-only-built-in-rules) a
#### Maven
* Due to some changes in PMD's API, you can't simply pull in the new PMD 7 dependency using the
approach documented in [Upgrading PMD at Runtime](https://maven.apache.org/plugins/maven-pmd-plugin/examples/upgrading-PMD-at-runtime.html).
* A new maven-pmd-plugin version, that supports PMD 7 is in the works. See [MPMD-379](https://issues.apache.org/jira/browse/MPMD-379).
* As long as no new maven-pmd-plugin version with PMD 7 support is released, you can try it out using a
SNAPSHOT version:
1. Add the Apache SNAPSHOT maven repository:
```xml
<pluginRepository>
<id>apache.snapshots</id>
<name>Apache Snapshot Repository</name>
<url>https://repository.apache.org/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
```
2. Use the version **3.21.1-pmd-7-SNAPSHOT** of the maven-pmd-plugin
3. Override the dependencies of the plugin to use PMD 7, e.g.
```xml
<project>
<properties>
<pmdVersion>{{site.pmd.version}}</pmdVersion>
<mavenPmdPluginVersion>3.21.1-pmd-7.0.0-SNAPSHOT</mavenPmdPluginVersion>
</properties>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${mavenPmdPluginVersion}</version>
<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
<version>${pmdVersion}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>${pmdVersion}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-javascript</artifactId>
<version>${pmdVersion}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-jsp</artifactId>
<version>${pmdVersion}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
...
</project>
```
* Due to some changes in PMD's API, you can't simply pull in the new PMD 7 dependency.
* However, there is now a compatibility module, that makes it possible to use PMD 7 with Maven. In addition to the PMD 7
dependencies documented in [Upgrading PMD at Runtime](https://maven.apache.org/plugins/maven-pmd-plugin/examples/upgrading-PMD-at-runtime.html)
you need to add additionally the following dependency (first available version is 7.0.0-rc4):
```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](#im-using-only-built-in-rules)
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](#im-using-custom-rules).
#### Gradle
+34
View File
@@ -41,6 +41,38 @@ The remaining section describes the complete release notes for 7.0.0.
#### New and Noteworthy
##### Maven PMD Plugin compatibility with PMD 7
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]({{ baseurl }}pmd_userdocs_migrating_to_pmd7.html#im-using-only-built-in-rules)
in the [Migration Guide for PMD 7]({{ baseurl }}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]({{ baseurl }}pmd_userdocs_migrating_to_pmd7.html#im-using-custom-rules)
in the Migration Guide.
#### Rule Changes
**New Rules**
@@ -64,6 +96,7 @@ The remaining section describes the complete release notes for 7.0.0.
* miscellaneous
* [#4699](https://github.com/pmd/pmd/pull/4699): Make PMD buildable with java 21
* [#4586](https://github.com/pmd/pmd/pull/4586): Use explicit encoding in ruleset xml files
* [#4741](https://github.com/pmd/pmd/pull/4741): Add pmd-compat6 module for maven-pmd-plugin
* apex-performance
* [#4675](https://github.com/pmd/pmd/issues/4675): \[apex] New Rule: OperationWithHighCostInLoop
* java-codestyle
@@ -445,6 +478,7 @@ See also [Detailed Release Notes for PMD 7]({{ baseurl }}pmd_release_notes_pmd7.
* [#4586](https://github.com/pmd/pmd/pull/4586): Use explicit encoding in ruleset xml files
* [#4691](https://github.com/pmd/pmd/issues/4691): \[CVEs] Critical and High CEVs reported on PMD and PMD dependencies
* [#4699](https://github.com/pmd/pmd/pull/4699): Make PMD buildable with java 21
* [#4741](https://github.com/pmd/pmd/pull/4741): Add pmd-compat6 module for maven-pmd-plugin
* ant
* [#4080](https://github.com/pmd/pmd/issues/4080): \[ant] Split off Ant integration into a new submodule
* core
+35
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.
+69
View File
@@ -0,0 +1,69 @@
<?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-SNAPSHOT</version>
</parent>
<artifactId>pmd-compat6</artifactId>
<name>PMD Compatibility Classes for PMD6</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>
</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>
<streamLogsOnFailures>true</streamLogsOnFailures>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>install</goal>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,4 @@
invoker.goals.1 = verify
invoker.goals.2 = pmd:cpd-check -Dformat=csv
invoker.goals.3 = pmd:cpd-check -Dformat=txt
invoker.buildResult = failure
+66
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>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>
@@ -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;
}
}
@@ -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;
}
}
@@ -0,0 +1,62 @@
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");
}
@@ -0,0 +1,2 @@
invoker.goals = verify
invoker.buildResult = failure
@@ -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>
@@ -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.
}
@@ -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.
}
@@ -0,0 +1,36 @@
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");
}
@@ -0,0 +1,2 @@
invoker.goals = verify
invoker.buildResult = failure
+74
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>
@@ -0,0 +1,3 @@
<HTML> <BODY>
<P class="MajorHeading">Some text</P>
</BODY> </HTML>
@@ -0,0 +1,3 @@
<HTML> <BODY>
<P class="MajorHeading">Some text</P>
</BODY> </HTML>
+36
View File
@@ -0,0 +1,36 @@
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");
}
@@ -0,0 +1,4 @@
invoker.goals.1 = verify
invoker.goals.2 = pmd:check -Dformat=csv
invoker.goals.3 = pmd:check -Dformat=txt
invoker.buildResult = failure
+66
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>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>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>
@@ -0,0 +1,8 @@
package org.example;
public class Main {
public static void main(String[] args) {
String thisIsAUnusedLocalVar = "a";
System.out.println("Hello world!");
}
}
@@ -0,0 +1,53 @@
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] 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");
}
File mainFile = new File("pmd-for-java/src/main/java/org/example/Main.java");
if (!pmdXml.contains(mainFile + "\">")) {
throw new RuntimeException("Expected violation has not been reported");
}
File pmdCsvReport = new File(basedir, "target/pmd.csv");
if (!pmdCsvReport.exists()) {
throw new FileNotFoundException("Could not find pmd CSV report: " + pmdCsvReport);
}
String csvReport = readFile(pmdCsvReport);
if (!csvReport.contains(mainFile + "\",\"3\",\"5\",\"Avoid unused local")) {
throw new RuntimeException("Expected violation has not been reported in CSV");
}
File pmdTextReport = new File(basedir, "target/pmd.txt");
if (!pmdTextReport.exists()) {
throw new FileNotFoundException("Could not find pmd TXT report: " + pmdTextReport);
}
String textReport = readFile(pmdTextReport);
if (!textReport.contains(mainFile + ":5:\tUnusedLocalVariable")) {
throw new RuntimeException("Expected violation has not been reported in TXT");
}
@@ -0,0 +1,2 @@
invoker.goals = verify
invoker.buildResult = failure
@@ -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>
@@ -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.
}
@@ -0,0 +1,33 @@
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");
}
File globalVariable = new File("pmd-for-javascript/src/main/js/globalVariable.js");
if (!pmdXml.contains(globalVariable + "\">")) {
throw new RuntimeException("Expected violation has not been reported");
}
@@ -0,0 +1,2 @@
invoker.goals = verify
invoker.buildResult = failure
Loaded 30 of 66 files, more files were not shown because too many files have changed in this diff. Show more