Skip to content

Commit

Permalink
Merge pull request pmd#4594 from Monits:runtime-completion
Browse files Browse the repository at this point in the history
[cli] Change completion generation to runtime pmd#4594
  • Loading branch information
adangel committed Oct 20, 2023
2 parents 3d0839d + ec3abf0 commit 20a7f61
Show file tree
Hide file tree
Showing 13 changed files with 11 additions and 91 deletions.
2 changes: 1 addition & 1 deletion docs/pages/pmd/userdocs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions docs/pages/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions docs/pages/release_notes_pmd7.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
49 changes: 0 additions & 49 deletions pmd-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
8 changes: 4 additions & 4 deletions pmd-cli/src/main/java/net/sourceforge/pmd/cli/PmdCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import net.sourceforge.pmd.PMDVersion;

import picocli.AutoComplete.GenerateCompletion;
import picocli.CommandLine.Command;
import picocli.CommandLine.IVersionProvider;

Expand All @@ -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 {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

/**
* 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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

/**
* 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> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

/**
* 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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<LanguageVersion>, Iterable<String> {

Expand Down
8 changes: 0 additions & 8 deletions pmd-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
13 changes: 0 additions & 13 deletions pmd-dist/src/main/resources/assemblies/pmd-bin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ private Set<String> 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");
Expand Down

0 comments on commit 20a7f61

Please sign in to comment.