From 218b023458d41226ecd68d14f3750b2d04c2472c Mon Sep 17 00:00:00 2001 From: Xavier Le Vourch Date: Mon, 29 Oct 2007 21:35:58 +0000 Subject: [PATCH] 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 --- .../pmd/renderers/YAHTMLRendererTest.java | 14 +++++++++----- .../pmd/dfa/report/ReportHTMLPrintVisitor.java | 10 ++++++---- .../pmd/renderers/YAHTMLRenderer.java | 17 +++++++++++++++-- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/pmd/regress/test/net/sourceforge/pmd/renderers/YAHTMLRendererTest.java b/pmd/regress/test/net/sourceforge/pmd/renderers/YAHTMLRendererTest.java index a065228d91..5682412fb6 100644 --- a/pmd/regress/test/net/sourceforge/pmd/renderers/YAHTMLRendererTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/renderers/YAHTMLRendererTest.java @@ -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 = "

The HTML files are located in '" + OUTPUT_DIR + "'.

"; + public String getExpected() { - return "

The HTML files are created above the project directory.

"; + return EXPECTED_OUTPUT; } public String getExpectedEmpty() { - return "

The HTML files are created above the project directory.

"; + return EXPECTED_OUTPUT; } public String getExpectedMultiple() { - return "

The HTML files are created above the project directory.

"; + return EXPECTED_OUTPUT; } public String getExpectedError(ProcessingError error) { - return "

The HTML files are created above the project directory.

"; + return EXPECTED_OUTPUT; } public static junit.framework.Test suite() { diff --git a/pmd/src/net/sourceforge/pmd/dfa/report/ReportHTMLPrintVisitor.java b/pmd/src/net/sourceforge/pmd/dfa/report/ReportHTMLPrintVisitor.java index 95e08d86c6..85c473eb19 100644 --- a/pmd/src/net/sourceforge/pmd/dfa/report/ReportHTMLPrintVisitor.java +++ b/pmd/src/net/sourceforge/pmd/dfa/report/ReportHTMLPrintVisitor.java @@ -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(); diff --git a/pmd/src/net/sourceforge/pmd/renderers/YAHTMLRenderer.java b/pmd/src/net/sourceforge/pmd/renderers/YAHTMLRenderer.java index bad5c8e17b..2c800e2fc1 100644 --- a/pmd/src/net/sourceforge/pmd/renderers/YAHTMLRenderer.java +++ b/pmd/src/net/sourceforge/pmd/renderers/YAHTMLRenderer.java @@ -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("

The HTML files are created above the project directory.

"); + tree.getRootNode().accept(new ReportHTMLPrintVisitor(outputDir==null?"..":outputDir)); + writer.write("

The HTML files are located " + + (outputDir==null?"above the project directory":("in '" + outputDir + '\'')) + + ".

"); + } }