From 1e99280cab5057c86c6c5403326bc474418ae2bc Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 4 Jun 2022 10:27:57 +0200 Subject: [PATCH] [core] Fix cli when only --file-list is used Fixes #3999 --- docs/pages/release_notes.md | 2 ++ .../java/net/sourceforge/pmd/cli/PMDParameters.java | 2 +- .../pmd/cli/PMDCommandLineInterfaceTest.java | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 1eb0bab3e3..4ba7666866 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -15,6 +15,8 @@ This is a {{ site.pmd.release_type }} release. ### New and noteworthy ### Fixed Issues +* core + * [#3999](https://github.com/pmd/pmd/issues/3999): \[cli] All files are analyzed despite parameter `--file-list` * java-errorprone * [#3937](https://github.com/pmd/pmd/issues/3937): \[java] AvoidDuplicateLiterals - uncompilable test cases diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java index 18c1da8a28..6b1888db54 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java @@ -224,7 +224,7 @@ public class PMDParameters { */ public PMDConfiguration toConfiguration() { PMDConfiguration configuration = new PMDConfiguration(); - configuration.setInputPaths(this.getSourceDir()); + configuration.setInputPaths(this.getInputPaths()); configuration.setInputFilePath(this.getFileListPath()); configuration.setIgnoreFilePath(this.getIgnoreListPath()); configuration.setInputUri(this.getUri()); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDCommandLineInterfaceTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDCommandLineInterfaceTest.java index 5923717395..897884da7a 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDCommandLineInterfaceTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDCommandLineInterfaceTest.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.cli; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.junit.Assert; @@ -100,4 +102,15 @@ public class PMDCommandLineInterfaceTest { Assert.assertNotNull(PMDCommandLineInterface.buildUsageText()); } + @Test + public void testOnlyFileListOption() { + PMDParameters params = new PMDParameters(); + String[] args = {"--file-list", "pmd.filelist", "-f", "text", "-R", "rulesets/java/quickstart.xml", "--no-cache", }; + PMDCommandLineInterface.extractParameters(params, args, "PMD"); + + PMDConfiguration config = params.toConfiguration(); + assertEquals("pmd.filelist", config.getInputFilePath()); + assertTrue(config.getAllInputPaths().isEmpty()); // no additional input paths + assertNull(config.getInputPaths()); + } }