diff --git a/pmd/etc/build.xml b/pmd/etc/build.xml index ded3cc8cfd..1aadc54a7b 100644 --- a/pmd/etc/build.xml +++ b/pmd/etc/build.xml @@ -58,7 +58,7 @@ - + diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 4b23964f66..2eed9e7dce 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -4,6 +4,7 @@ Fixed bug 672742 - grammar typo was hosing up ASTConstructorDeclaration which wa Fixed bug 674393 - OnlyOneReturn rule no longer counts returns that are inside anonymous inner classes as being inside the containing method. Thx to C. Lamont Gilbert for the bug report. Fixed bug 674420 - AvoidReassigningParametersRule no longer counts parameter field reassignment as a violation. Thx to C. Lamont Gilbert for the bug report. Fixed bug in OverrideBothEqualsAndHashcodeRule - it no longer bails out with a NullPtrException on interfaces that declare a method signature "equals(Object)". Thx to Don Leckie for catching that. +Added an optional Ant task formatter attribute 'isReportFilePathAbsolute'. Thx to Andriy Rozeluk for the feedback. January 22, 2003 - 1.02: Added new rules: ImportFromSamePackageRule, SwitchDensityRule, NullAssignmentRule, UnusedModifierRule, ForLoopShouldBeWhileLoopRule diff --git a/pmd/etc/doing_the_next_pmd_release.txt b/pmd/etc/doing_the_next_pmd_release.txt index b41abba1d6..e8a416b8fc 100644 --- a/pmd/etc/doing_the_next_pmd_release.txt +++ b/pmd/etc/doing_the_next_pmd_release.txt @@ -1,3 +1,5 @@ +UPDATE THE ANT XDOCS WITH isReportFilePathAbsolute ATTRIBUTE! + Move rulesets/tmp.xml somewhere else update run.bat to point to pmd-1.02.jar diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/UnusedImportsRuleTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/UnusedImportsRuleTest.java index f36a4436b7..404ab577f2 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/UnusedImportsRuleTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/rules/UnusedImportsRuleTest.java @@ -5,7 +5,6 @@ */ package test.net.sourceforge.pmd.rules; -import net.sourceforge.pmd.Report; import net.sourceforge.pmd.rules.UnusedImportsRule; public class UnusedImportsRuleTest extends RuleTst { @@ -18,22 +17,15 @@ public class UnusedImportsRuleTest extends RuleTst { } public void test1() throws Throwable { - Report report = process("UnusedImports1.java", rule); - assertEquals(1, report.size()); + runTest("UnusedImports1.java", 1, rule); } - public void test2() throws Throwable { - Report report = process("UnusedImports2.java", rule); - assertTrue(report.isEmpty()); + runTest("UnusedImports2.java", 0, rule); } - public void test3() throws Throwable { - Report report = process("UnusedImports3.java", rule); - assertEquals(2, report.size()); + runTest("UnusedImports3.java", 2, rule); } - public void test4() throws Throwable { - Report report = process("UnusedImports4.java", rule); - assertTrue(report.isEmpty()); + runTest("UnusedImports4.java", 0, rule); } } diff --git a/pmd/src/net/sourceforge/pmd/ant/PMDTask.java b/pmd/src/net/sourceforge/pmd/ant/PMDTask.java index 0ebb67ff6c..2a40160440 100644 --- a/pmd/src/net/sourceforge/pmd/ant/PMDTask.java +++ b/pmd/src/net/sourceforge/pmd/ant/PMDTask.java @@ -22,6 +22,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; +import java.io.Writer; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -31,6 +32,8 @@ public class PMDTask extends Task { public static class Formatter { private Renderer renderer; private String toFile; + private boolean isReportFilePathAbsolute; + public void setType(String type) { if (type.equals("xml")) { renderer = new XMLRenderer(); @@ -43,8 +46,17 @@ public class PMDTask extends Task { } } public void setToFile(String toFile) {this.toFile = toFile;} + + public void setIsReportFilePathAbsolute(boolean value) {this.isReportFilePathAbsolute = value;} public Renderer getRenderer() {return renderer;} - public String getToFile() {return toFile;} + + public Writer getToFileWriter(String baseDir) throws IOException { + String outFile = toFile; + if (!isReportFilePathAbsolute) { + outFile = baseDir + System.getProperty("file.separator") + toFile; + } + return new BufferedWriter(new FileWriter(new File(outFile))); + } } public static class Database { @@ -192,7 +204,7 @@ public class PMDTask extends Task { Formatter formatter = (Formatter)i.next(); String buffer = formatter.getRenderer().render(ctx.getReport()) + EOL; try { - BufferedWriter writer = new BufferedWriter(new FileWriter(new File(project.getBaseDir() + System.getProperty("file.separator") + formatter.getToFile()))); + Writer writer = formatter.getToFileWriter(project.getBaseDir().toString()); writer.write(buffer, 0, buffer.length()); writer.close(); } catch (IOException ioe) {