Modified Ant task to fix bug 673117

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1386 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2003-01-28 20:18:06 +00:00
parent 9135daf8d8
commit 80a89aceb5
5 changed files with 22 additions and 15 deletions

View File

@ -58,7 +58,7 @@
<target name="pmd">
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"/>
<pmd rulesetfiles="rulesets/imports.xml" shortFilenames="true">
<formatter type="html" toFile="foo.html"/>
<formatter type="html" toFile="c:\foo.html" isReportFilePathAbsolute="true"/>
<fileset dir="C:\j2sdk1.4.1_01\src\java\lang\">
<include name="**/*.java"/>
</fileset>

View File

@ -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

View File

@ -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

View File

@ -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);
}
}

View File

@ -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) {