Draft DesignerCommand to identify gaps
This commit is contained in:
@ -7,7 +7,7 @@ public class PmdCli {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new CommandLine(new PmdRootCommand()).setCaseInsensitiveEnumValuesAllowed(true)
|
||||
.execute("run", "-h");
|
||||
.execute("designer", "--version");
|
||||
// .execute("run", "--use-version", "scala-2.11", "--use-version", "apex", "--use-version",
|
||||
// "ecmascript-latest", "-P", "foo=bar", "-R", "foo,bar", "-R", "baz", "-d",
|
||||
// "src/main/java", "-f", "xml");
|
||||
|
@ -19,7 +19,7 @@ public abstract class AbstractPmdSubcommand implements Callable<Integer> {
|
||||
@Option(names = { "-h", "--help" }, usageHelp = true, description = "Show this help message and exit.")
|
||||
protected boolean helpRequested;
|
||||
|
||||
@Option(names = { "--debug", "--verbose", "-D", "-V" }, description = "Debug mode.")
|
||||
@Option(names = { "--debug", "--verbose", "-D", "-v" }, description = "Debug mode.")
|
||||
protected boolean debug;
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,71 @@
|
||||
package net.sourceforge.pmd.cli.commands.internal;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import net.sourceforge.pmd.cli.internal.ExecutionResult;
|
||||
import net.sourceforge.pmd.util.fxdesigner.Designer;
|
||||
import net.sourceforge.pmd.util.fxdesigner.DesignerStarter;
|
||||
import picocli.CommandLine.Command;
|
||||
import picocli.CommandLine.IVersionProvider;
|
||||
import picocli.CommandLine.Option;
|
||||
|
||||
@Command(name = "designer", showDefaultValues = true,
|
||||
versionProvider = DesignerVersionProvider.class,
|
||||
description = "The PMD visual rule designer")
|
||||
public class DesignerCommand extends AbstractPmdSubcommand {
|
||||
|
||||
@Option(names = {"-V", "--version"}, versionHelp = true, description = "Print version information and exit.")
|
||||
private boolean versionRequested;
|
||||
|
||||
// TODO : Until a Designer version is released making DesignerStarter.launchGui() public we need to copy these…
|
||||
// launchGui should probably be changed to take no arguments, and return an int with the exit status code
|
||||
private static final String MISSING_JAVAFX =
|
||||
"You seem to be missing the JavaFX runtime." + System.lineSeparator()
|
||||
+ " Please install JavaFX on your system and try again." + System.lineSeparator()
|
||||
+ " See https://gluonhq.com/products/javafx/";
|
||||
|
||||
private static final int ERROR_EXIT = 1;
|
||||
private static final int OK = 0;
|
||||
|
||||
private static boolean isJavaFxAvailable() {
|
||||
try {
|
||||
DesignerStarter.class.getClassLoader().loadClass("javafx.application.Application");
|
||||
return true;
|
||||
} catch (ClassNotFoundException | LinkageError e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static int launchGui() {
|
||||
String message = null;
|
||||
if (!isJavaFxAvailable()) {
|
||||
message = MISSING_JAVAFX;
|
||||
}
|
||||
|
||||
if (message != null) {
|
||||
System.err.println(message);
|
||||
JOptionPane.showMessageDialog(null, message);
|
||||
return ERROR_EXIT;
|
||||
}
|
||||
|
||||
// TODO : add JavaFX to manually launch app…
|
||||
//Application.launch(Designer.class, args);
|
||||
return OK;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ExecutionResult execute() {
|
||||
final int status = launchGui();
|
||||
return status == OK ? ExecutionResult.OK : ExecutionResult.ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
class DesignerVersionProvider implements IVersionProvider {
|
||||
|
||||
// TODO : Since getCurrentVersion is within Designer, we can't ask for the version without JavaFX or we will face a NoClassDefFoundError
|
||||
@Override
|
||||
public String[] getVersion() throws Exception {
|
||||
return new String[] { "PMD Rule Designer " + Designer.getCurrentVersion() };
|
||||
}
|
||||
|
||||
}
|
@ -4,13 +4,12 @@ import net.sourceforge.pmd.PMDVersion;
|
||||
import picocli.CommandLine.Command;
|
||||
import picocli.CommandLine.IVersionProvider;
|
||||
|
||||
// TODO : Status code 4 is actually contingent on using --fail-on-violation… we need to raise that to a common flag
|
||||
@Command(name = "pmd", mixinStandardHelpOptions = true,
|
||||
versionProvider = PMDVersionProvider.class,
|
||||
exitCodeListHeading = "Exit Codes:%n",
|
||||
exitCodeList = { "0:Succesful 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 })
|
||||
subcommands = { PmdCommand.class, CpdCommand.class, DesignerCommand.class })
|
||||
public class PmdRootCommand {
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user