Skip to content

Commit

Permalink
Merge branch 'pr/3886'
Browse files Browse the repository at this point in the history
  • Loading branch information
oowekyala committed Apr 15, 2022
2 parents 45cb0a0 + 28168ac commit be2618b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/pages/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ This is a {{ site.pmd.release_type }} release.
* java
* [#3889](https://github.com/pmd/pmd/pull/3889): \[java] Catch LinkageError in UselessOverridingMethodRule

* core
* [#3884](https://github.com/pmd/pmd/issues/3884): \[core] XML report via ant task contains XML header twice

### API Changes

### External Contributions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public void start(String baseDir) {
}
renderer = createRenderer();
renderer.setWriter(writer);
renderer.start();
} catch (IOException ioe) {
throw new BuildException(ioe.getMessage(), ioe);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.commons.io.output.WriterOutputStream;
import org.apache.commons.lang3.StringUtils;

import net.sourceforge.pmd.PMD;
import net.sourceforge.pmd.PMDVersion;
import net.sourceforge.pmd.Report;
import net.sourceforge.pmd.RuleViolation;
Expand Down Expand Up @@ -69,7 +68,7 @@ public String defaultFileExtension() {
public void start() throws IOException {
String encoding = getProperty(ENCODING);
String unmarkedEncoding = toUnmarkedEncoding(encoding);
lineSeparator = PMD.EOL.getBytes(unmarkedEncoding);
lineSeparator = System.lineSeparator().getBytes(unmarkedEncoding);

try {
xmlWriter.writeStartDocument(encoding, "1.0");
Expand Down
18 changes: 18 additions & 0 deletions pmd-core/src/test/java/net/sourceforge/pmd/ant/PMDTaskTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,22 @@ public void testWithShortFilenames() throws IOException {
Assert.assertEquals("sample.dummy:0:\tSampleXPathRule:\tTest Rule 2", actual);
}
}

@Test
public void testXmlFormatter() throws IOException {
buildRule.executeTarget("testXmlFormatter");

try (InputStream in = new FileInputStream("target/pmd-ant-xml.xml");
InputStream expectedStream = PMDTaskTest.class.getResourceAsStream("xml/expected-pmd-ant-xml.xml")) {
String actual = IOUtils.toString(in, StandardCharsets.UTF_8);
actual = actual.replaceFirst("timestamp=\"[^\"]+\"", "timestamp=\"\"");
actual = actual.replaceFirst("\\.xsd\" version=\"[^\"]+\"", ".xsd\" version=\"\"");

String expected = IOUtils.toString(expectedStream, StandardCharsets.UTF_8);
expected = expected.replaceFirst("timestamp=\"[^\"]+\"", "timestamp=\"\"");
expected = expected.replaceFirst("\\.xsd\" version=\"[^\"]+\"", ".xsd\" version=\"\"");

Assert.assertEquals(expected, actual);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<pmd xmlns="http://pmd.sourceforge.net/report/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/report/2.0.0 http://pmd.sourceforge.net/report_2_0_0.xsd" version="6.45.0-SNAPSHOT" timestamp="2022-03-31T17:55:43.046">
<file name="sample.dummy">
<violation beginline="0" endline="0" begincolumn="1" endcolumn="0" rule="SampleXPathRule" ruleset="Test Ruleset" package="foo" externalInfoUrl="${pmd.website.baseurl}/rules/dummy/basic.xml#SampleXPathRule" priority="3">
Test Rule 2
</violation>
</file>
</pmd>
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,14 @@
</fileset>
</pmd>
</target>

<target name="testXmlFormatter">
<pmd noCache="true" shortFilenames="true">
<ruleset>${pmd.home}/src/test/resources/rulesets/dummy/basic.xml</ruleset>
<formatter type="xml" toFile="${pmd.home}/target/pmd-ant-xml.xml" />
<fileset dir="${pmd.home}/src/test/resources/net/sourceforge/pmd/ant/src">
<include name="**/*dummy"/>
</fileset>
</pmd>
</target>
</project>

0 comments on commit be2618b

Please sign in to comment.