diff --git a/docs/pages/pmd/userdocs/installation.md b/docs/pages/pmd/userdocs/installation.md index eaa4115bcea..a4c475980c8 100644 --- a/docs/pages/pmd/userdocs/installation.md +++ b/docs/pages/pmd/userdocs/installation.md @@ -47,7 +47,7 @@ On Windows this is achieved by: PMD ships with built-in completion support for Bash / Zsh. -To enable it, simply add `source *path_to_pmd*/shell/pmd-completion.sh` to your `~/.bashrc` / `~/.zshrc` file. +To enable it, simply add `source <(pmd generate-completion)` to your `~/.bashrc` / `~/.zshrc` file. ## Running PMD via command line diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 618a25d0754..bbcba6115e0 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -51,6 +51,7 @@ The remaining section describes the complete release notes for 7.0.0. #### Fixed issues * cli + * [#4594](https://github.com/pmd/pmd/pull/4594): \[cli] Change completion generation to runtime * [#4723](https://github.com/pmd/pmd/issues/4723): \[cli] Launch fails for "bash pmd" * doc * [#3175](https://github.com/pmd/pmd/issues/3175): \[doc] Document language module features @@ -480,6 +481,7 @@ See also [Detailed Release Notes for PMD 7]({{ baseurl }}pmd_release_notes_pmd7. * [#4423](https://github.com/pmd/pmd/pull/4423): \[cli] Fix NPE when only `--file-list` is specified * [#4482](https://github.com/pmd/pmd/issues/4482): \[cli] pmd.bat can only be executed once * [#4484](https://github.com/pmd/pmd/issues/4484): \[cli] ast-dump with no properties produce an NPE + * [#4594](https://github.com/pmd/pmd/pull/4594): \[cli] Change completion generation to runtime * [#4723](https://github.com/pmd/pmd/issues/4723): \[cli] Launch fails for "bash pmd" * doc * [#2501](https://github.com/pmd/pmd/issues/2501): \[doc] Verify ANTLR Documentation diff --git a/docs/pages/release_notes_pmd7.md b/docs/pages/release_notes_pmd7.md index 2de83e17764..bed2e176cbb 100644 --- a/docs/pages/release_notes_pmd7.md +++ b/docs/pages/release_notes_pmd7.md @@ -114,11 +114,10 @@ current progress of the analysis. This can be disabled with the `--no-progress` flag. Finally, we now provide a completion script for Bash/Zsh to further help daily usage. -This script can be found under `shell/pmd-completion.sh` in the binary distribution. To use it, edit your `~/.bashrc` / `~/.zshrc` file and add the following line: ``` -source *path_to_pmd*/shell/pmd-completion.sh +source <(pmd generate-completion) ``` Contributors: [Juan Martín Sotuyo Dodero](https://github.com/jsotuyod) (@jsotuyod) diff --git a/pmd-cli/pom.xml b/pmd-cli/pom.xml index 2df635e272b..a217e76abdb 100644 --- a/pmd-cli/pom.xml +++ b/pmd-cli/pom.xml @@ -20,55 +20,6 @@ pmd-cli-checkstyle-suppressions.xml - - - org.codehaus.mojo - exec-maven-plugin - - - generate-autocompletion-script - package - - exec - - - - - java - - -Dpicocli.autocomplete.systemExitOnError - -cp - - picocli.AutoComplete - --force - --completionScript - ${project.build.directory}/pmd_completion.sh - net.sourceforge.pmd.cli.commands.internal.PmdRootCommand - - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - add-completion-artifact - - attach-artifact - - - - - ${project.build.directory}/pmd_completion.sh - sh - completion - - - - - - diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/PmdCli.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/PmdCli.java index 1de2edc64a1..4fb38773593 100644 --- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/PmdCli.java +++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/PmdCli.java @@ -13,9 +13,9 @@ public final class PmdCli { private PmdCli() { } public static void main(String[] args) { - final int exitCode = new CommandLine(new PmdRootCommand()) - .setCaseInsensitiveEnumValuesAllowed(true) - .execute(args); - System.exit(exitCode); + final CommandLine cli = new CommandLine(new PmdRootCommand()) + .setCaseInsensitiveEnumValuesAllowed(true); + + System.exit(cli.execute(args)); } } diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdRootCommand.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdRootCommand.java index ef15d504fd2..169690f98a0 100644 --- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdRootCommand.java +++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdRootCommand.java @@ -6,6 +6,7 @@ import net.sourceforge.pmd.PMDVersion; +import picocli.AutoComplete.GenerateCompletion; import picocli.CommandLine.Command; import picocli.CommandLine.IVersionProvider; @@ -14,7 +15,8 @@ exitCodeListHeading = "Exit Codes:%n", exitCodeList = { "0:Successful analysis, no violations found", "1:An unexpected error occurred during execution", "2:Usage error, please refer to the command help", "4:Successful analysis, at least 1 violation found" }, - subcommands = { PmdCommand.class, CpdCommand.class, DesignerCommand.class, CpdGuiCommand.class, TreeExportCommand.class }) + subcommands = { PmdCommand.class, CpdCommand.class, DesignerCommand.class, + CpdGuiCommand.class, TreeExportCommand.class, GenerateCompletion.class }) public class PmdRootCommand { } diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/CpdLanguageTypeSupport.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/CpdLanguageTypeSupport.java index 82b0125f520..74bdcd594d0 100644 --- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/CpdLanguageTypeSupport.java +++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/CpdLanguageTypeSupport.java @@ -8,9 +8,6 @@ /** * Provider of candidates / conversion support for supported CPD languages. - * - *

