forked from phoedos/pmd
merge from trunk:
relative paths for custom rulesets are now handled properly when ant is called from a different directory using the "-f" option. git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6448 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
parent
69ff09410a
commit
037cf154f7
@ -7,7 +7,7 @@ import java.util.StringTokenizer;
|
||||
public class SimpleRuleSetNameMapper {
|
||||
|
||||
private StringBuffer rulesets = new StringBuffer();
|
||||
private Map<String, String> nameMap = new HashMap<String, String>();
|
||||
protected Map<String, String> nameMap = new HashMap<String, String>();
|
||||
|
||||
public SimpleRuleSetNameMapper(String ruleString) {
|
||||
populateNameMap();
|
||||
@ -25,7 +25,7 @@ public class SimpleRuleSetNameMapper {
|
||||
return rulesets.toString();
|
||||
}
|
||||
|
||||
private void check(String name) {
|
||||
protected void check(String name) {
|
||||
if (name.indexOf("rulesets") == -1 && nameMap.containsKey(name)) {
|
||||
append(nameMap.get(name));
|
||||
} else {
|
||||
@ -33,7 +33,7 @@ public class SimpleRuleSetNameMapper {
|
||||
}
|
||||
}
|
||||
|
||||
private void append(String name) {
|
||||
protected void append(String name) {
|
||||
if (rulesets.length() > 0) {
|
||||
rulesets.append(',');
|
||||
}
|
||||
|
@ -157,8 +157,24 @@ public class PMDTask extends Task {
|
||||
createLongAuxClasspath().setRefid(r);
|
||||
}
|
||||
|
||||
private class AntTaskNameMapper extends SimpleRuleSetNameMapper {
|
||||
public AntTaskNameMapper(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
protected void check(String name) {
|
||||
if (name.indexOf("rulesets") == -1 && nameMap.containsKey(name)) {
|
||||
append(nameMap.get(name));
|
||||
} else {
|
||||
// substitute env variables/properties
|
||||
append(getProject().replaceProperties(name));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void doTask(){
|
||||
ruleSetFiles = new SimpleRuleSetNameMapper(ruleSetFiles).getRuleSets();
|
||||
ruleSetFiles = new AntTaskNameMapper(ruleSetFiles).getRuleSets();
|
||||
|
||||
ClassLoader cl;
|
||||
if (classpath == null) {
|
||||
@ -168,14 +184,23 @@ public class PMDTask extends Task {
|
||||
log("Using the AntClassLoader", Project.MSG_VERBOSE);
|
||||
cl = new AntClassLoader(getProject(), classpath);
|
||||
}
|
||||
/*
|
||||
* 'basedir' is added to the path to make sure that relative paths
|
||||
* such as "<ruleset>resources/custom_ruleset.xml</ruleset>" still
|
||||
* work when ant is invoked from a different directory using "-f"
|
||||
*/
|
||||
String extraPath = getProject().getBaseDir().toString();
|
||||
|
||||
if (auxClasspath != null) {
|
||||
log("Using auxclasspath: " + auxClasspath, Project.MSG_VERBOSE);
|
||||
extraPath = auxClasspath.toString() + File.pathSeparator + extraPath;
|
||||
}
|
||||
|
||||
try {
|
||||
cl = new ClasspathClassLoader(auxClasspath.toString(), cl);
|
||||
cl = new ClasspathClassLoader(extraPath, cl);
|
||||
} catch (IOException ioe) {
|
||||
throw new BuildException(ioe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
final ClassLoader classLoader = cl;
|
||||
RuleSetFactory ruleSetFactory = new RuleSetFactory() {
|
||||
@ -340,18 +365,6 @@ public class PMDTask extends Task {
|
||||
ruleSetFiles = getNestedRuleSetFiles();
|
||||
}
|
||||
|
||||
// convert relative paths and substitute env variables/properties
|
||||
final StringBuffer sb = new StringBuffer();
|
||||
for(String s: ruleSetFiles.split(",")) {
|
||||
Path p = new Path(getProject());
|
||||
p.setPath(getProject().replaceProperties(s));
|
||||
if (sb.length() > 0) {
|
||||
sb.append(',');
|
||||
}
|
||||
sb.append(p);
|
||||
}
|
||||
ruleSetFiles = sb.toString();
|
||||
|
||||
if (!targetJDK.equals("1.3") && !targetJDK.equals("1.4") && !targetJDK.equals("1.5") && !targetJDK.equals("1.6") && !targetJDK.equals("1.7") && !targetJDK.equals("jsp")) {
|
||||
throw new BuildException("The targetjdk attribute, if used, must be set to either '1.3', '1.4', '1.5', '1.6', '1.7' or 'jsp'");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user