forked from phoedos/pmd
Replaced Jakarta ORO with built-in java.util.regex. I think all these changes are correct - at least, all the tests pass - but if anyone notices anything awry, please let me know... thanks!
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4766 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -1 +1 @@
|
||||
java -cp ../build;../lib/jakarta-oro-2.0.8.jar;../lib/pmd-3.8.jar;../lib/xercesImpl-2.6.2.jar;../lib/xmlParserAPIs-2.6.2.jar;../lib/jaxen-1.1-beta-10.jar net.sourceforge.pmd.util.viewer.Viewer
|
||||
java -cp ../build;../lib/asm-3.0_RC1.jar;../lib/pmd-3.8.jar;../lib/xercesImpl-2.6.2.jar;../lib/xmlParserAPIs-2.6.2.jar;../lib/jaxen-1.1-beta-10.jar net.sourceforge.pmd.util.viewer.Viewer
|
||||
|
@ -1 +1 @@
|
||||
java -cp ../build:../lib/jakarta-oro-2.0.8.jar:../lib/pmd-3.8.jar:../lib/xercesImpl-2.6.2.jar:../lib/xmlParserAPIs-2.6.2.jar:../lib/jaxen-1.1-beta-10.jar net.sourceforge.pmd.util.viewer.Viewer
|
||||
java -cp ../build:../lib/asm-3.0_RC1.jar:../lib/pmd-3.8.jar:../lib/xercesImpl-2.6.2.jar:../lib/xmlParserAPIs-2.6.2.jar:../lib/jaxen-1.1-beta-10.jar net.sourceforge.pmd.util.viewer.Viewer
|
||||
|
@ -14,7 +14,6 @@
|
||||
<pathelement location="${dir.build}" />
|
||||
<fileset dir="${dir.lib}">
|
||||
<include name="jaxen-1.1-beta-10.jar" />
|
||||
<include name="jakarta-oro-2.0.8.jar" />
|
||||
<include name="xercesImpl-2.6.2.jar" />
|
||||
<include name="xmlParserAPIs-2.6.2.jar" />
|
||||
<include name="asm-3.0_RC1.jar" />
|
||||
@ -49,6 +48,11 @@
|
||||
<include name="*.properties" />
|
||||
</fileset>
|
||||
</copy>
|
||||
<copy todir="${dir.build}/test/net/sourceforge/pmd/rules/xml/">
|
||||
<fileset dir="${dir.regress}/test/net/sourceforge/pmd/rules/xml/">
|
||||
<include name="*.xml" />
|
||||
</fileset>
|
||||
</copy>
|
||||
<mkdir dir="${dir.build}/rulesets/releases" />
|
||||
<copy todir="${dir.build}rulesets/releases">
|
||||
<fileset dir="${dir.rulesets}/releases">
|
||||
@ -61,7 +65,7 @@
|
||||
<jar jarfile="${dir.lib}\pmd-${version}.jar" includes="net/sourceforge/pmd/**/**,test/net/sourceforge/pmd/testframework/**/**,rulesets/**" basedir="${dir.build}">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="net.sourceforge.pmd.PMD" />
|
||||
<attribute name="Class-Path" value="jaxen-1.1-beta-10.jar jakarta-oro-2.0.8.jar" />
|
||||
<attribute name="Class-Path" value="jaxen-1.1-beta-10.jar asm-3.0_RC1.jar" />
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
|
@ -6,7 +6,7 @@ esac
|
||||
FILE=$1
|
||||
FORMAT=$2
|
||||
RULESETFILES=$3
|
||||
PMD_CLASSPATH=../lib/pmd-3.8.jar:../lib/jaxen-1.1-beta-10.jar:../lib/jakarta-oro-2.0.8.jar
|
||||
PMD_CLASSPATH=../lib/pmd-3.8.jar:../lib/jaxen-1.1-beta-10.jar:../lib/asm-3.0_RC1.jar
|
||||
if $cygwin; then
|
||||
FILE=`cygpath --windows "$FILE"`
|
||||
PMD_CLASSPATH=`cygpath --path --windows "$PMD_CLASSPATH"`
|
||||
|
@ -1 +1 @@
|
||||
java -cp ../build;../lib/jakarta-oro-2.0.8.jar;../lib/pmd-3.8.jar;../lib/xercesImpl-2.6.2.jar;../lib/xmlParserAPIs-2.6.2.jar;../lib/jaxen-1.1-beta-10.jar net.sourceforge.pmd.util.designer.Designer
|
||||
java -cp ../build;../lib/asm-3.0_RC1.jar;../lib/pmd-3.8.jar;../lib/xercesImpl-2.6.2.jar;../lib/xmlParserAPIs-2.6.2.jar;../lib/jaxen-1.1-beta-10.jar net.sourceforge.pmd.util.designer.Designer
|
||||
|
@ -1,2 +1,2 @@
|
||||
@echo off
|
||||
java -cp %~dp0\..\lib\pmd-3.8.jar;%~dp0\..\lib\jaxen-1.1-beta-10.jar;%~dp0\..\lib\jakarta-oro-2.0.8.jar;%~dp0\..\lib\asm-3.0_RC1.jar;%CLASSPATH% net.sourceforge.pmd.PMD %*
|
||||
java -cp %~dp0\..\lib\pmd-3.8.jar;%~dp0\..\lib\jaxen-1.1-beta-10.jar;%~dp0\..\lib\asm-3.0_RC1.jar;%~dp0\..\lib\asm-3.0_RC1.jar;%CLASSPATH% net.sourceforge.pmd.PMD %*
|
||||
|
@ -6,7 +6,7 @@ set ANT_HOME=c:\ant
|
||||
set PATH=c:\j2sdk1.4.2_04\bin;c:\ant\bin\;%PATH%
|
||||
set CLASSPATH=../build/
|
||||
set CLASSPATH=%CLASSPATH%;../
|
||||
set CLASSPATH=%CLASSPATH%;../lib/jakarta-oro-2.0.8.jar
|
||||
set CLASSPATH=%CLASSPATH%;../lib/asm-3.0_RC1.jar
|
||||
set CLASSPATH=%CLASSPATH%;../lib/jaxen-1.1-beta-10.jar
|
||||
set CLASSPATH=%CLASSPATH%;../lib/xercesImpl-2.6.2.jar
|
||||
set CLASSPATH=%CLASSPATH%;../lib/xmlParserAPIs-2.6.2.jar
|
||||
|
@ -4,6 +4,5 @@ PATH=/usr/local/java/bin/:$PATH
|
||||
ANT_OPTS=-Xmx512m
|
||||
PATH=$MAVEN_HOME/bin:$PATH
|
||||
CVSROOT=:ext:tomcopeland@cvs.sourceforge.net:/cvsroot/pmd
|
||||
CLASSPATH=../build/:../lib/jakarta-oro-2.0.8.jar:../lib/jaxen-1.1-beta-10.jar:/usr/local/junit/junit.jar:/usr/local/ant/lib/ant.jar:/usr/local/ant/lib/ant-nodeps.jar
|
||||
#CLASSPATH=../build/:../lib/jaxen-1.1-beta-10.jar:/usr/local/junit/junit.jar:/usr/local/ant/lib/ant.jar:../lib/asm.jar:../lib/asm-util.jar:../lib/asm-tree.jar:../lib/kasm.jar
|
||||
CLASSPATH=../build/:../lib/asm-3.0_RC1.jar:../lib/jaxen-1.1-beta-10.jar:/usr/local/junit/junit.jar:/usr/local/ant/lib/ant.jar:/usr/local/ant/lib/ant-nodeps.jar
|
||||
export CLASSPATH PATH CVSROOT ANT_OPTS
|
||||
|
@ -19,7 +19,9 @@ Applied patch 1573981 - false + in CloneMethodMustImplementCloneable
|
||||
Applied patch 1574988 - false + in OverrideBothEqualsAndHashcode
|
||||
Applied patch 1583167 - Better test code management. Internal JUnits can now be written in XML's
|
||||
Implemented RFE 1566313 - Command Line now takes minimumpriority attribute to filter out rulesets
|
||||
PMD now requires JDK 1.4 to run. Note that, however, PMD will still analyze code from earlier JDKs.
|
||||
PMD now requires JDK 1.4 to run
|
||||
- PMD will still analyze code from earlier JDKs
|
||||
- PMD now uses the built-in JDK 1.4 regex utils vs Jakarta ORO
|
||||
SummaryHTML Report changes from Brent Fisher - now contains linePrefix to support source output from javadoc using "linksource"
|
||||
Fixed CSVRenderer - had flipped line and priority columns
|
||||
Fixed bug in Ant task - CSV reports were being output as text.
|
||||
|
@ -33,7 +33,7 @@ cp ../LICENSE.txt changelog.txt ~/tmp/pmd-3.8/etc
|
||||
cd ../bin/
|
||||
cp pmd.* cygwin-run.sh build.xml cpd.sh cpdgui.bat designer.* ~/tmp/pmd-3.8/bin
|
||||
cd ../etc/
|
||||
cp ../lib/pmd-3.8.jar ../lib/jakarta-oro-2.0.8.jar ../lib/xmlParserAPIs-2.6.2.jar ../lib/xercesImpl-2.6.2.jar ../lib/jaxen-1.1-beta-10.jar ~/tmp/pmd-3.8/lib/
|
||||
cp ../lib/pmd-3.8.jar ../lib/asm-3.0_RC1.jar ../lib/xmlParserAPIs-2.6.2.jar ../lib/xercesImpl-2.6.2.jar ../lib/jaxen-1.1-beta-10.jar ~/tmp/pmd-3.8/lib/
|
||||
mkdir ~/tmp/pmd-3.8/etc/xslt
|
||||
cp xslt/*.xslt xslt/*.js xslt/*.gif xslt/*.css ~/tmp/pmd-3.8/etc/xslt/
|
||||
cp -R ../target/docs ~/tmp/pmd-3.8
|
||||
|
Binary file not shown.
@ -212,8 +212,8 @@
|
||||
<version>1.1-beta-10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<id>oro</id>
|
||||
<version>2.0.8</version>
|
||||
<id>asm</id>
|
||||
<version>3.0_rc1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xerces</groupId>
|
||||
|
@ -265,7 +265,7 @@ public class GUI implements CPDListener {
|
||||
trimItem.addItemListener(new ItemListener() {
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
AbstractButton button = (AbstractButton)e.getItem();
|
||||
trimLeadingWhitespace = button.isSelected();
|
||||
GUI.this.trimLeadingWhitespace = button.isSelected();
|
||||
}
|
||||
});
|
||||
viewMenu.add(trimItem);
|
||||
|
@ -5,16 +5,13 @@ package net.sourceforge.pmd.cpd;
|
||||
|
||||
import net.sourceforge.pmd.PMD;
|
||||
import net.sourceforge.pmd.util.StringUtil;
|
||||
import org.apache.oro.text.perl.Perl5Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class SimpleRenderer implements Renderer {
|
||||
|
||||
private String separator;
|
||||
private Perl5Util perl5Util;
|
||||
private boolean trimLeadingWhitespace;
|
||||
|
||||
public static final String defaultSeparator = "=====================================================================";
|
||||
|
||||
@ -24,9 +21,7 @@ public class SimpleRenderer implements Renderer {
|
||||
|
||||
public SimpleRenderer(boolean trimLeadingWhitespace) {
|
||||
this(defaultSeparator);
|
||||
if (trimLeadingWhitespace) {
|
||||
perl5Util = new Perl5Util();
|
||||
}
|
||||
this.trimLeadingWhitespace = trimLeadingWhitespace;
|
||||
}
|
||||
|
||||
public SimpleRenderer(String theSeparator) {
|
||||
@ -46,11 +41,9 @@ public class SimpleRenderer implements Renderer {
|
||||
rpt.append(PMD.EOL); // add a line to separate the source from the desc above
|
||||
|
||||
String source = match.getSourceCodeSlice();
|
||||
|
||||
if (perl5Util != null) { // trimming wanted?
|
||||
List list = new ArrayList();
|
||||
perl5Util.split(list, PMD.EOL, source, 0);
|
||||
String[] lines = (String[])list.toArray(new String[list.size()]);
|
||||
|
||||
if (trimLeadingWhitespace) {
|
||||
String[] lines = source.split("[" + PMD.EOL + "]");
|
||||
int trimDepth = StringUtil.maxCommonLeadingWhitespaceForAll(lines);
|
||||
if (trimDepth > 0) {
|
||||
lines = StringUtil.trimStartOn(lines, trimDepth);
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.sourceforge.pmd.jaxen;
|
||||
|
||||
import org.apache.oro.text.perl.Perl5Util;
|
||||
import org.jaxen.Context;
|
||||
import org.jaxen.Function;
|
||||
import org.jaxen.FunctionCallException;
|
||||
@ -8,6 +7,8 @@ import org.jaxen.SimpleFunctionContext;
|
||||
import org.jaxen.XPathFunctionContext;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
public class MatchesFunction implements Function {
|
||||
|
||||
@ -22,12 +23,10 @@ public class MatchesFunction implements Function {
|
||||
}
|
||||
List attributes = (List) args.get(0);
|
||||
Attribute attr = (Attribute) attributes.get(0);
|
||||
String testString = attr.getValue();
|
||||
String regularExpression = '/' + (String) args.get(1) + '/';
|
||||
|
||||
// see http://jakarta.apache.org/oro/api/org/apache/oro/text/regex/package-summary.html#package_description
|
||||
Perl5Util regexp = new Perl5Util();
|
||||
if (regexp.match(regularExpression, testString)) {
|
||||
Pattern check = Pattern.compile((String) args.get(1));
|
||||
Matcher matcher = check.matcher(attr.getValue());
|
||||
if (matcher.find()) {
|
||||
return context.getNodeSet();
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
|
@ -6,7 +6,9 @@ package net.sourceforge.pmd.rules.strings;
|
||||
import net.sourceforge.pmd.AbstractRule;
|
||||
import net.sourceforge.pmd.ast.ASTBlockStatement;
|
||||
import net.sourceforge.pmd.ast.ASTLiteral;
|
||||
import org.apache.oro.text.perl.Perl5Util;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
/**
|
||||
* This rule finds the following:
|
||||
@ -21,7 +23,7 @@ import org.apache.oro.text.perl.Perl5Util;
|
||||
*/
|
||||
public class AppendCharacterWithChar extends AbstractRule {
|
||||
|
||||
private static final String REGEX = "/\"[\\\\]?[\\s\\S]\"/i";
|
||||
private static final Pattern REGEX = Pattern.compile("\"[\\\\]?[\\s\\S]\"");
|
||||
|
||||
public Object visit(ASTLiteral node, Object data) {
|
||||
ASTBlockStatement bs = (ASTBlockStatement) node
|
||||
@ -35,10 +37,8 @@ public class AppendCharacterWithChar extends AbstractRule {
|
||||
return data;
|
||||
}
|
||||
|
||||
// see
|
||||
// http://jakarta.apache.org/oro/api/org/apache/oro/text/regex/package-summary.html#package_description
|
||||
Perl5Util regexp = new Perl5Util();
|
||||
if (regexp.match(REGEX, str)) {
|
||||
Matcher matcher = REGEX.matcher(str);
|
||||
if (matcher.find()) {
|
||||
if (!InefficientStringBuffering.isInStringBufferOpperation(node, 8, "append")) {
|
||||
return data;
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ import net.sourceforge.pmd.ast.ASTVariableDeclaratorId;
|
||||
import net.sourceforge.pmd.ast.Node;
|
||||
import net.sourceforge.pmd.ast.SimpleNode;
|
||||
import net.sourceforge.pmd.symboltable.NameOccurrence;
|
||||
import org.apache.oro.text.perl.Perl5Util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -28,6 +27,8 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
/**
|
||||
* This rule finds StringBuffers which may have been pre-sized incorrectly
|
||||
@ -45,8 +46,6 @@ public class InsufficientStringBufferDeclaration extends AbstractRule {
|
||||
blockParents.add(ASTSwitchStatement.class);
|
||||
}
|
||||
|
||||
private final Perl5Util regexp = new Perl5Util();
|
||||
|
||||
public Object visit(ASTVariableDeclaratorId node, Object data) {
|
||||
|
||||
if (!"StringBuffer".equals(node.getNameDeclaration().getTypeImage())) {
|
||||
@ -185,9 +184,13 @@ public class InsufficientStringBufferDeclaration extends AbstractRule {
|
||||
} else {
|
||||
anticipatedLength += str.length();
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
String str = ((SimpleNode) xn.jjtGetChild(0)).getImage();
|
||||
if(regexp.match("/^[\"']/", str)){
|
||||
Pattern pattern = Pattern.compile("^[\"']");
|
||||
Matcher matcher = pattern.matcher(str);
|
||||
//if(regexp.match("//", str)){
|
||||
if(matcher.find()){
|
||||
anticipatedLength += str.length() - 2;
|
||||
} else if(str.startsWith("0x")){
|
||||
anticipatedLength += 1;
|
||||
@ -220,9 +223,11 @@ public class InsufficientStringBufferDeclaration extends AbstractRule {
|
||||
}
|
||||
} else if (literal.size() == 1) {
|
||||
String str = ((SimpleNode) literal.get(0)).getImage();
|
||||
Pattern pattern = Pattern.compile("^[\"']");
|
||||
Matcher matcher = pattern.matcher(str);
|
||||
if (str == null) {
|
||||
iConstructorLength = 0;
|
||||
} else if (regexp.match("/^['\"]/", str)) {
|
||||
} else if (matcher.find()) {
|
||||
// since it's not taken into account
|
||||
// anywhere. only count the extra 16
|
||||
// characters
|
||||
@ -255,7 +260,9 @@ public class InsufficientStringBufferDeclaration extends AbstractRule {
|
||||
literal = (block.findChildrenOfType(ASTLiteral.class));
|
||||
if (literal.size() == 1) {
|
||||
String str = ((SimpleNode) literal.get(0)).getImage();
|
||||
if (str!= null && regexp.match("/^['\"]/", str)) {
|
||||
Pattern pattern = Pattern.compile("^[\"']");
|
||||
Matcher matcher = pattern.matcher(str);
|
||||
if (str!= null && matcher.find()) {
|
||||
return str.length() - 2; // take off the quotes
|
||||
}
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ try deleting the ruleset.xml file in the .metadata/plugins/net.sourceforge.pmd.e
|
||||
<li>Menu: Select the "Main menu", "Project views", "Editor menu", and "Search results" checkboxes.</li>
|
||||
<li>Program: $JDKPath$\bin\java.exe</li>
|
||||
<li>For the next parameter you'll need to plug in the location of your PMD installation and the rulesets you want to use</li>
|
||||
<li>Parameters: -cp %CLASSPATH%;c:\pmd\lib\pmd-3.8.jar;c:\pmd\lib\jakarta-oro-2.0.8.jar;c:\pmd\lib\jaxen-1.1-beta-10.jar net.sourceforge.pmd.PMD "$FilePath$" ideaj unusedcode,imports "$Sourcepath$" $FileClass$.method $FileName$ </li>
|
||||
<li>Parameters: -cp %CLASSPATH%;c:\pmd\lib\pmd-3.8.jar;c:\pmd\lib\asm-3.0_RC1.jar;c:\pmd\lib\jaxen-1.1-beta-10.jar net.sourceforge.pmd.PMD "$FilePath$" ideaj unusedcode,imports "$Sourcepath$" $FileClass$.method $FileName$ </li>
|
||||
</ul>
|
||||
</ul>
|
||||
<p>That's pretty much it. Now you can right click on a source directory and select PMD, it'll run recursively on the source files, and the results should
|
||||
@ -348,8 +348,8 @@ selecting the "Ask for Directory" checkbox.</p>
|
||||
<LI>Expand the <B>Tools</B> branch (if not already) by clicking on the '<CODE>+</CODE>' directly to its left.</LI>
|
||||
<LI>In the expanded list, select <B>PMD directory</B>. This changes the right side of this dialog to the "tool" form.</LI>
|
||||
<LI>In the "tool" form, enter these parameters:<UL>
|
||||
<LI><B>Parameters:</B> <CODE>-classpath D:\java\pmd-3.8\lib\pmd-3.8.jar;D:\java\pmd-3.8\lib\jakarta-oro-2.0.8.kar;D:\java\pmd-3.8\lib\jaxen-1.1-beta-10.jar;D:\java\pmd-3.8\lib\xmlParserAPIs-2.6.2.jar; D:\java\pmd-3.8\lib\xercesImpl-2.6.2.jar net.sourceforge.pmd.PMD <I><B>$FileDir</B></I> net.sourceforge.pmd.renderers.TextPadRenderer E:\directory\my_pmd_ruleset.xml -debug</CODE>
|
||||
<BR/>(<I>Eliminate the spaces following both '<CODE>jaxen-1.1-beta-10.jar;</CODE>' and '<CODE>xmlParserAPIs-2.6.2.jar;</CODE>' and '<CODE>jakarta-oro-2.0.8.jar;</CODE>'. They are there to prevent the text from exceeding the right side of your screen</I>)</LI>
|
||||
<LI><B>Parameters:</B> <CODE>-classpath D:\java\pmd-3.8\lib\pmd-3.8.jar;D:\java\pmd-3.8\lib\asm-3.0_RC1.jar;D:\java\pmd-3.8\lib\jaxen-1.1-beta-10.jar;D:\java\pmd-3.8\lib\xmlParserAPIs-2.6.2.jar; D:\java\pmd-3.8\lib\xercesImpl-2.6.2.jar net.sourceforge.pmd.PMD <I><B>$FileDir</B></I> net.sourceforge.pmd.renderers.TextPadRenderer E:\directory\my_pmd_ruleset.xml -debug</CODE>
|
||||
<BR/>(<I>Eliminate the spaces following both '<CODE>jaxen-1.1-beta-10.jar;</CODE>' and '<CODE>xmlParserAPIs-2.6.2.jar;</CODE>' and '<CODE>asm-3.0_RC1.jar;</CODE>'. They are there to prevent the text from exceeding the right side of your screen</I>)</LI>
|
||||
<LI><B>Initial Folder:</B> <CODE>$FileDir</CODE></LI>
|
||||
<LI><B>Save all documents first:</B> <CODE>Checked</CODE></LI>
|
||||
<LI><B>Capture output:</B> <CODE>Checked</CODE></LI>
|
||||
|
@ -32,7 +32,7 @@ C:\tmp\pmd-3.8\pmd\bin>
|
||||
<li>If you are want to run PMD without the batch file, you can do a:</li>
|
||||
<source>
|
||||
C:\data\pmd\pmd>java -cp lib\pmd-3.8.jar;lib\xercesImpl-2.6.2.jar;
|
||||
lib\xmlParserAPIs-2.6.2.jar;lib\jaxen-1.1-beta-10.jar;lib\jakarta-oro-2.0.8.jar
|
||||
lib\xmlParserAPIs-2.6.2.jar;lib\jaxen-1.1-beta-10.jar;lib\asm-3.0_RC1.jar
|
||||
net.sourceforge.pmd.PMD
|
||||
c:\j2sdk1.4.1_01\src\java\lang xml
|
||||
rulesets/imports.xml
|
||||
|
Reference in New Issue
Block a user