Beware, the help will report this on runtime, and be accurate to available - * modules in the classpath, but autocomplete will include all available at build time. */ public class CpdLanguageTypeSupport extends LanguageTypeSupport { diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/LanguageTypeSupport.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/LanguageTypeSupport.java index e1cf8978c34..0630b125f64 100644 --- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/LanguageTypeSupport.java +++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/LanguageTypeSupport.java @@ -14,9 +14,6 @@ /** * Provider of candidates / conversion support for supported PMD/CPD languages. - * - *

Beware, the help will report this on runtime, and be accurate to available - * modules in the classpath, but autocomplete will include all available at build time. */ public class LanguageTypeSupport implements ITypeConverter, Iterable { diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/PmdLanguageTypeSupport.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/PmdLanguageTypeSupport.java index 6b6332b343f..41023a59b09 100644 --- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/PmdLanguageTypeSupport.java +++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/PmdLanguageTypeSupport.java @@ -8,9 +8,6 @@ /** * Provider of candidates / conversion support for supported PMD languages. - * - *

Beware, the help will report this on runtime, and be accurate to available - * modules in the classpath, but autocomplete will include all available at build time. */ public class PmdLanguageTypeSupport extends LanguageTypeSupport { diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/PmdLanguageVersionTypeSupport.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/PmdLanguageVersionTypeSupport.java index 114bcf64d0d..fdc5f51efac 100644 --- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/PmdLanguageVersionTypeSupport.java +++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/PmdLanguageVersionTypeSupport.java @@ -17,9 +17,6 @@ /** * Provider of candidates for valid language-version combinations. - * - * Beware, the help will report this on runtime, and be accurate to available - * modules in the classpath, but autocomplete will include all available at build time. */ public class PmdLanguageVersionTypeSupport implements ITypeConverter, Iterable { diff --git a/pmd-dist/pom.xml b/pmd-dist/pom.xml index 4a657699bf7..facb2c6dc0e 100644 --- a/pmd-dist/pom.xml +++ b/pmd-dist/pom.xml @@ -132,14 +132,6 @@ pmd-cli ${project.version} - - - net.sourceforge.pmd - pmd-cli - ${project.version} - sh - completion - net.sourceforge.pmd pmd-ant diff --git a/pmd-dist/src/main/resources/assemblies/pmd-bin.xml b/pmd-dist/src/main/resources/assemblies/pmd-bin.xml index a69cde3c66f..f33bf93348b 100644 --- a/pmd-dist/src/main/resources/assemblies/pmd-bin.xml +++ b/pmd-dist/src/main/resources/assemblies/pmd-bin.xml @@ -67,19 +67,6 @@ - - - runtime - - net.sourceforge.pmd:pmd-cli:sh:completion:* - - pmd-completion.sh - shell - 0755 - 0644 - false - - runtime diff --git a/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java b/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java index 86aec7be9b3..86bb126f76b 100644 --- a/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java +++ b/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java @@ -88,7 +88,6 @@ private Set getExpectedFileNames() { result.add(basedir + "bin/pmd"); result.add(basedir + "bin/pmd.bat"); result.add(basedir + "conf/simplelogger.properties"); - result.add(basedir + "shell/pmd-completion.sh"); result.add(basedir + "lib/pmd-core-" + PMDVersion.VERSION + ".jar"); result.add(basedir + "lib/pmd-java-" + PMDVersion.VERSION + ".jar"); result.add(basedir + "sbom/pmd-" + PMDVersion.VERSION + "-cyclonedx.xml");