forked from phoedos/pmd
1.6 added as a valid option for targetjdk
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4724 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -28,6 +28,7 @@ ArrayIsStoredDirectly rule now checks Constructors
|
||||
undo/redo added to text areas in Designer.
|
||||
Better 'create rule XML' panel in Designer.
|
||||
use of entrySet to iterate over Maps.
|
||||
1.6 added as a valid option for targetjdk.
|
||||
|
||||
October 4, 2006 - 3.8:
|
||||
New rules:
|
||||
|
@ -43,6 +43,8 @@ public class CommandLineOptionsTest extends TestCase {
|
||||
assertEquals("1.3", opt.getTargetJDK());
|
||||
opt = new CommandLineOptions(new String[]{"file", "format", "ruleset", "-targetjdk", "1.5"});
|
||||
assertEquals("1.5", opt.getTargetJDK());
|
||||
opt = new CommandLineOptions(new String[]{"file", "format", "ruleset", "-targetjdk", "1.6"});
|
||||
assertEquals("1.6", opt.getTargetJDK());
|
||||
}
|
||||
|
||||
public void testDebug() {
|
||||
|
@ -62,10 +62,10 @@ public class PMDTaskTest extends TestCase {
|
||||
|
||||
public void testInvalidJDK() {
|
||||
PMDTask task = new PMDTask();
|
||||
task.setTargetJDK("1.6");
|
||||
task.setTargetJDK("1.7");
|
||||
try {
|
||||
task.execute();
|
||||
throw new RuntimeException("Should have thrown a BuildException - JDK 1.6 targeted");
|
||||
throw new RuntimeException("Should have thrown a BuildException - JDK 1.7 targeted");
|
||||
} catch (BuildException be) {
|
||||
// cool
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ public class CommandLineOptions {
|
||||
PMD.EOL +
|
||||
"Optional arguments that may be put after the mandatory arguments are: " + PMD.EOL +
|
||||
"-debug: prints debugging information " + PMD.EOL +
|
||||
"-targetjdk: specifies a language version to target - 1.3, 1.4, or 1.5" + PMD.EOL +
|
||||
"-targetjdk: specifies a language version to target - 1.3, 1.4, 1.5 or 1.6" + PMD.EOL +
|
||||
"-encoding: specifies the character set encoding of the source code files PMD is reading (i.e., UTF-8)" + PMD.EOL +
|
||||
"-excludemarker: specifies the String that marks the a line which PMD should ignore; default is NOPMD" + PMD.EOL +
|
||||
"-shortnames: prints shortened filenames in the report" + PMD.EOL +
|
||||
|
@ -233,6 +233,10 @@ public class PMD {
|
||||
if (opts.debugEnabled())
|
||||
System.out.println("In JDK 1.5 mode");
|
||||
pmd.setJavaVersion(SourceType.JAVA_15);
|
||||
} else if (opts.getTargetJDK().equals("1.6")) {
|
||||
if (opts.debugEnabled())
|
||||
System.out.println("In JDK 1.6 mode");
|
||||
pmd.setJavaVersion(SourceType.JAVA_16);
|
||||
} else {
|
||||
if (opts.debugEnabled())
|
||||
System.out.println("In JDK 1.4 mode");
|
||||
|
@ -9,6 +9,7 @@ public final class SourceType implements Comparable {
|
||||
public static final SourceType JAVA_13 = new SourceType("java 1.3");
|
||||
public static final SourceType JAVA_14 = new SourceType("java 1.4");
|
||||
public static final SourceType JAVA_15 = new SourceType("java 1.5");
|
||||
public static final SourceType JAVA_16 = new SourceType("java 1.6");
|
||||
public static final SourceType JSP = new SourceType("jsp");
|
||||
|
||||
private String id;
|
||||
|
41
pmd/src/net/sourceforge/pmd/TargetJDK1_6.java
Normal file
41
pmd/src/net/sourceforge/pmd/TargetJDK1_6.java
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd;
|
||||
|
||||
import net.sourceforge.pmd.ast.JavaCharStream;
|
||||
import net.sourceforge.pmd.ast.JavaParser;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
|
||||
/**
|
||||
* This is an implementation of {@link net.sourceforge.pmd.TargetJDKVersion} for
|
||||
* JDK 1.6.
|
||||
*
|
||||
*/
|
||||
public class TargetJDK1_6 implements TargetJDKVersion {
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.TargetJDKVersion#createParser(InputStream)
|
||||
*/
|
||||
public JavaParser createParser(InputStream in) {
|
||||
JavaParser jp = new JavaParser(new JavaCharStream(in));
|
||||
jp.setJDK15();
|
||||
return jp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.TargetJDKVersion#createParser(Reader)
|
||||
*/
|
||||
public JavaParser createParser(Reader in) {
|
||||
JavaParser jp = new JavaParser(new JavaCharStream(in));
|
||||
jp.setJDK15();
|
||||
return jp;
|
||||
}
|
||||
|
||||
public String getVersionString() {
|
||||
return "1.6";
|
||||
}
|
||||
|
||||
}
|
@ -142,6 +142,10 @@ public class PMDTask extends Task {
|
||||
log("Targeting Java language version 1.5", Project.MSG_VERBOSE);
|
||||
pmd = new PMD();
|
||||
pmd.setJavaVersion(SourceType.JAVA_15);
|
||||
} else if (targetJDK.equals("1.6")) {
|
||||
log("Targeting Java language version 1.6", Project.MSG_VERBOSE);
|
||||
pmd = new PMD();
|
||||
pmd.setJavaVersion(SourceType.JAVA_16);
|
||||
} else if(targetJDK.equals("jsp")){
|
||||
log("Targeting JSP", Project.MSG_VERBOSE);
|
||||
pmd = new PMD();
|
||||
@ -242,8 +246,8 @@ public class PMDTask extends Task {
|
||||
ruleSetFiles = getNestedRuleSetFiles();
|
||||
}
|
||||
|
||||
if (!targetJDK.equals("1.3") && !targetJDK.equals("1.4") && !targetJDK.equals("1.5") && !targetJDK.equals("jsp")) {
|
||||
throw new BuildException("The targetjdk attribute, if used, must be set to either '1.3', '1.4', or '1.5', or 'jsp'");
|
||||
if (!targetJDK.equals("1.3") && !targetJDK.equals("1.4") && !targetJDK.equals("1.5") && !targetJDK.equals("1.6") && !targetJDK.equals("jsp")) {
|
||||
throw new BuildException("The targetjdk attribute, if used, must be set to either '1.3', '1.4', '1.5', '1.6' or 'jsp'");
|
||||
}
|
||||
}
|
||||
|
||||
|
34
pmd/src/net/sourceforge/pmd/parsers/Java16Parser.java
Normal file
34
pmd/src/net/sourceforge/pmd/parsers/Java16Parser.java
Normal file
@ -0,0 +1,34 @@
|
||||
package net.sourceforge.pmd.parsers;
|
||||
|
||||
import net.sourceforge.pmd.ast.JavaCharStream;
|
||||
import net.sourceforge.pmd.ast.JavaParser;
|
||||
import net.sourceforge.pmd.ast.ParseException;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Adapter for the JavaParser, using Java 1.6 grammar.
|
||||
*
|
||||
*/
|
||||
public class Java16Parser implements Parser {
|
||||
|
||||
private JavaParser parser;
|
||||
private String marker;
|
||||
|
||||
public Object parse(Reader source) throws ParseException {
|
||||
parser = new JavaParser(new JavaCharStream(source));
|
||||
parser.setJDK15();
|
||||
parser.setExcludeMarker(marker);
|
||||
return parser.CompilationUnit();
|
||||
}
|
||||
|
||||
public Map getExcludeMap() {
|
||||
return parser.getExcludeMap();
|
||||
}
|
||||
|
||||
public void setExcludeMarker(String marker) {
|
||||
this.marker = marker;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package net.sourceforge.pmd.sourcetypehandlers;
|
||||
|
||||
import net.sourceforge.pmd.parsers.Java16Parser;
|
||||
import net.sourceforge.pmd.parsers.Parser;
|
||||
|
||||
public class Java16Handler extends JavaTypeHandler {
|
||||
|
||||
public Parser getParser() {
|
||||
return new Java16Parser();
|
||||
}
|
||||
|
||||
}
|
@ -31,6 +31,7 @@ public class SourceTypeHandlerBroker {
|
||||
mapSourceTypeOnSourceTypeHandler.put(SourceType.JAVA_13, new Java13Handler());
|
||||
mapSourceTypeOnSourceTypeHandler.put(SourceType.JAVA_14, new Java14Handler());
|
||||
mapSourceTypeOnSourceTypeHandler.put(SourceType.JAVA_15, new Java15Handler());
|
||||
mapSourceTypeOnSourceTypeHandler.put(SourceType.JAVA_16, new Java16Handler());
|
||||
mapSourceTypeOnSourceTypeHandler.put(SourceType.JSP, new JspTypeHandler());
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ import net.sourceforge.pmd.SourceType;
|
||||
import net.sourceforge.pmd.TargetJDK1_3;
|
||||
import net.sourceforge.pmd.TargetJDK1_4;
|
||||
import net.sourceforge.pmd.TargetJDK1_5;
|
||||
import net.sourceforge.pmd.TargetJDK1_6;
|
||||
import net.sourceforge.pmd.TargetJDKVersion;
|
||||
import net.sourceforge.pmd.ast.JavaParser;
|
||||
import net.sourceforge.pmd.cpd.FileFinder;
|
||||
@ -75,8 +76,13 @@ public class Benchmark {
|
||||
List files = new FileFinder().findFilesFrom(srcDir, new SourceFileOrDirectoryFilter(new SourceFileSelector()), true);
|
||||
|
||||
SourceType jdk = SourceType.JAVA_14;
|
||||
if (findOptionalStringValue(args, "--targetjdk", "1.4").equals("1.5")) {
|
||||
String targetjdk = findOptionalStringValue(args, "--targetjdk", "1.4");
|
||||
if (targetjdk.equals("1.3")) {
|
||||
jdk = SourceType.JAVA_13;
|
||||
} else if (targetjdk.equals("1.5")) {
|
||||
jdk = SourceType.JAVA_15;
|
||||
} else if (targetjdk.equals("1.6")) {
|
||||
jdk = SourceType.JAVA_16;
|
||||
}
|
||||
boolean debug = findBooleanSwitch(args, "--debug");
|
||||
boolean parseOnly = findBooleanSwitch(args, "--parse-only");
|
||||
@ -124,8 +130,10 @@ public class Benchmark {
|
||||
jdk = new TargetJDK1_3();
|
||||
} else if (t.equals(SourceType.JAVA_14)) {
|
||||
jdk = new TargetJDK1_4();
|
||||
} else {
|
||||
} else if (t.equals(SourceType.JAVA_15)) {
|
||||
jdk = new TargetJDK1_5();
|
||||
} else {
|
||||
jdk = new TargetJDK1_6();
|
||||
}
|
||||
JavaParser parser = jdk.createParser(new FileReader(file));
|
||||
parser.CompilationUnit();
|
||||
|
@ -10,6 +10,7 @@ import net.sourceforge.pmd.SourceType;
|
||||
import net.sourceforge.pmd.TargetJDK1_3;
|
||||
import net.sourceforge.pmd.TargetJDK1_4;
|
||||
import net.sourceforge.pmd.TargetJDK1_5;
|
||||
import net.sourceforge.pmd.TargetJDK1_6;
|
||||
import net.sourceforge.pmd.ast.Node;
|
||||
import net.sourceforge.pmd.ast.ParseException;
|
||||
import net.sourceforge.pmd.ast.SimpleNode;
|
||||
@ -78,6 +79,10 @@ public class Designer implements ClipboardOwner {
|
||||
public SimpleNode parse(StringReader sr) { return new TargetJDK1_5().createParser(sr).CompilationUnit(); };
|
||||
};
|
||||
|
||||
private static final Parser jdkParser1_6 = new Parser() {
|
||||
public SimpleNode parse(StringReader sr) { return new TargetJDK1_6().createParser(sr).CompilationUnit(); };
|
||||
};
|
||||
|
||||
private static final Parser jspParser = new Parser() {
|
||||
public SimpleNode parse(StringReader sr) { return new JspParser(new JspCharStream(sr)).CompilationUnit(); };
|
||||
};
|
||||
@ -86,6 +91,7 @@ public class Designer implements ClipboardOwner {
|
||||
{ "JDK 1.3", SourceType.JAVA_13, jdkParser1_3 },
|
||||
{ "JDK 1.4", SourceType.JAVA_14, jdkParser1_4 },
|
||||
{ "JDK 1.5", SourceType.JAVA_15, jdkParser1_5 },
|
||||
{ "JDK 1.6", SourceType.JAVA_16, jdkParser1_6 },
|
||||
{ "JSP", SourceType.JSP, jspParser }
|
||||
};
|
||||
|
||||
|
@ -3,6 +3,7 @@ package net.sourceforge.pmd.util.viewer.gui;
|
||||
import net.sourceforge.pmd.TargetJDK1_3;
|
||||
import net.sourceforge.pmd.TargetJDK1_4;
|
||||
import net.sourceforge.pmd.TargetJDK1_5;
|
||||
import net.sourceforge.pmd.TargetJDK1_6;
|
||||
import net.sourceforge.pmd.TargetJDKVersion;
|
||||
import net.sourceforge.pmd.ast.ParseException;
|
||||
import net.sourceforge.pmd.util.viewer.model.ViewerModel;
|
||||
@ -37,6 +38,7 @@ public class MainFrame
|
||||
private JRadioButtonMenuItem jdk13MenuItem;
|
||||
private JRadioButtonMenuItem jdk14MenuItem;
|
||||
private JRadioButtonMenuItem jdk15MenuItem;
|
||||
private JRadioButtonMenuItem jdk16MenuItem;
|
||||
|
||||
/**
|
||||
* constructs and shows the frame
|
||||
@ -89,6 +91,10 @@ public class MainFrame
|
||||
jdk15MenuItem.setSelected(false);
|
||||
group.add(jdk15MenuItem);
|
||||
menu.add(jdk15MenuItem);
|
||||
jdk16MenuItem = new JRadioButtonMenuItem("JDK 1.6");
|
||||
jdk16MenuItem.setSelected(false);
|
||||
group.add(jdk16MenuItem);
|
||||
menu.add(jdk16MenuItem);
|
||||
menuBar.add(menu);
|
||||
setJMenuBar(menuBar);
|
||||
|
||||
@ -103,6 +109,8 @@ public class MainFrame
|
||||
return new TargetJDK1_4();
|
||||
} else if (jdk13MenuItem.isSelected()) {
|
||||
return new TargetJDK1_3();
|
||||
} else if (jdk16MenuItem.isSelected()) {
|
||||
return new TargetJDK1_6();
|
||||
}
|
||||
return new TargetJDK1_5();
|
||||
}
|
||||
|
@ -47,7 +47,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top">targetjdk</td>
|
||||
<td valign="top">Target JDK 1.3, 1.4, 1.5, or jsp. "1.4" is the default.</td>
|
||||
<td valign="top">Target JDK 1.3, 1.4, 1.5, 1.6, or jsp. "1.4" is the default.</td>
|
||||
<td valign="top" align="center">No</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
@ -47,7 +47,7 @@ java net.sourceforge.pmd.PMD /path/to/source text basic,imports,unusedcode
|
||||
<ul>
|
||||
<li><code>-debug</code> - prints a stacktrace if an error is encountered</li>
|
||||
<li><code>-shortnames</code> - puts shortened names in the report. This only works if the filename argument is a single directory</li>
|
||||
<li><code>-targetjdk [1.3|1.4|1.5]</code> - selects either JDK 1.3, 1.4 or 1.5 language compatibility; default is 1.4</li>
|
||||
<li><code>-targetjdk [1.3|1.4|1.5|1.6]</code> - selects either JDK 1.3, 1.4, 1.5 or 1.6 language compatibility; default is 1.4</li>
|
||||
<li><code>-encoding Cp1252</code> - uses the specified encoding for reading the source code files</li>
|
||||
<li><code>-excludemarker NOPMDFORME</code> - uses the specified string of characters as the marker for PMD to ignore. The default string is "NOPMD".</li>
|
||||
<li><code>-linkprefix</code> - path to HTML source, for summary html renderer only.</li>
|
||||
|
Reference in New Issue
Block a user