Skip to content

Commit 5e42898

Browse files
committed
[MPMD-296] - Copy ruleset files into a subdirectory of target
* Add new property "rulesetsTargetDirectory" * Update existing tests for the new default behavior * Add integration test, to verify backwards comaptible configuration
1 parent b46470f commit 5e42898

29 files changed

+271
-18
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
invoker.goals.1 = clean verify
19+
invoker.profiles.1 =
20+
# no clean for the next executions, otherwise we can't verify
21+
invoker.goals.2 = verify
22+
invoker.profiles.2 = customTargetOld
23+
invoker.goals.3 = verify
24+
invoker.profiles.3 = customTarget
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
-->
21+
22+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
<groupId>org.apache.maven.plugins.pmd.it</groupId>
26+
<artifactId>MPMD-296-rulesetsTargetDirectory</artifactId>
27+
<version>1.0.0-SNAPSHOT</version>
28+
29+
<description>Verifies that the resolved and extracted rulesets are in the correct target directory</description>
30+
31+
<build>
32+
<plugins>
33+
<plugin>
34+
<groupId>org.apache.maven.plugins</groupId>
35+
<artifactId>maven-pmd-plugin</artifactId>
36+
<version>@project.version@</version>
37+
<configuration>
38+
<failOnViolation>false</failOnViolation>
39+
</configuration>
40+
<executions>
41+
<execution>
42+
<id>pmd-check</id>
43+
<goals>
44+
<goal>check</goal>
45+
</goals>
46+
</execution>
47+
</executions>
48+
</plugin>
49+
</plugins>
50+
</build>
51+
52+
<profiles>
53+
<profile>
54+
<id>customTargetOld</id>
55+
<build>
56+
<plugins>
57+
<plugin>
58+
<groupId>org.apache.maven.plugins</groupId>
59+
<artifactId>maven-pmd-plugin</artifactId>
60+
<configuration>
61+
<rulesetsTargetDirectory>${project.build.directory}</rulesetsTargetDirectory>
62+
</configuration>
63+
</plugin>
64+
</plugins>
65+
</build>
66+
</profile>
67+
<profile>
68+
<id>customTarget</id>
69+
<build>
70+
<plugins>
71+
<plugin>
72+
<groupId>org.apache.maven.plugins</groupId>
73+
<artifactId>maven-pmd-plugin</artifactId>
74+
<configuration>
75+
<rulesetsTargetDirectory>${project.build.directory}/pmd-custom</rulesetsTargetDirectory>
76+
</configuration>
77+
</plugin>
78+
</plugins>
79+
</build>
80+
</profile>
81+
</profiles>
82+
</project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package test;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
public class MyClass
23+
{
24+
25+
public static void main( String[] args )
26+
{
27+
;
28+
return;
29+
}
30+
31+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
/*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
*/
20+
21+
File buildLog = new File( basedir, 'build.log' )
22+
assert buildLog.exists()
23+
24+
// default configuration
25+
File defaultRuleset = new File( basedir, 'target/pmd/rulesets/maven-pmd-plugin-default.xml' )
26+
assert defaultRuleset.exists()
27+
28+
// backwards compatible configuration (profile customTargetOld)
29+
File customTargetOld = new File( basedir, 'target/maven-pmd-plugin-default.xml' )
30+
assert customTargetOld.exists()
31+
32+
// custom configuration (profile customTarget)
33+
File customTarget = new File( basedir, 'target/pmd-custom/maven-pmd-plugin-default.xml' )
34+
assert customTarget.exists()

src/it/multi-module/verify.bsh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ for ( String path : paths )
5959

6060

6161
// check PMD rulesets target copy
62-
File rule = new File( basedir, "mod-1/target/latin-1.xml" );
62+
File rule = new File( basedir, "mod-1/target/pmd/rulesets/latin-1.xml" );
6363
String nonascii = "-CHARS: \u00C4\u00D6\u00DC\u00E4\u00F6\u00FC\u00DF\u00BC\u00BD\u00BE\u00A4";
6464
String content = FileUtils.fileRead( rule, "ISO-8859-1" );
6565
if ( content.indexOf( nonascii ) < 0 )
6666
{
6767
throw new IOException( "non-ascii content corrupted in Latin1." );
6868
}
69-
rule = new File( basedir, "mod-1/target/utf-8.xml" );
69+
rule = new File( basedir, "mod-1/target/pmd/rulesets/utf-8.xml" );
7070
content = FileUtils.fileRead( rule, "UTF-8" );
7171
if ( content.indexOf( nonascii ) < 0 )
7272
{

src/main/java/org/apache/maven/plugins/pmd/PmdReport.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,15 @@ public class PmdReport
250250
@Parameter( property = "pmd.renderViolationsByPriority", defaultValue = "true" )
251251
private boolean renderViolationsByPriority = true;
252252

253+
/**
254+
* Before PMD is executed, the configured rulesets are resolved and copied into this directory.
255+
* <p>Note: Before 3.13.0, this was by default ${project.build.directory}.
256+
*
257+
* @since 3.13.0
258+
*/
259+
@Parameter( property = "pmd.rulesetsTargetDirectory", defaultValue = "${project.build.directory}/pmd/rulesets" )
260+
private File rulesetsTargetDirectory;
261+
253262
@Component
254263
private DependencyResolver dependencyResolver;
255264

@@ -396,7 +405,7 @@ private void executePmd()
396405
// configure ResourceManager
397406
locator.addSearchPath( FileResourceLoader.ID, project.getFile().getParentFile().getAbsolutePath() );
398407
locator.addSearchPath( "url", "" );
399-
locator.setOutputDirectory( targetDirectory );
408+
locator.setOutputDirectory( rulesetsTargetDirectory );
400409

401410
renderer = new PmdCollectingRenderer();
402411
PMDConfiguration pmdConfiguration = getPMDConfiguration();

src/test/java/org/apache/maven/plugins/pmd/CpdViolationCheckMojoTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void testNotFailOnViolation()
6969

7070
testPom =
7171
new File( getBasedir(),
72-
"src/test/resources/unit/default-configuration/pmd-check-notfailonviolation-plugin-config.xml" );
72+
"src/test/resources/unit/default-configuration/cpd-check-notfailonviolation-plugin-config.xml" );
7373
final CpdViolationCheckMojo cpdViolationMojo = (CpdViolationCheckMojo) lookupMojo( "cpd-check", testPom );
7474
cpdViolationMojo.execute();
7575

src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void testDefaultConfiguration()
7474
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
7575

7676
// check if the rulesets, that have been applied, have been copied
77-
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/maven-pmd-plugin-default.xml" );
77+
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/maven-pmd-plugin-default.xml" );
7878
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
7979

8080
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/site/pmd.html" );
@@ -187,13 +187,13 @@ public void testJavascriptConfiguration()
187187
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
188188

189189
// these are the rulesets, that have been applied...
190-
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/bestpractices.xml" );
190+
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/bestpractices.xml" );
191191
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
192192

193-
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/codestyle.xml" );
193+
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/codestyle.xml" );
194194
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
195195

196-
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/errorprone.xml" );
196+
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/errorprone.xml" );
197197
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
198198

199199
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/site/pmd.html" );
@@ -250,18 +250,19 @@ public void testFileURL()
250250
File generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/pmd.xml" );
251251
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
252252

253-
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/basic.xml" );
253+
// the resolved and extracted rulesets
254+
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/basic.xml" );
254255
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
255256

256-
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/imports.xml" );
257+
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/imports.xml" );
257258
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
258259

259-
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/unusedcode.xml" );
260+
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/unusedcode.xml" );
260261
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
261262

262263
generatedFile =
263264
new File( getBasedir(),
264-
"target/test/unit/default-configuration/target/export_format_pmd_language_java_name_Sonar_2520way.xml" );
265+
"target/test/unit/default-configuration/target/pmd/rulesets/export_format_pmd_language_java_name_Sonar_2520way.xml" );
265266
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
266267

