From 5a55af46d35e74ba80a3e2015ad9f3c9d2026def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Thu, 8 Jun 2023 00:28:58 -0300 Subject: [PATCH 1/8] Change completion generation to runtime - We no longer ship a pre-built completion script - A hidden subcommand is available to generate it dynamically based on actually available languages. - We update docs everywhere accordingly. --- docs/pages/pmd/userdocs/installation.md | 2 +- docs/pages/release_notes_pmd7.md | 3 +- pmd-cli/pom.xml | 49 ------------------- .../java/net/sourceforge/pmd/cli/PmdCli.java | 12 +++-- .../cli/commands/internal/PmdRootCommand.java | 4 +- .../src/main/resources/assemblies/pmd-bin.xml | 13 ----- .../pmd/it/BinaryDistributionIT.java | 1 - .../java/rule/design/xml/LawOfDemeter.xml | 36 ++++++++++++++ 8 files changed, 49 insertions(+), 71 deletions(-) diff --git a/docs/pages/pmd/userdocs/installation.md b/docs/pages/pmd/userdocs/installation.md index eaa4115bce..da419f375d 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 <(*path_to_pmd*/bin/pmd generate-completion)` to your `~/.bashrc` / `~/.zshrc` file. ## Running PMD via command line diff --git a/docs/pages/release_notes_pmd7.md b/docs/pages/release_notes_pmd7.md index 3a57818bf4..db850ce333 100644 --- a/docs/pages/release_notes_pmd7.md +++ b/docs/pages/release_notes_pmd7.md @@ -416,11 +416,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 <(*path_to_pmd*/bin/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 2df635e272..a217e76abd 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 1de2edc64a..1b246b86f1 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,13 @@ 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); + + // Don't show autocomplete subcommand in help by default + cli.getSubcommands().get("generate-completion") + .getCommandSpec().usageMessage().hidden(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 ef15d504fd..d596745bfc 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 @@ package net.sourceforge.pmd.cli.commands.internal; import net.sourceforge.pmd.PMDVersion; +import picocli.AutoComplete.GenerateCompletion; import picocli.CommandLine.Command; import picocli.CommandLine.IVersionProvider; @@ -14,7 +15,8 @@ import picocli.CommandLine.IVersionProvider; 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-dist/src/main/resources/assemblies/pmd-bin.xml b/pmd-dist/src/main/resources/assemblies/pmd-bin.xml index a69cde3c66..f33bf93348 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 04f87ac700..bd863c44a3 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 @@ -85,7 +85,6 @@ class BinaryDistributionIT extends AbstractBinaryDistributionTest { 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"); diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/LawOfDemeter.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/LawOfDemeter.xml index c977a3e509..6c6eceac33 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/LawOfDemeter.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/LawOfDemeter.xml @@ -1222,6 +1222,42 @@ class LawOfDemeterFields { return null; } } +]]> + + + + sadasd conditional self assignment of fields + 2 + 12,18 + { + TreeNode root = (TreeNode) tree.getModel().getRoot(); // NOT report + visitAll(tree, new TreePath(root), true); + })); + box.add(new JButton(new AbstractAction("collapse") { + @Override + public void actionPerformed(ActionEvent e) { + TreeNode root = (TreeNode) tree.getModel().getRoot(); // report LawOfDemeter(method chain calls) + visitAll(tree, new TreePath(root), false); + } + })); + box.add(Box.createVerticalGlue()); + JPanel p = new JPanel(new BorderLayout()); + p.add(box, BorderLayout.EAST); + p.add(new JScrollPane(tree)); + return p; + } +} ]]> From 7062d795777b10ff77130cb389425d848e4bf277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Thu, 8 Jun 2023 10:13:46 -0300 Subject: [PATCH 2/8] Fix indentation --- .../sourceforge/pmd/cli/commands/internal/PmdRootCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d596745bfc..169690f98a 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 @@ -16,7 +16,7 @@ import picocli.CommandLine.IVersionProvider; 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, GenerateCompletion.class }) + CpdGuiCommand.class, TreeExportCommand.class, GenerateCompletion.class }) public class PmdRootCommand { } From 2fc4cb9929a396305bccaa466705ec56528bba4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Fri, 9 Jun 2023 11:42:54 -0300 Subject: [PATCH 3/8] Remove completion dependency from dist --- pmd-dist/pom.xml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pmd-dist/pom.xml b/pmd-dist/pom.xml index 9e824be8a3..44c745feff 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 From 7792404e7de53c5a21655df285a067b62333b174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Thu, 19 Oct 2023 20:24:26 -0300 Subject: [PATCH 4/8] Don't hide the completion command --- pmd-cli/src/main/java/net/sourceforge/pmd/cli/PmdCli.java | 4 ---- 1 file changed, 4 deletions(-) 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 1b246b86f1..4fb3877359 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 @@ -16,10 +16,6 @@ public final class PmdCli { final CommandLine cli = new CommandLine(new PmdRootCommand()) .setCaseInsensitiveEnumValuesAllowed(true); - // Don't show autocomplete subcommand in help by default - cli.getSubcommands().get("generate-completion") - .getCommandSpec().usageMessage().hidden(true); - System.exit(cli.execute(args)); } } From 508034d4ddfcb33a9a5bc30473a2188a7f55e7c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Thu, 19 Oct 2023 20:27:04 -0300 Subject: [PATCH 5/8] Assume pmd is in the PATH already when enabling completion --- docs/pages/pmd/userdocs/installation.md | 2 +- docs/pages/release_notes_pmd7.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/pages/pmd/userdocs/installation.md b/docs/pages/pmd/userdocs/installation.md index da419f375d..a4c475980c 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*/bin/pmd generate-completion)` 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_pmd7.md b/docs/pages/release_notes_pmd7.md index db850ce333..a858f2c8c9 100644 --- a/docs/pages/release_notes_pmd7.md +++ b/docs/pages/release_notes_pmd7.md @@ -419,7 +419,7 @@ Finally, we now provide a completion script for Bash/Zsh to further help daily u To use it, edit your `~/.bashrc` / `~/.zshrc` file and add the following line: ``` -source <(*path_to_pmd*/bin/pmd generate-completion) +source <(pmd generate-completion) ``` Contributors: [Juan Martín Sotuyo Dodero](https://github.com/jsotuyod) (@jsotuyod) From 974092b7b946d200a3e184a324404f4dcc691668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Thu, 19 Oct 2023 20:30:25 -0300 Subject: [PATCH 6/8] Update javadoc to reflect new behavior --- .../commands/typesupport/internal/CpdLanguageTypeSupport.java | 3 --- .../commands/typesupport/internal/PmdLanguageTypeSupport.java | 3 --- .../typesupport/internal/PmdLanguageVersionTypeSupport.java | 3 --- 3 files changed, 9 deletions(-) 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 29868b8da7..b0f39fc699 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 @@ -14,9 +14,6 @@ import picocli.CommandLine.ITypeConverter; /** * 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 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 a84dfcff24..db3a1383ee 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 @@ -14,9 +14,6 @@ import picocli.CommandLine.TypeConversionException; /** * 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 implements ITypeConverter, Iterable { 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 2c71afd4b3..abd1c2275d 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 @@ import picocli.CommandLine.TypeConversionException; /** * 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 { From 1951c685896172067e185ce9b10e9cae11651c17 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 20 Oct 2023 11:39:30 +0200 Subject: [PATCH 7/8] [java] Revert unrelated change in LawOfDemeter.xml --- .../java/rule/design/xml/LawOfDemeter.xml | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/LawOfDemeter.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/LawOfDemeter.xml index 6c6eceac33..c977a3e509 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/LawOfDemeter.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/LawOfDemeter.xml @@ -1222,42 +1222,6 @@ class LawOfDemeterFields { return null; } } -]]> - - - - sadasd conditional self assignment of fields - 2 - 12,18 - { - TreeNode root = (TreeNode) tree.getModel().getRoot(); // NOT report - visitAll(tree, new TreePath(root), true); - })); - box.add(new JButton(new AbstractAction("collapse") { - @Override - public void actionPerformed(ActionEvent e) { - TreeNode root = (TreeNode) tree.getModel().getRoot(); // report LawOfDemeter(method chain calls) - visitAll(tree, new TreePath(root), false); - } - })); - box.add(Box.createVerticalGlue()); - JPanel p = new JPanel(new BorderLayout()); - p.add(box, BorderLayout.EAST); - p.add(new JScrollPane(tree)); - return p; - } -} ]]> From ec3abf0ca2e2334fba44379e76838161206ebb92 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 20 Oct 2023 11:45:58 +0200 Subject: [PATCH 8/8] [doc] Update release notes (#4594) --- docs/pages/release_notes.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index f30a145821..3ea0ac3067 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -50,6 +50,8 @@ 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 * miscellaneous * [#4699](https://github.com/pmd/pmd/pull/4699): Make PMD buildable with java 21 * [#4586](https://github.com/pmd/pmd/pull/4586): Use explicit encoding in ruleset xml files @@ -457,6 +459,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 * doc * [#2501](https://github.com/pmd/pmd/issues/2501): \[doc] Verify ANTLR Documentation * [#4294](https://github.com/pmd/pmd/issues/4294): \[doc] Migration Guide for upgrading PMD 6 ➡️ 7