Cleaned up the PMD Ant task some more; many thanks to Philippe for his code
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1850 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
--------> Update ant docs - remove verbose attribute and make a note about -verbose
|
||||
update run.bat to point to pmd-1.05.jar
|
||||
update run.sh to point to pmd-1.05.jar
|
||||
update cpdgui.bat to point to pmd-1.05.jar
|
||||
|
@ -7,6 +7,8 @@ import net.sourceforge.pmd.renderers.TextRenderer;
|
||||
import net.sourceforge.pmd.renderers.XMLRenderer;
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class FormatterTest extends TestCase {
|
||||
|
||||
public void testType() {
|
||||
@ -28,7 +30,7 @@ public class FormatterTest extends TestCase {
|
||||
public void testNull() {
|
||||
Formatter f = new Formatter();
|
||||
assertTrue("Formatter toFile should start off null!", f.isToFileNull());
|
||||
f.setToFile("foo");
|
||||
f.setToFile(new File("foo"));
|
||||
assertFalse("Formatter toFile should not be null!", f.isToFileNull());
|
||||
}
|
||||
|
||||
|
@ -1,28 +0,0 @@
|
||||
package test.net.sourceforge.pmd.ant;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sourceforge.pmd.ant.PathChecker;
|
||||
|
||||
public class PathCheckerTest extends TestCase {
|
||||
|
||||
public void testPathCheckerRelativeWin() {
|
||||
PathChecker pc = new PathChecker("Windows XP");
|
||||
assertTrue(!pc.isAbsolute("foo\\bar.html"));
|
||||
}
|
||||
|
||||
public void testPathCheckerAbsoluteWin() {
|
||||
PathChecker pc = new PathChecker("Windows XP");
|
||||
assertTrue(pc.isAbsolute("c:\\foo\\bar.html"));
|
||||
}
|
||||
|
||||
public void testPathCheckerRelativeNix() {
|
||||
PathChecker pc = new PathChecker("Linux");
|
||||
assertTrue(!pc.isAbsolute("foo/bar.html"));
|
||||
}
|
||||
|
||||
public void testPathCheckerAbsoluteNix() {
|
||||
PathChecker pc = new PathChecker("Linux");
|
||||
assertTrue(pc.isAbsolute("/var/www/html/report.html"));
|
||||
}
|
||||
|
||||
}
|
@ -15,7 +15,7 @@ import java.io.Writer;
|
||||
public class Formatter {
|
||||
|
||||
private Renderer renderer;
|
||||
private String toFile;
|
||||
private File toFile;
|
||||
|
||||
public void setType(String type) {
|
||||
if (type.equals("xml")) {
|
||||
@ -36,7 +36,7 @@ public class Formatter {
|
||||
}
|
||||
}
|
||||
|
||||
public void setToFile(String toFile) {
|
||||
public void setToFile(File toFile) {
|
||||
this.toFile = toFile;
|
||||
}
|
||||
|
||||
@ -45,15 +45,17 @@ public class Formatter {
|
||||
}
|
||||
|
||||
public boolean isToFileNull() {
|
||||
return this.toFile == null;
|
||||
return toFile == null;
|
||||
}
|
||||
|
||||
public Writer getToFileWriter(String baseDir) throws IOException {
|
||||
String outFile = toFile;
|
||||
PathChecker pc = new PathChecker(System.getProperty("os.name"));
|
||||
if (!pc.isAbsolute(toFile)) {
|
||||
outFile = baseDir + System.getProperty("file.separator") + toFile;
|
||||
if (!toFile.isAbsolute()) {
|
||||
return new BufferedWriter(new FileWriter(new File(baseDir + System.getProperty("file.separator") + toFile.getPath())));
|
||||
}
|
||||
return new BufferedWriter(new FileWriter(new File(outFile)));
|
||||
return new BufferedWriter(new FileWriter(toFile));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "file = " + toFile + "; renderer = " + renderer.getClass().getName();
|
||||
}
|
||||
}
|
||||
|
@ -131,6 +131,7 @@ public class PMDTask extends Task {
|
||||
if (!ctx.getReport().isEmpty()) {
|
||||
for (Iterator i = formatters.iterator(); i.hasNext();) {
|
||||
Formatter formatter = (Formatter) i.next();
|
||||
log("Sending a report to " + formatter, Project.MSG_VERBOSE);
|
||||
String buffer = formatter.getRenderer().render(ctx.getReport()) + EOL;
|
||||
try {
|
||||
Writer writer = formatter.getToFileWriter(project.getBaseDir().toString());
|
||||
|
@ -1,17 +0,0 @@
|
||||
package net.sourceforge.pmd.ant;
|
||||
|
||||
public class PathChecker {
|
||||
|
||||
private boolean isWindowsVariant;
|
||||
|
||||
public PathChecker(String osNameProperty) {
|
||||
isWindowsVariant = osNameProperty.toLowerCase().indexOf("windows") != -1;
|
||||
}
|
||||
|
||||
public boolean isAbsolute(String path) {
|
||||
if (!isWindowsVariant) {
|
||||
return path.charAt(0) == '/';
|
||||
}
|
||||
return path.charAt(1) == ':';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user