output directory can be set for yahtml report

-> junit testing doesn't "pollute" parent directory


git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5601 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Xavier Le Vourch
2007-10-29 21:35:58 +00:00
parent 607f5d6dcd
commit 218b023458
3 changed files with 30 additions and 11 deletions

View File

@ -6,24 +6,28 @@ import net.sourceforge.pmd.renderers.YAHTMLRenderer;
public class YAHTMLRendererTest extends AbstractRendererTst {
private static final String OUTPUT_DIR = System.getProperty("java.io.tmpdir");
public AbstractRenderer getRenderer() {
return new YAHTMLRenderer();
return new YAHTMLRenderer(OUTPUT_DIR);
}
private static final String EXPECTED_OUTPUT = "<h3 align=\"center\">The HTML files are located in '" + OUTPUT_DIR + "'.</h3>";
public String getExpected() {
return "<h3 align=\"center\">The HTML files are created above the project directory.</h3>";
return EXPECTED_OUTPUT;
}
public String getExpectedEmpty() {
return "<h3 align=\"center\">The HTML files are created above the project directory.</h3>";
return EXPECTED_OUTPUT;
}
public String getExpectedMultiple() {
return "<h3 align=\"center\">The HTML files are created above the project directory.</h3>";
return EXPECTED_OUTPUT;
}
public String getExpectedError(ProcessingError error) {
return "<h3 align=\"center\">The HTML files are created above the project directory.</h3>";
return EXPECTED_OUTPUT;
}
public static junit.framework.Test suite() {

View File

@ -22,16 +22,18 @@ public class ReportHTMLPrintVisitor extends ReportVisitor {
private StringBuffer packageBuf = new StringBuffer();
private StringBuffer classBuf = new StringBuffer();
private int length;
private String baseDir;
private static final String fs = System.getProperty("file.separator");
public ReportHTMLPrintVisitor(String baseDir) {
this.baseDir = baseDir;
}
/**
* Writes the buffer to file.
*/
private void write(String filename, StringBuffer buf) throws IOException {
String baseDir = ".." + fs; // TODO output destination
BufferedWriter bw = new BufferedWriter(new FileWriter(new File(baseDir + fs + filename)));
bw.write(buf.toString(), 0, buf.length());
bw.close();

View File

@ -9,10 +9,23 @@ import net.sourceforge.pmd.dfa.report.ReportTree;
public class YAHTMLRenderer extends AbstractRenderer {
private String outputDir;
public YAHTMLRenderer() {
// TODO output destination
}
public YAHTMLRenderer(String outputDir) {
this.outputDir = outputDir;
};
public void render(Writer writer, Report report) throws IOException {
ReportTree tree = report.getViolationTree();
tree.getRootNode().accept(new ReportHTMLPrintVisitor());
writer.write("<h3 align=\"center\">The HTML files are created above the project directory.</h3>");
tree.getRootNode().accept(new ReportHTMLPrintVisitor(outputDir==null?"..":outputDir));
writer.write("<h3 align=\"center\">The HTML files are located " +
(outputDir==null?"above the project directory":("in '" + outputDir + '\'')) +
".</h3>");
}
}