diff --git a/pmd/src/net/sourceforge/pmd/PMD.java b/pmd/src/net/sourceforge/pmd/PMD.java index 8096b68eac..ef678f1080 100644 --- a/pmd/src/net/sourceforge/pmd/PMD.java +++ b/pmd/src/net/sourceforge/pmd/PMD.java @@ -9,9 +9,8 @@ import net.sourceforge.pmd.ast.JavaParser; import net.sourceforge.pmd.ast.ASTCompilationUnit; import net.sourceforge.pmd.ast.JavaParserVisitor; import net.sourceforge.pmd.ast.ParseException; +import net.sourceforge.pmd.renderers.*; import net.sourceforge.pmd.renderers.Renderer; -import net.sourceforge.pmd.renderers.XMLRenderer; -import net.sourceforge.pmd.renderers.HTMLRenderer; import net.sourceforge.pmd.swingui.PMDViewer; import net.sourceforge.pmd.cpd.FileFinder; import net.sourceforge.pmd.cpd.JavaFileOrDirectoryFilter; @@ -65,7 +64,7 @@ public class PMD { return; } - if (args.length != 3) { + if (args.length < 3) { System.err.println(""); System.err.println("Please pass in a java source code filename or directory, a report format, and a ruleset filename or a comma-delimited string of ruleset filenames." + System.getProperty("line.separator") + "For example: " + System.getProperty("line.separator") + "c:\\> java -jar pmd-0.9.jar c:\\my\\source\\code html rulesets/unusedcode.xml,rulesets/imports.xml"); System.err.println(""); @@ -109,12 +108,15 @@ public class PMD { rsnfe.printStackTrace(); } - Renderer rend = null; if (reportFormat.equals("xml")) { - rend = new XMLRenderer(); + Renderer rend = new XMLRenderer(); + System.out.println(rend.render(ctx.getReport())); + } else if (reportFormat.equals("text")) { + TextRendererForIDEAJ special = new TextRendererForIDEAJ(); + System.out.println(special.render(ctx.getReport(), args[3], args[4])); } else { - rend = new HTMLRenderer(); + Renderer rend = new HTMLRenderer(); + System.out.println(rend.render(ctx.getReport())); } - System.out.println(rend.render(ctx.getReport())); } } diff --git a/pmd/src/net/sourceforge/pmd/renderers/TextRendererForIDEAJ.java b/pmd/src/net/sourceforge/pmd/renderers/TextRendererForIDEAJ.java new file mode 100644 index 0000000000..16d48a9f0e --- /dev/null +++ b/pmd/src/net/sourceforge/pmd/renderers/TextRendererForIDEAJ.java @@ -0,0 +1,25 @@ +/* + * User: tom + * Date: Sep 23, 2002 + * Time: 5:07:40 PM + */ +package net.sourceforge.pmd.renderers; + +import net.sourceforge.pmd.Report; +import net.sourceforge.pmd.RuleViolation; + +import java.util.Iterator; + +public class TextRendererForIDEAJ { + protected String EOL = System.getProperty("line.separator", "\n"); + + public String render(Report report, String classAndMethod, String file) { + StringBuffer buf = new StringBuffer(); + for (Iterator i = report.iterator(); i.hasNext();) { + RuleViolation rv = (RuleViolation) i.next(); + buf.append(rv.getDescription() + EOL); + buf.append(" at " + classAndMethod + "(" + file + ":" + rv.getLine() +")" + EOL); + } + return buf.toString(); + } +}