267268
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/site/pmd.html" );
@@ -306,7 +307,7 @@ public void testCustomConfiguration()
306307
File generatedFile = new File( getBasedir(), "target/test/unit/custom-configuration/target/pmd.csv" );
307308
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
308309

309-
generatedFile = new File( getBasedir(), "target/test/unit/custom-configuration/target/custom.xml" );
310+
generatedFile = new File( getBasedir(), "target/test/unit/custom-configuration/target/pmd/rulesets/custom.xml" );
310311
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
311312

312313
generatedFile = new File( getBasedir(), "target/test/unit/custom-configuration/target/site/pmd.html" );
@@ -528,19 +529,19 @@ public void testJspConfiguration()
528529
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
529530

530531
// these are the rulesets, that have been applied...
531-
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/bestpractices.xml" );
532+
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/bestpractices.xml" );
532533
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
533534

534-
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/codestyle.xml" );
535+
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/codestyle.xml" );
535536
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
536537

537-
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/design.xml" );
538+
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/design.xml" );
538539
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
539540

540-
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/errorprone.xml" );
541+
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/errorprone.xml" );
541542
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
542543

543-
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/security.xml" );
544+
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/security.xml" );
544545
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
545546

546547
generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/site/pmd.html" );

src/test/resources/unit/custom-configuration/custom-configuration-plugin-config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ under the License.
3636
<project implementation="org.apache.maven.plugins.pmd.stubs.CustomConfigurationMavenProjectStub"/>
3737
<outputDirectory>${basedir}/target/test/unit/custom-configuration/target/site</outputDirectory>
3838
<targetDirectory>${basedir}/target/test/unit/custom-configuration/target</targetDirectory>
39+
<rulesetsTargetDirectory>${basedir}/target/test/unit/custom-configuration/target/pmd/rulesets</rulesetsTargetDirectory>
3940
<format>csv</format>
4041
<linkXRef>true</linkXRef>
4142
<xrefLocation>${basedir}/target/test/unit/custom-configuration/target/site/xref</xrefLocation>

src/test/resources/unit/custom-configuration/pmd-check-exception-test-plugin-config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ under the License.
3535
<configuration>
3636
<sourceDirectory>${basedir}/src/test/resources/unit/custom-configuration</sourceDirectory>
3737
<targetDirectory>${basedir}/target/test/unit/custom-configuration/target</targetDirectory>
38+
<rulesetsTargetDirectory>${basedir}/target/test/unit/custom-configuration/target/pmd/rulesets</rulesetsTargetDirectory>
3839
<failOnViolation>false</failOnViolation>
3940
<language>java</language>
4041
</configuration>

0 commit comments

Comments
 (0)