[cli] Display a PMD banner and more detailed version info

Generated via https://www.asciiart.eu/image-to-ascii
from docs/images/logo/pmd-logo-300px.png
This commit is contained in:
Andreas Dangel 2024-02-29 18:47:29 +01:00
parent 80db40b6a2
commit c2a215d7b5
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3
5 changed files with 75 additions and 11 deletions

View File

@ -5,8 +5,11 @@
package net.sourceforge.pmd.cli.commands.internal;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
import net.sourceforge.pmd.PMDVersion;
import net.sourceforge.pmd.cli.internal.CliExitCode;
import net.sourceforge.pmd.cli.internal.PmdBanner;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.Option;
@ -26,6 +29,8 @@ public abstract class AbstractPmdSubcommand implements Callable<Integer> {
@Override
public final Integer call() throws Exception {
System.err.println(PmdBanner.loadBanner().stream().collect(Collectors.joining(System.lineSeparator())));
System.err.println(PMDVersion.getFullVersionName());
validate();
return execute().getExitCode();
}

View File

@ -0,0 +1,23 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cli.commands.internal;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.pmd.PMDVersion;
import net.sourceforge.pmd.cli.internal.PmdBanner;
import picocli.CommandLine;
class PMDVersionProvider implements CommandLine.IVersionProvider {
@Override
public String[] getVersion() throws Exception {
List<String> lines = new ArrayList<>(PmdBanner.loadBanner());
lines.add(PMDVersion.getFullVersionName());
lines.add("Java version: " + System.getProperty("java.version") + ", vendor: " + System.getProperty("java.vendor") + ", runtime: " + System.getProperty("java.home"));
return lines.toArray(new String[0]);
}
}

View File

@ -4,11 +4,8 @@
package net.sourceforge.pmd.cli.commands.internal;
import net.sourceforge.pmd.PMDVersion;
import picocli.AutoComplete.GenerateCompletion;
import picocli.CommandLine.Command;
import picocli.CommandLine.IVersionProvider;
@Command(name = "pmd", mixinStandardHelpOptions = true,
versionProvider = PMDVersionProvider.class,
@ -20,11 +17,3 @@ import picocli.CommandLine.IVersionProvider;
public class PmdRootCommand {
}
class PMDVersionProvider implements IVersionProvider {
@Override
public String[] getVersion() throws Exception {
return new String[] { "PMD " + PMDVersion.VERSION };
}
}

View File

@ -0,0 +1,39 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cli.internal;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class PmdBanner {
private static final Logger LOGGER = LoggerFactory.getLogger(PmdBanner.class);
private static final String BANNER_RESOURCE = "/net/sourceforge/pmd/cli/internal/banner.txt";
private PmdBanner() {}
public static List<String> loadBanner() {
List<String> lines = new ArrayList<>();
try (BufferedReader bannerReader = new BufferedReader(
new InputStreamReader(PmdBanner.class.getResourceAsStream(BANNER_RESOURCE), StandardCharsets.UTF_8))) {
String line = bannerReader.readLine();
while (line != null) {
lines.add(line);
line = bannerReader.readLine();
}
} catch (IOException e) {
LOGGER.debug("Couldn't load banner", e);
}
return lines;
}
}

View File

@ -0,0 +1,8 @@
████ ████
██ ██
██ █████ █ ███ ███ ███████ ██
███ ██ ███ ████ ████ ██ ██ ███
███ ███████ ██ ████ ██ ██ ██ ███
██ ██ ██ ██ ██ ███████ ██
██ ██
████ ████