Merge pull request #4594 from Monits:runtime-completion

[cli] Change completion generation to runtime #4594
This commit is contained in:
Andreas Dangel 2023-10-20 12:46:35 +02:00
commit 20a7f612d8
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3
13 changed files with 11 additions and 91 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -20,55 +20,6 @@
<suppressionsLocation>pmd-cli-checkstyle-suppressions.xml</suppressionsLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-autocompletion-script</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Dpicocli.autocomplete.systemExitOnError</argument>
<argument>-cp</argument>
<classpath />
<argument>picocli.AutoComplete</argument>
<argument>--force</argument>
<argument>--completionScript</argument>
<argument>${project.build.directory}/pmd_completion.sh</argument>
<argument>net.sourceforge.pmd.cli.commands.internal.PmdRootCommand</argument>
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-completion-artifact</id>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/pmd_completion.sh</file>
<type>sh</type>
<classifier>completion</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>

View File

@ -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));
}
}

View File

@ -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 {
}

View File

@ -8,9 +8,6 @@ import net.sourceforge.pmd.lang.LanguageRegistry;
/**
* Provider of candidates / conversion support for supported CPD languages.
*
* <p>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 {

View File

@ -14,9 +14,6 @@ import picocli.CommandLine.TypeConversionException;
/**
* Provider of candidates / conversion support for supported PMD/CPD languages.
*
* <p>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<Language>, Iterable<String> {

View File

@ -8,9 +8,6 @@ import net.sourceforge.pmd.lang.LanguageRegistry;
/**
* Provider of candidates / conversion support for supported PMD languages.
*
* <p>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 {

View File

@ -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<LanguageVersion>, Iterable<String> {

View File

@ -132,14 +132,6 @@
<artifactId>pmd-cli</artifactId>
<version>${project.version}</version>
</dependency>
<!-- include bash/zsh completions -->
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-cli</artifactId>
<version>${project.version}</version>
<type>sh</type>
<classifier>completion</classifier>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-ant</artifactId>

View File

@ -67,19 +67,6 @@
</files>
<dependencySets>
<!-- shell completion goes to shell/ -->
<dependencySet>
<scope>runtime</scope>
<includes>
<include>net.sourceforge.pmd:pmd-cli:sh:completion:*</include>
</includes>
<outputFileNameMapping>pmd-completion.sh</outputFileNameMapping>
<outputDirectory>shell</outputDirectory>
<directoryMode>0755</directoryMode>
<fileMode>0644</fileMode>
<useProjectArtifact>false</useProjectArtifact>
</dependencySet>
<!-- jar dependencies go to lib/ -->
<dependencySet>
<scope>runtime</scope>

View File

@ -88,7 +88,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");