[ant] Make relativizePathsWith a path-like structure
Update documentation
This commit is contained in:
4 files changed
+47
-11
No files matched your search
@@ -79,7 +79,11 @@ The examples below won't repeat this taskdef element, as this is always required
|
||||
</tr>
|
||||
<tr>
|
||||
<td>shortFilenames</td>
|
||||
<td>Places truncated filenames in the report. This can reduce your report file size by 15%-20%.</td>
|
||||
<td>
|
||||
<span class="label label-default">Deprecated</span> Use <code>relativizePathsWith</code>
|
||||
as nested element instead.
|
||||
Places truncated filenames in the report. This can reduce your report file size by 15%-20%.
|
||||
</td>
|
||||
<td>No</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -187,7 +191,7 @@ automatically and the latest language version is used.
|
||||
|
||||
<target name="pmd">
|
||||
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"/>
|
||||
<pmd shortFilenames="true">
|
||||
<pmd>
|
||||
<ruleset>rulesets/java/quickstart.xml</ruleset>
|
||||
<ruleset>config/my-ruleset.xml</ruleset>
|
||||
<fileset dir="/usr/local/j2sdk1.4.1_01/src/">
|
||||
@@ -199,6 +203,12 @@ automatically and the latest language version is used.
|
||||
`fileset` nested element - specify the actual java source files, that PMD should analyze. You can use multiple
|
||||
fileset elements. See [FileSet](https://ant.apache.org/manual/Types/fileset.html) for the syntax and usage.
|
||||
|
||||
`relativizePathsWith` nested element - configures the paths relative to which directories are rendered in the report.
|
||||
This option allows shortening directories in the report; without it, paths are rendered as absolute paths.
|
||||
The option can be repeated, in which case the shortest relative path will be used.
|
||||
It is a [path-like structure](https://ant.apache.org/manual/using.html#path).
|
||||
This option replaces `shortFilenames` since PMD 6.54.0.
|
||||
|
||||
### Language version selection
|
||||
|
||||
PMD selects the language automatically using the file extension. If multiple versions of a language are
|
||||
@@ -410,7 +420,7 @@ An HTML report with the "linkPrefix" and "linePrefix" properties:
|
||||
|
||||
<target name="pmd">
|
||||
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"/>
|
||||
<pmd rulesetfiles="rulesets/java/quickstart.xml" shortFilenames="true">
|
||||
<pmd rulesetfiles="rulesets/java/quickstart.xml">
|
||||
<formatter type="html" toFile="pmd_report.html">
|
||||
<param name="linkPrefix" value="https://maven.apache.org/plugins/maven-pmd-plugin/xref/"/>
|
||||
<param name="linePrefix" value="L"/>
|
||||
@@ -418,6 +428,9 @@ An HTML report with the "linkPrefix" and "linePrefix" properties:
|
||||
<fileset dir="/usr/local/j2sdk1.4.1_01/src/">
|
||||
<include name="java/lang/*.java"/>
|
||||
</fileset>
|
||||
<relativizePathsWith>
|
||||
<pathelement location="/usr/local/j2sdk1.4.1_01/src/"/>
|
||||
</relativizePathsWith>
|
||||
</pmd>
|
||||
</target>
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
package net.sourceforge.pmd.ant;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -12,11 +11,14 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.Task;
|
||||
import org.apache.tools.ant.types.FileSet;
|
||||
import org.apache.tools.ant.types.Path;
|
||||
import org.apache.tools.ant.types.Reference;
|
||||
import org.apache.tools.ant.types.Resource;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.ant.internal.PMDTaskImpl;
|
||||
|
||||
public class PMDTask extends Task {
|
||||
@@ -29,7 +31,7 @@ public class PMDTask extends Task {
|
||||
private boolean failOnRuleViolation;
|
||||
@Deprecated
|
||||
private boolean shortFilenames;
|
||||
private String relativizePathsWith;
|
||||
private final List<Path> relativizePathsWith = new ArrayList<>();
|
||||
private String suppressMarker;
|
||||
private String rulesetFiles;
|
||||
private boolean noRuleSetCompatibility;
|
||||
@@ -77,6 +79,11 @@ public class PMDTask extends Task {
|
||||
}
|
||||
rulesetFiles = getNestedRuleSetFiles();
|
||||
}
|
||||
|
||||
if (shortFilenames) {
|
||||
log("DEPRECATED - Use of shortFilenames is deprecated. Use a nested relativePathsWith element instead.",
|
||||
Project.MSG_WARN);
|
||||
}
|
||||
}
|
||||
|
||||
private String getNestedRuleSetFiles() {
|
||||
@@ -91,6 +98,10 @@ public class PMDTask extends Task {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #addRelativizePathsWith(Path)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setShortFilenames(boolean reportShortNames) {
|
||||
this.shortFilenames = reportShortNames;
|
||||
}
|
||||
@@ -269,15 +280,20 @@ public class PMDTask extends Task {
|
||||
this.noCache = noCache;
|
||||
}
|
||||
|
||||
public void setRelativizePathsWith(String relativizePathsWith) {
|
||||
this.relativizePathsWith = relativizePathsWith;
|
||||
public void addRelativizePathsWith(Path relativizePathsWith) {
|
||||
this.relativizePathsWith.add(relativizePathsWith);
|
||||
}
|
||||
|
||||
public List<Path> getRelativizePathsWith() {
|
||||
return relativizePathsWith;
|
||||
}
|
||||
|
||||
@InternalApi
|
||||
public List<java.nio.file.Path> getRelativizeRoots() {
|
||||
List<java.nio.file.Path> paths = new ArrayList<>();
|
||||
if (relativizePathsWith != null) {
|
||||
for (String file : relativizePathsWith.split(File.pathSeparator)) {
|
||||
paths.add(Paths.get(file));
|
||||
for (Path path : getRelativizePathsWith()) {
|
||||
for (Resource resource : path) {
|
||||
paths.add(Paths.get(resource.toString()));
|
||||
}
|
||||
}
|
||||
return paths;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
package net.sourceforge.pmd.ant;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
@@ -82,6 +84,8 @@ public class PMDTaskTest {
|
||||
actual = actual.replaceAll("\n|\r", "");
|
||||
Assert.assertEquals(IOUtil.normalizePath("src/sample.dummy") + ":0:\tSampleXPathRule:\tTest Rule 2", actual);
|
||||
}
|
||||
|
||||
assertThat(buildRule.getLog(), containsString("DEPRECATED - Use of shortFilenames is deprecated. Use a nested relativePathsWith element instead."));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -36,12 +36,15 @@
|
||||
</target>
|
||||
|
||||
<target name="testRelativizeWith">
|
||||
<pmd noCache="true" relativizePathsWith="${pmd.home}/src/test/resources/net/sourceforge/pmd/ant/">
|
||||
<pmd noCache="true">
|
||||
<ruleset>${pmd.home}/src/test/resources/rulesets/dummy/basic.xml</ruleset>
|
||||
<formatter type="text" toFile="${pmd.home}/target/pmd-ant-test.txt" />
|
||||
<fileset dir="${pmd.home}/src/test/resources/net/sourceforge/pmd/ant/">
|
||||
<include name="**/*dummy"/>
|
||||
</fileset>
|
||||
<relativizePathsWith>
|
||||
<pathelement location="${pmd.home}/src/test/resources/net/sourceforge/pmd/ant"/>
|
||||
</relativizePathsWith>
|
||||
</pmd>
|
||||
</target>
|
||||
|
||||
|
||||
Reference in new issue
Block a user