apply patch 3175832 from Cd-MaN: Add options to to the CPD command line task.
While applying the patch, I discover that properties where never really used and not passed down to the language implementation. In order to fix that and keep the loose coupling we currently have, I used the system properties. Also did isolate that in a separate function and did a (little) code cleaning. git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.3.x@7317 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -19,6 +19,7 @@ if [ -z "$1" ]; then
|
||||
echo " $script <directory>"
|
||||
exit 1
|
||||
fi
|
||||
shift
|
||||
|
||||
# OS specific support. $var _must_ be set to either true or false.
|
||||
cygwin=false;
|
||||
@ -82,4 +83,4 @@ if $cygwin; then
|
||||
DIRECTORY=`cygpath --windows "$DIRECTORY"`
|
||||
fi
|
||||
|
||||
java $HEAPSIZE -cp $classpath net.sourceforge.pmd.cpd.CPD --minimum-tokens $MINIMUM_TOKENS --files $DIRECTORY --language $LANGUAGE
|
||||
java $HEAPSIZE -cp $classpath net.sourceforge.pmd.cpd.CPD --minimum-tokens $MINIMUM_TOKENS --files $DIRECTORY --language $LANGUAGE ${@}
|
||||
|
@ -1,3 +1,7 @@
|
||||
?? ??, 201? - 4.3:
|
||||
|
||||
Add options --ignore-literals and --ignore-identifiers to the CPD command line task, thanks to Cd-Man
|
||||
|
||||
September 14, 2011 - 4.2.6:
|
||||
Fixed bug 2920057 - False + : CloseRessource whith an external getter
|
||||
Fixed bug 1808110 - Fixed performance issue on PreserveStackTrace
|
||||
|
@ -10,6 +10,7 @@ import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@ -154,22 +155,41 @@ public class CPD {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
private static void setSystemProperties(String[] args) {
|
||||
boolean ignoreLiterals = findBooleanSwitch(args, "--ignore-literals"),
|
||||
ignoreIdentifiers = findBooleanSwitch(args, "--ignore-identifiers");
|
||||
Properties properties = System.getProperties();
|
||||
if (ignoreLiterals) {
|
||||
properties.setProperty(JavaTokenizer.IGNORE_LITERALS, "true");
|
||||
}
|
||||
if (ignoreIdentifiers) {
|
||||
properties.setProperty(JavaTokenizer.IGNORE_IDENTIFIERS, "true");
|
||||
}
|
||||
System.setProperties(properties);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length == 0) {
|
||||
usage();
|
||||
}
|
||||
|
||||
try {
|
||||
boolean skipDuplicateFiles = findBooleanSwitch(args, "--skip-duplicate-files");
|
||||
|
||||
String languageString = findOptionalStringValue(args, "--language", "java");
|
||||
String formatString = findOptionalStringValue(args, "--format", "text");
|
||||
String encodingString = findOptionalStringValue(args, "--encoding", System.getProperty("file.encoding"));
|
||||
int minimumTokens = Integer.parseInt(findRequiredStringValue(args, "--minimum-tokens"));
|
||||
LanguageFactory f = new LanguageFactory();
|
||||
// Pass extra paramteters as System properties to allow language
|
||||
// implementation to retrieve their associate values...
|
||||
setSystemProperties(args);
|
||||
|
||||
Language language = f.createLanguage(languageString);
|
||||
Renderer renderer = CPD.getRendererFromString(formatString, encodingString);
|
||||
CPD cpd = new CPD(minimumTokens, language);
|
||||
cpd.setEncoding(encodingString);
|
||||
|
||||
boolean skipDuplicateFiles = findBooleanSwitch(args, "--skip-duplicate-files");
|
||||
if (skipDuplicateFiles) {
|
||||
cpd.skipDuplicates();
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import java.util.Properties;
|
||||
|
||||
public class JavaLanguage extends AbstractLanguage {
|
||||
public JavaLanguage() {
|
||||
this(new Properties());
|
||||
this(System.getProperties());
|
||||
}
|
||||
|
||||
public JavaLanguage(Properties properties) {
|
||||
|
Reference in New Issue
Block a user