From 4155d94028729f8768dc775e42f1e943ed833631 Mon Sep 17 00:00:00 2001 From: Romain Pelisse Date: Fri, 23 Sep 2011 17:33:41 +0000 Subject: [PATCH] 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 --- pmd/bin/cpd.sh | 3 ++- pmd/etc/changelog.txt | 4 ++++ pmd/src/net/sourceforge/pmd/cpd/CPD.java | 22 ++++++++++++++++++- .../net/sourceforge/pmd/cpd/JavaLanguage.java | 2 +- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/pmd/bin/cpd.sh b/pmd/bin/cpd.sh index eec53e3a06..422388f935 100644 --- a/pmd/bin/cpd.sh +++ b/pmd/bin/cpd.sh @@ -19,6 +19,7 @@ if [ -z "$1" ]; then echo " $script " 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 ${@} diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index d10514a149..61898428ac 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -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 diff --git a/pmd/src/net/sourceforge/pmd/cpd/CPD.java b/pmd/src/net/sourceforge/pmd/cpd/CPD.java index b8e9fc1d53..dcc51e3f4c 100644 --- a/pmd/src/net/sourceforge/pmd/cpd/CPD.java +++ b/pmd/src/net/sourceforge/pmd/cpd/CPD.java @@ -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(); } diff --git a/pmd/src/net/sourceforge/pmd/cpd/JavaLanguage.java b/pmd/src/net/sourceforge/pmd/cpd/JavaLanguage.java index 5a016bf7e1..658b3017e2 100644 --- a/pmd/src/net/sourceforge/pmd/cpd/JavaLanguage.java +++ b/pmd/src/net/sourceforge/pmd/cpd/JavaLanguage.java @@ -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) {