From ce49bdd9868e4ed238046ae6ed88c2faf8c51128 Mon Sep 17 00:00:00 2001 From: Xavier Le Vourch Date: Wed, 9 Apr 2008 16:00:10 +0000 Subject: [PATCH] Added file encoding option to CPD GUI, which already existed for the command line and Ant git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6000 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 1 + pmd/src/net/sourceforge/pmd/cpd/GUI.java | 9 +++++++++ pmd/xdocs/cpd.xml | 8 +++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index c01f194bce..8842e22a3a 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -5,6 +5,7 @@ Fixed bug 1928009 - Error using migration ruleset in PMD 4.2 Fixed bug 1932242 - EmptyMethodInAbstractClassShouldBeAbstract false + ruleset.dtd and ruleset_xml_schema.xsd added to jar file in rulesets directory Update RuleSetWriter to handle non-Apache TRAX implementations, add an option to not use XML Namespaces +Added file encoding option to CPD GUI, which already existed for the command line and Ant bin and java14/bin scripts: retroweaver version was not correct in java14/bin scripts support for extra languages in cpd.sh diff --git a/pmd/src/net/sourceforge/pmd/cpd/GUI.java b/pmd/src/net/sourceforge/pmd/cpd/GUI.java index 20155784e9..2a9f49b626 100644 --- a/pmd/src/net/sourceforge/pmd/cpd/GUI.java +++ b/pmd/src/net/sourceforge/pmd/cpd/GUI.java @@ -221,6 +221,7 @@ public class GUI implements CPDListener { private JTextField rootDirectoryField = new JTextField(System.getProperty("user.home")); private JTextField minimumLengthField = new JTextField(Integer.toString(defaultCPDMinimumLength)); + private JTextField encodingField = new JTextField(System.getProperty("file.encoding")); private JTextField timeField = new JTextField(6); private JLabel phaseLabel = new JLabel(); private JProgressBar tokenizingFilesBar = new JProgressBar(); @@ -351,6 +352,13 @@ public class GUI implements CPDListener { helper.add(goButton); helper.add(cxButton); helper.nextRow(); + + helper.addLabel("File encoding (defaults based upon locale):"); + encodingField.setColumns(1); + helper.add(encodingField); + helper.addLabel(""); + helper.addLabel(""); + helper.nextRow(); // settingsPanel.setBorder(BorderFactory.createTitledBorder("Settings")); return settingsPanel; } @@ -510,6 +518,7 @@ public class GUI implements CPDListener { LanguageConfig conf = languageConfigFor((String)languageBox.getSelectedItem()); Language language = conf.languageFor(new LanguageFactory(), p); CPD cpd = new CPD(Integer.parseInt(minimumLengthField.getText()), language); + cpd.setEncoding(encodingField.getText()); cpd.setCpdListener(this); tokenizingFilesBar.setMinimum(0); phaseLabel.setText(""); diff --git a/pmd/xdocs/cpd.xml b/pmd/xdocs/cpd.xml index a6ec312046..cfee78f22e 100644 --- a/pmd/xdocs/cpd.xml +++ b/pmd/xdocs/cpd.xml @@ -50,7 +50,9 @@ will be seen as equivalent. You may want to run PMD with this option off to start with and then switch it on to see what it turns up. There's also a ignoreIdentifiers="true" option that does the same thing with identifiers; i.e., variable names, methods names, and so forth. - The same guidelines apply. Finally, there's an optional language="cpp|java|php|ruby" flag + The same guidelines apply. There's also an encoding option which allows the encoding used + when parsing files to be specified; the default is based upon the locale. + Finally, there's an optional language="cpp|java|php|ruby" flag to select the appropriate language; the default language is "java".

Also, you can get verbose output from this task by running ant with the -v flag; i.e.:

@@ -84,6 +86,10 @@ $ java net.sourceforge.pmd.cpd.CPD --minimum-tokens 100 --files /path/to/other/s you can skip those using --skip-duplicate-files:

$ java net.sourceforge.pmd.cpd.CPD --minimum-tokens 100 --files /path/to/c/source --language cpp --skip-duplicate-files + +

You can also the encoding to use when parsing files:

+ +$ java net.sourceforge.pmd.cpd.CPD --minimum-tokens 100 --files /usr/local/java/src/java --encoding utf-16le

You can also specify a report format - here we're using the XML report: