[MPMD-253] PMD links to java Xref fail in aggregated report
Fix Xref link to a Java source in a module: don't use the file section
name but the file name for the link.
diff --git a/src/it/MPMD-253-xref-link-multi-module/invoker.properties b/src/it/MPMD-253-xref-link-multi-module/invoker.properties
new file mode 100644
index 0000000..67f758a
--- /dev/null
+++ b/src/it/MPMD-253-xref-link-multi-module/invoker.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals = clean site
\ No newline at end of file
diff --git a/src/it/MPMD-253-xref-link-multi-module/module/pom.xml b/src/it/MPMD-253-xref-link-multi-module/module/pom.xml
new file mode 100644
index 0000000..ddbb671
--- /dev/null
+++ b/src/it/MPMD-253-xref-link-multi-module/module/pom.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.maven.plugins.pmd.it</groupId>
+ <artifactId>MPMD-253-xref-link-multi-module</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>module</artifactId>
+</project>
diff --git a/src/it/MPMD-253-xref-link-multi-module/module/src/main/java/app/App.java b/src/it/MPMD-253-xref-link-multi-module/module/src/main/java/app/App.java
new file mode 100644
index 0000000..7fd1a89
--- /dev/null
+++ b/src/it/MPMD-253-xref-link-multi-module/module/src/main/java/app/App.java
@@ -0,0 +1,35 @@
+package app;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Hello world!
+ *
+ */
+public class App
+{
+
+ public static void main( String[] args )
+ {
+ System.out.println( "Hello World!" );
+ return; // Unnecessary return.
+ }
+
+}
\ No newline at end of file
diff --git a/src/it/MPMD-253-xref-link-multi-module/pom.xml b/src/it/MPMD-253-xref-link-multi-module/pom.xml
new file mode 100644
index 0000000..b0be09e
--- /dev/null
+++ b/src/it/MPMD-253-xref-link-multi-module/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.plugins.pmd.it</groupId>
+ <artifactId>MPMD-253-xref-link-multi-module</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <description>Tests that Xref link points to correct module source file in aggregate report</description>
+ <modules>
+ <module>module</module>
+ </modules>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-site-plugin</artifactId>
+ <version>@sitePluginVersion@</version>
+ </plugin>
+ </plugins>
+ </build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-pmd-plugin</artifactId>
+ <version>@project.version@</version>
+ <configuration>
+ <rulesets>
+ <ruleset>src/main/config/pmd/rules.xml</ruleset>
+ </rulesets>
+ <aggregate>true</aggregate>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jxr-plugin</artifactId>
+ <version>2.3</version>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>
diff --git a/src/it/MPMD-253-xref-link-multi-module/src/main/config/pmd/rules.xml b/src/it/MPMD-253-xref-link-multi-module/src/main/config/pmd/rules.xml
new file mode 100644
index 0000000..d9d8eb4
--- /dev/null
+++ b/src/it/MPMD-253-xref-link-multi-module/src/main/config/pmd/rules.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<ruleset name="Custom Ruleset"
+ xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
+ <description>Custom rules for MPMD-253</description>
+ <rule ref="category/java/codestyle.xml/UnnecessaryReturn" message="TEST: MPMD-253" />
+</ruleset>
\ No newline at end of file
diff --git a/src/it/MPMD-253-xref-link-multi-module/verify.groovy b/src/it/MPMD-253-xref-link-multi-module/verify.groovy
new file mode 100644
index 0000000..e92ea46
--- /dev/null
+++ b/src/it/MPMD-253-xref-link-multi-module/verify.groovy
@@ -0,0 +1,27 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+File buildLog = new File( basedir, 'build.log' )
+assert buildLog.exists()
+
+File report = new File( basedir, 'target/site/pmd.html' )
+assert report.exists()
+
+assert 1 == report.getText().count( 'xref/app/App.html#L32' )
diff --git a/src/main/java/org/apache/maven/plugins/pmd/PmdReportGenerator.java b/src/main/java/org/apache/maven/plugins/pmd/PmdReportGenerator.java
index 152064a..f13d7c2 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/PmdReportGenerator.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/PmdReportGenerator.java
@@ -115,20 +115,22 @@
String result = filename;
if ( fileInfo != null && fileInfo.getSourceDirectory() != null )
{
- result =
- StringUtils.substring( result, fileInfo.getSourceDirectory().getAbsolutePath().length() + 1 );
+ result = StringUtils.substring( result, fileInfo.getSourceDirectory().getAbsolutePath().length() + 1 );
}
- result = StringUtils.replace( result, "\\", "/" );
-
- if ( aggregate && fileInfo != null && fileInfo.getProject() != null )
- {
- result = fileInfo.getProject().getName() + " - " + result;
- }
-
- return result;
+ return StringUtils.replace( result, "\\", "/" );
}
- private PmdFileInfo determineFileInfo( String filename ) throws IOException
+ private String makeFileSectionName( String filename, PmdFileInfo fileInfo )
+ {
+ if ( aggregate && fileInfo != null && fileInfo.getProject() != null )
+ {
+ return fileInfo.getProject().getName() + " - " + filename;
+ }
+ return filename;
+ }
+
+ private PmdFileInfo determineFileInfo( String filename )
+ throws IOException
{
File canonicalFilename = new File( filename ).getCanonicalFile();
PmdFileInfo fileInfo = files.get( canonicalFilename );
@@ -149,7 +151,7 @@
// prepare the filename
this.currentFilename = shortenFilename( currentFilename, fileInfo );
- sink.text( this.currentFilename );
+ sink.text( makeFileSectionName( this.currentFilename, fileInfo ) );
sink.sectionTitle2_();
sink.table();
@@ -321,7 +323,7 @@
{
String filename = error.getFile();
PmdFileInfo fileInfo = determineFileInfo( filename );
- filename = shortenFilename( filename, fileInfo );
+ filename = makeFileSectionName( shortenFilename( filename, fileInfo ), fileInfo );
sink.tableRow();
sink.tableCell();