Merge branch 'master' into build-improvements
This commit is contained in:
15
.ci/build.sh
15
.ci/build.sh
@ -36,7 +36,7 @@ function build() {
|
||||
|
||||
if pmd_ci_utils_is_fork_or_pull_request; then
|
||||
pmd_ci_log_group_start "Build with mvnw"
|
||||
./mvnw clean install --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
|
||||
./mvnw clean install -Pcli-dist --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
|
||||
pmd_ci_log_group_end
|
||||
|
||||
# Execute danger and dogfood only for pull requests in our own repository
|
||||
@ -70,7 +70,7 @@ function build() {
|
||||
|
||||
if [ "$(pmd_ci_utils_get_os)" != "linux" ]; then
|
||||
pmd_ci_log_group_start "Build with mvnw"
|
||||
./mvnw clean verify --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
|
||||
./mvnw clean verify -Pcli-dist --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
|
||||
pmd_ci_log_group_end
|
||||
|
||||
pmd_ci_log_info "Stopping build here, because os is not linux"
|
||||
@ -87,7 +87,7 @@ function build() {
|
||||
|
||||
if [ "${PMD_CI_BRANCH}" = "experimental-apex-parser" ]; then
|
||||
pmd_ci_log_group_start "Build with mvnw"
|
||||
./mvnw clean install --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
|
||||
./mvnw clean install -Pcli-dist --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
|
||||
pmd_ci_log_group_end
|
||||
|
||||
pmd_ci_log_group_start "Creating new baseline for regression tester"
|
||||
@ -321,19 +321,16 @@ ${rendered_release_notes}"
|
||||
#
|
||||
function pmd_ci_dogfood() {
|
||||
local mpmdVersion=()
|
||||
./mvnw versions:set -DnewVersion="${PMD_CI_MAVEN_PROJECT_VERSION}-dogfood" -DgenerateBackupPoms=false
|
||||
./mvnw versions:set -DnewVersion="${PMD_CI_MAVEN_PROJECT_VERSION}-dogfood" -DgenerateBackupPoms=false -Pcli-dist
|
||||
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[@]}" \
|
||||
-Pcli-dist \
|
||||
"${mpmdVersion[@]}" \
|
||||
-DskipTests \
|
||||
-Dmaven.javadoc.skip=true \
|
||||
-Dmaven.source.skip=true \
|
||||
-Dcheckstyle.skip=true
|
||||
./mvnw versions:set -DnewVersion="${PMD_CI_MAVEN_PROJECT_VERSION}" -DgenerateBackupPoms=false
|
||||
./mvnw versions:set -DnewVersion="${PMD_CI_MAVEN_PROJECT_VERSION}" -DgenerateBackupPoms=false -Pcli-dist
|
||||
git checkout -- pom.xml
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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**
|
||||
@ -65,6 +97,7 @@ The remaining section describes the complete release notes for 7.0.0.
|
||||
* [#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
|
||||
* [#4736](https://github.com/pmd/pmd/issues/4736): \[ci] Improve build procedure
|
||||
* [#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
|
||||
@ -447,6 +480,7 @@ See also [Detailed Release Notes for PMD 7]({{ baseurl }}pmd_release_notes_pmd7.
|
||||
* [#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
|
||||
* [#4736](https://github.com/pmd/pmd/issues/4736): \[ci] Improve build procedure
|
||||
* [#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
pmd-compat6/README.md
Normal file
35
pmd-compat6/README.md
Normal 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
pmd-compat6/pom.xml
Normal file
69
pmd-compat6/pom.xml
Normal 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>
|
4
pmd-compat6/src/it/cpd-for-java/invoker.properties
Normal file
4
pmd-compat6/src/it/cpd-for-java/invoker.properties
Normal file
@ -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
pmd-compat6/src/it/cpd-for-java/pom.xml
Normal file
66
pmd-compat6/src/it/cpd-for-java/pom.xml
Normal 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;
|
||||
}
|
||||
}
|
62
pmd-compat6/src/it/cpd-for-java/verify.bsh
Normal file
62
pmd-compat6/src/it/cpd-for-java/verify.bsh
Normal file
@ -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");
|
||||
}
|
2
pmd-compat6/src/it/cpd-for-javascript/invoker.properties
Normal file
2
pmd-compat6/src/it/cpd-for-javascript/invoker.properties
Normal file
@ -0,0 +1,2 @@
|
||||
invoker.goals = verify
|
||||
invoker.buildResult = failure
|
74
pmd-compat6/src/it/cpd-for-javascript/pom.xml
Normal file
74
pmd-compat6/src/it/cpd-for-javascript/pom.xml
Normal 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>
|
@ -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.
|
||||
}
|
36
pmd-compat6/src/it/cpd-for-javascript/verify.bsh
Normal file
36
pmd-compat6/src/it/cpd-for-javascript/verify.bsh
Normal 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 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");
|
||||
}
|
2
pmd-compat6/src/it/cpd-for-jsp/invoker.properties
Normal file
2
pmd-compat6/src/it/cpd-for-jsp/invoker.properties
Normal file
@ -0,0 +1,2 @@
|
||||
invoker.goals = verify
|
||||
invoker.buildResult = failure
|
74
pmd-compat6/src/it/cpd-for-jsp/pom.xml
Normal file
74
pmd-compat6/src/it/cpd-for-jsp/pom.xml
Normal 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
pmd-compat6/src/it/cpd-for-jsp/verify.bsh
Normal file
36
pmd-compat6/src/it/cpd-for-jsp/verify.bsh
Normal 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");
|
||||
}
|
4
pmd-compat6/src/it/pmd-for-java/invoker.properties
Normal file
4
pmd-compat6/src/it/pmd-for-java/invoker.properties
Normal file
@ -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
pmd-compat6/src/it/pmd-for-java/pom.xml
Normal file
66
pmd-compat6/src/it/pmd-for-java/pom.xml
Normal 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!");
|
||||
}
|
||||
}
|
53
pmd-compat6/src/it/pmd-for-java/verify.bsh
Normal file
53
pmd-compat6/src/it/pmd-for-java/verify.bsh
Normal file
@ -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");
|
||||
}
|
2
pmd-compat6/src/it/pmd-for-javascript/invoker.properties
Normal file
2
pmd-compat6/src/it/pmd-for-javascript/invoker.properties
Normal file
@ -0,0 +1,2 @@
|
||||
invoker.goals = verify
|
||||
invoker.buildResult = failure
|
74
pmd-compat6/src/it/pmd-for-javascript/pom.xml
Normal file
74
pmd-compat6/src/it/pmd-for-javascript/pom.xml
Normal 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>
|
@ -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.
|
||||
}
|
33
pmd-compat6/src/it/pmd-for-javascript/verify.bsh
Normal file
33
pmd-compat6/src/it/pmd-for-javascript/verify.bsh
Normal file
@ -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");
|
||||
}
|
2
pmd-compat6/src/it/pmd-for-jsp/invoker.properties
Normal file
2
pmd-compat6/src/it/pmd-for-jsp/invoker.properties
Normal file
@ -0,0 +1,2 @@
|
||||
invoker.goals = verify
|
||||
invoker.buildResult = failure
|
74
pmd-compat6/src/it/pmd-for-jsp/pom.xml
Normal file
74
pmd-compat6/src/it/pmd-for-jsp/pom.xml
Normal 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>
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user