diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index ad55ff8fac..b3eb4433bd 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -21,6 +21,7 @@ Fixed bug 1593292 - The CPD GUI now works with the 'by extension' option selecte Fixed bug 1560944 - CPD now skips symlinks. Fixed bug 1570824 - HTML reports generated on Windows no longer contain double backslashes. This caused problems when viewing those reports with Apache. Fixed bug 1031966 - Re-Implemented CloneMethodMustImplementCloneable as a typeresolution rule. This rule can now detect super classes/interfaces which are cloneable +Fixed bug 1571309 - Optional command line options may be used either before or after the mandatory arguments Applied patch 1551189 - SingularField false + for initialization blocks Applied patch 1573981 - false + in CloneMethodMustImplementCloneable Applied patch 1574988 - false + in OverrideBothEqualsAndHashcode diff --git a/pmd/regress/test/net/sourceforge/pmd/CommandLineOptionsTest.java b/pmd/regress/test/net/sourceforge/pmd/CommandLineOptionsTest.java index 55d4478f20..b8bf9d542b 100644 --- a/pmd/regress/test/net/sourceforge/pmd/CommandLineOptionsTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/CommandLineOptionsTest.java @@ -45,21 +45,29 @@ public class CommandLineOptionsTest extends TestCase { assertEquals("1.5", opt.getTargetJDK()); opt = new CommandLineOptions(new String[]{"file", "format", "ruleset", "-targetjdk", "1.6"}); assertEquals("1.6", opt.getTargetJDK()); + opt = new CommandLineOptions(new String[]{"-targetjdk", "1.6", "file", "format", "ruleset"}); + assertEquals("1.6", opt.getTargetJDK()); } public void testDebug() { CommandLineOptions opt = new CommandLineOptions(new String[]{"file", "format", "basic", "-debug"}); assertTrue(opt.debugEnabled()); + opt = new CommandLineOptions(new String[]{"-debug", "file", "format", "basic"}); + assertTrue(opt.debugEnabled()); } public void testExcludeMarker() { CommandLineOptions opt = new CommandLineOptions(new String[]{"file", "format", "basic", "-excludemarker", "FOOBAR"}); assertEquals("FOOBAR", opt.getExcludeMarker()); + opt = new CommandLineOptions(new String[]{"-excludemarker", "FOOBAR", "file", "format", "basic"}); + assertEquals("FOOBAR", opt.getExcludeMarker()); } public void testShortNames() { CommandLineOptions opt = new CommandLineOptions(new String[]{"file", "format", "basic", "-shortnames"}); assertTrue(opt.shortNamesEnabled()); + opt = new CommandLineOptions(new String[]{"-shortnames", "file", "format", "basic"}); + assertTrue(opt.shortNamesEnabled()); } public void testEncoding() { @@ -67,6 +75,8 @@ public class CommandLineOptionsTest extends TestCase { assertTrue(opt.getEncoding().equals((new InputStreamReader(System.in)).getEncoding())); opt = new CommandLineOptions(new String[]{"file", "format", "ruleset", "-encoding", "UTF-8"}); assertTrue(opt.getEncoding().equals("UTF-8")); + opt = new CommandLineOptions(new String[]{"-encoding", "UTF-8", "file", "format", "ruleset"}); + assertTrue(opt.getEncoding().equals("UTF-8")); } public void testInputFileName() { @@ -111,8 +121,18 @@ public class CommandLineOptionsTest extends TestCase { CommandLineOptions opt = new CommandLineOptions(new String[]{"file", "format", "basic", "-reportfile", "foo.txt"}); assertSame("foo.txt", opt.getReportFile()); + opt = new CommandLineOptions(new String[]{"-reportfile", "foo.txt", "file", "format", "basic"}); + assertSame("foo.txt", opt.getReportFile()); } + public void testCpus() { + + CommandLineOptions opt = new CommandLineOptions(new String[] { "file", "format", "basic", "-cpus", "2" }); + assertEquals(2, opt.getCpus()); + opt = new CommandLineOptions(new String[] { "-cpus", "2", "file", "format", "basic" }); + assertEquals(2, opt.getCpus()); + } + public void testRenderer() { CommandLineOptions opt = new CommandLineOptions(new String[]{"file", "xml", "basic"}); assertTrue(opt.createRenderer() instanceof XMLRenderer); @@ -143,4 +163,13 @@ public class CommandLineOptionsTest extends TestCase { // cool } } + + public void testOptionsFirst(){ + CommandLineOptions opt = new CommandLineOptions(new String[] { "-cpus", "2", "-debug", "file", "format", "basic" }); + assertEquals(2, opt.getCpus()); + assertEquals("file", opt.getInputPath()); + assertEquals("format", opt.getReportFormat()); + assertEquals("rulesets/basic.xml", opt.getRulesets()); + assertTrue(opt.debugEnabled()); + } } diff --git a/pmd/src/net/sourceforge/pmd/CommandLineOptions.java b/pmd/src/net/sourceforge/pmd/CommandLineOptions.java index e92fb2cec1..0b32ad7891 100644 --- a/pmd/src/net/sourceforge/pmd/CommandLineOptions.java +++ b/pmd/src/net/sourceforge/pmd/CommandLineOptions.java @@ -46,10 +46,14 @@ public class CommandLineOptions { if (args == null || args.length < 3) { throw new RuntimeException(usage()); } + int optIndex = 0; + if (args[0].charAt(0) == '-') { + optIndex = args.length - 3; + } - inputPath = args[0]; - reportFormat = args[1]; - ruleSets = new SimpleRuleSetNameMapper(args[2]).getRuleSets(); + inputPath = args[optIndex]; + reportFormat = args[optIndex+1]; + ruleSets = new SimpleRuleSetNameMapper(args[optIndex+2]).getRuleSets(); this.args = args; @@ -92,7 +96,6 @@ public class CommandLineOptions { reportFile = args[++i]; } } - } public Renderer createRenderer() { @@ -186,7 +189,7 @@ public class CommandLineOptions { "For example: " + PMD.EOL + "c:\\> java -jar pmd-" + PMD.VERSION + ".jar c:\\my\\source\\code html unusedcode" + PMD.EOL + PMD.EOL + - "Optional arguments that may be put after the mandatory arguments are: " + PMD.EOL + + "Optional arguments that may be put before or after the mandatory arguments: " + PMD.EOL + "-debug: prints debugging information" + PMD.EOL + "-targetjdk: specifies a language version to target - 1.3, 1.4, 1.5 or 1.6" + PMD.EOL + "-cpus: specifies the number of threads to create" + PMD.EOL +