Skip to content

Commit

Permalink
Include version subcommand (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesbusy authored Dec 18, 2024
1 parent 6e73d41 commit b1895c3
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/1-report-bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ body:
description: |
For easier bug reporting, always give the version of the Plugin Modernizer you are using.
```shell
plugin-modernizer --version
plugin-modernizer version --short
```
validations:
required: true
Expand Down
5 changes: 5 additions & 0 deletions plugin-modernizer-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
BuildMetadataCommand.class,
DryRunCommand.class,
RunCommand.class,
CleanupCommand.class
CleanupCommand.class,
VersionCommand.class
},
mixinStandardHelpOptions = true,
versionProvider = VersionProvider.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public String[] getVersion() throws Exception {
* @throws Exception if the version is not found
*/
public String getMavenVersion() throws Exception {
return getValue("project.version");
return getValue("project.version").trim();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.jenkins.tools.pluginmodernizer.cli.command;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.jenkins.tools.pluginmodernizer.cli.VersionProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;

/**
* Version command
*/
@CommandLine.Command(name = "version", description = "Display version information")
@SuppressFBWarnings(value = "CRLF_INJECTION_LOGS", justification = "safe because versions from pom.xml")
public class VersionCommand implements ICommand {

/**
* Logger
*/
private static final Logger LOG = LoggerFactory.getLogger(VersionCommand.class);

/**
* Display the short version
*/
@CommandLine.Option(
names = {"--short"},
description = "Display the short version")
private boolean shortVersion;

@Override
public Integer call() throws Exception {
VersionProvider versionProvider = new VersionProvider();
if (shortVersion) {
LOG.info(versionProvider.getMavenVersion());
} else {
LOG.info(versionProvider.getVersion()[0].trim());
}
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,27 @@ private static Stream<Arguments> testsPlugins() {
public void testVersion() throws Exception {
LOG.info("Running testVersion");
Invoker invoker = buildInvoker();
InvocationRequest request = buildRequest("--version");
InvocationResult result = invoker.execute(request);
InvocationResult result1 = invoker.execute(buildRequest("--version"));
assertAll(
() -> assertEquals(0, result.getExitCode()),
() -> assertEquals(0, result1.getExitCode()),
() -> assertTrue(Files.readAllLines(outputPath.resolve("stdout.txt")).stream()
.anyMatch(line -> line.matches("plugin modernizer ([a-zA-Z0-9.-_]+) (.*)"))));

Files.delete(outputPath.resolve("stdout.txt"));

InvocationResult result2 = invoker.execute(buildRequest("version"));
assertAll(
() -> assertEquals(0, result2.getExitCode()),
() -> assertTrue(Files.readAllLines(outputPath.resolve("stdout.txt")).stream()
.anyMatch(line -> line.matches("plugin modernizer ([a-zA-Z0-9.-_]+) (.*)"))));

Files.delete(outputPath.resolve("stdout.txt"));

InvocationResult result3 = invoker.execute(buildRequest("version --short"));
assertAll(
() -> assertEquals(0, result3.getExitCode()),
() -> assertTrue(Files.readAllLines(outputPath.resolve("stdout.txt")).stream()
.anyMatch(line -> line.matches("plugin modernizer (.*) (.*)"))));
.anyMatch(line -> line.matches("(.*)\\s*[a-zA-Z0-9.-_]+\\s*"))));
}

@Test
Expand Down

0 comments on commit b1895c3

Please sign in to comment.