Use new commons-cli API, remove usages of deprecated one

This commit is contained in:
Alexey Andreev 2021-03-22 11:52:56 +03:00
parent bd53c1a5a2
commit 60e5c0bbce
3 changed files with 193 additions and 195 deletions

View File

@ -17,11 +17,11 @@ package org.teavm.cli;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options; import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException; import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.teavm.tooling.ConsoleTeaVMToolLog; import org.teavm.tooling.ConsoleTeaVMToolLog;
import org.teavm.tooling.c.incremental.IncrementalCBuilder; import org.teavm.tooling.c.incremental.IncrementalCBuilder;
@ -34,62 +34,61 @@ public class TeaVMCBuilderRunner {
setupOptions(); setupOptions();
} }
@SuppressWarnings("static-access")
private static void setupOptions() { private static void setupOptions() {
options.addOption(OptionBuilder options.addOption(Option.builder("d")
.withArgName("directory") .argName("directory")
.hasArg() .hasArg()
.withDescription("a directory in which generated C files will be placed") .desc("a directory in which generated C files will be placed")
.withLongOpt("targetdir") .longOpt("targetdir")
.create('d')); .build());
options.addOption(OptionBuilder options.addOption(Option.builder("p")
.withArgName("classpath") .argName("classpath")
.hasArgs() .hasArgs()
.withDescription("classpath element (either directory or jar file)") .desc("classpath element (either directory or jar file)")
.withLongOpt("classpath") .longOpt("classpath")
.create('p')); .build());
options.addOption(OptionBuilder options.addOption(Option.builder("v")
.withDescription("display more messages on server log") .desc("display more messages on server log")
.withLongOpt("verbose") .longOpt("verbose")
.create('v')); .build());
options.addOption(OptionBuilder options.addOption(Option.builder("g")
.withDescription("generate debugger-friendly code") .desc("generate debugger-friendly code")
.withLongOpt("debug") .longOpt("debug")
.create('g')); .build());
options.addOption(OptionBuilder options.addOption(Option.builder()
.withLongOpt("min-heap") .longOpt("min-heap")
.withArgName("size") .argName("size")
.hasArg() .hasArg()
.withDescription("Minimum heap size in megabytes") .desc("Minimum heap size in megabytes")
.create()); .build());
options.addOption(OptionBuilder options.addOption(Option.builder()
.withLongOpt("max-heap") .longOpt("max-heap")
.withArgName("size") .argName("size")
.hasArg() .hasArg()
.withDescription("Minimum heap size in megabytes") .desc("Minimum heap size in megabytes")
.create()); .build());
options.addOption(OptionBuilder options.addOption(Option.builder()
.withLongOpt("no-longjmp") .longOpt("no-longjmp")
.withDescription("Don't use setjmp/longjmp functions to emulate exception handling") .desc("Don't use setjmp/longjmp functions to emulate exception handling")
.create()); .build());
options.addOption(OptionBuilder options.addOption(Option.builder("e")
.withLongOpt("entry-point") .longOpt("entry-point")
.withArgName("name") .argName("name")
.hasArg() .hasArg()
.withDescription("Name of entry point function (main by default)") .desc("Name of entry point function (main by default)")
.create('e')); .build());
options.addOption(OptionBuilder options.addOption(Option.builder()
.withLongOpt("external-tool") .longOpt("external-tool")
.withArgName("path") .argName("path")
.hasArg() .hasArg()
.withDescription("Process to run after successful build") .desc("Process to run after successful build")
.create()); .build());
options.addOption(OptionBuilder options.addOption(Option.builder()
.withLongOpt("external-tool-workdir") .longOpt("external-tool-workdir")
.withArgName("path") .argName("path")
.hasArg() .hasArg()
.withDescription("Working directory of process") .desc("Working directory of process")
.create()); .build());
} }
private TeaVMCBuilderRunner(CommandLine commandLine) { private TeaVMCBuilderRunner(CommandLine commandLine) {
@ -102,7 +101,7 @@ public class TeaVMCBuilderRunner {
printUsage(); printUsage();
return; return;
} }
CommandLineParser parser = new PosixParser(); CommandLineParser parser = new DefaultParser();
CommandLine commandLine; CommandLine commandLine;
try { try {
commandLine = parser.parse(options, args); commandLine = parser.parse(options, args);

View File

@ -18,11 +18,11 @@ package org.teavm.cli;
import java.util.Arrays; import java.util.Arrays;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options; import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException; import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.teavm.devserver.DevServer; import org.teavm.devserver.DevServer;
import org.teavm.tooling.ConsoleTeaVMToolLog; import org.teavm.tooling.ConsoleTeaVMToolLog;
@ -35,66 +35,65 @@ public final class TeaVMDevServerRunner {
setupOptions(); setupOptions();
} }
@SuppressWarnings("AccessStaticViaInstance")
private static void setupOptions() { private static void setupOptions() {
options.addOption(OptionBuilder options.addOption(Option.builder("d")
.withArgName("directory") .argName("directory")
.hasArg() .hasArg()
.withDescription("a directory, relative to server's root, which serves generated files") .desc("a directory, relative to server's root, which serves generated files")
.withLongOpt("targetdir") .longOpt("targetdir")
.create('d')); .build());
options.addOption(OptionBuilder options.addOption(Option.builder("f")
.withArgName("file") .argName("file")
.hasArg() .hasArg()
.withDescription("a file where to put decompiled classes (classes.js by default)") .desc("a file where to put decompiled classes (classes.js by default)")
.withLongOpt("targetfile") .longOpt("targetfile")
.create('f')); .build());
options.addOption(OptionBuilder options.addOption(Option.builder("p")
.withArgName("classpath") .argName("classpath")
.hasArgs() .hasArgs()
.withDescription("classpath element (either directory or jar file)") .desc("classpath element (either directory or jar file)")
.withLongOpt("classpath") .longOpt("classpath")
.create('p')); .build());
options.addOption(OptionBuilder options.addOption(Option.builder("s")
.withArgName("sourcepath") .argName("sourcepath")
.hasArg() .hasArg()
.withDescription("source path (either directory or jar file which contains source code)") .desc("source path (either directory or jar file which contains source code)")
.withLongOpt("sourcepath") .longOpt("sourcepath")
.create('s')); .build());
options.addOption(OptionBuilder options.addOption(Option.builder()
.withArgName("number") .argName("number")
.hasArg() .hasArg()
.withDescription("port (default is 9090)") .desc("port (default is 9090)")
.withLongOpt("port") .longOpt("port")
.create()); .build());
options.addOption(OptionBuilder options.addOption(Option.builder("i")
.withDescription("display indicator on web page") .desc("display indicator on web page")
.withLongOpt("indicator") .longOpt("indicator")
.create('i')); .build());
options.addOption(OptionBuilder options.addOption(Option.builder()
.withDescription("deobfuscate stack traces") .desc("deobfuscate stack traces")
.withLongOpt("deobfuscate-stack") .longOpt("deobfuscate-stack")
.create()); .build());
options.addOption(OptionBuilder options.addOption(Option.builder()
.withDescription("automatically reload page when compilation completes") .desc("automatically reload page when compilation completes")
.withLongOpt("auto-reload") .longOpt("auto-reload")
.create()); .build());
options.addOption(OptionBuilder options.addOption(Option.builder("v")
.withDescription("display more messages on server log") .desc("display more messages on server log")
.withLongOpt("verbose") .longOpt("verbose")
.create('v')); .build());
options.addOption(OptionBuilder options.addOption(Option.builder()
.withArgName("URL") .argName("URL")
.hasArg() .hasArg()
.withDescription("delegate requests to URL") .desc("delegate requests to URL")
.withLongOpt("proxy-url") .longOpt("proxy-url")
.create()); .build());
options.addOption(OptionBuilder options.addOption(Option.builder()
.withArgName("path") .argName("path")
.hasArg() .hasArg()
.withDescription("delegate requests from path") .desc("delegate requests from path")
.withLongOpt("proxy-path") .longOpt("proxy-path")
.create()); .build());
} }
private TeaVMDevServerRunner(CommandLine commandLine) { private TeaVMDevServerRunner(CommandLine commandLine) {
@ -107,7 +106,7 @@ public final class TeaVMDevServerRunner {
printUsage(); printUsage();
return; return;
} }
CommandLineParser parser = new PosixParser(); CommandLineParser parser = new DefaultParser();
CommandLine commandLine; CommandLine commandLine;
try { try {
commandLine = parser.parse(options, args); commandLine = parser.parse(options, args);

View File

@ -23,11 +23,11 @@ import java.net.URLClassLoader;
import java.util.Arrays; import java.util.Arrays;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options; import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException; import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.teavm.backend.wasm.render.WasmBinaryVersion; import org.teavm.backend.wasm.render.WasmBinaryVersion;
import org.teavm.tooling.ConsoleTeaVMToolLog; import org.teavm.tooling.ConsoleTeaVMToolLog;
import org.teavm.tooling.TeaVMProblemRenderer; import org.teavm.tooling.TeaVMProblemRenderer;
@ -54,107 +54,107 @@ public final class TeaVMRunner {
setupOptions(); setupOptions();
} }
@SuppressWarnings("static-access")
private static void setupOptions() { private static void setupOptions() {
options.addOption(OptionBuilder options.addOption(Option.builder("t")
.withArgName("target") .argName("target")
.hasArg() .hasArg()
.withDescription("target type (javascript/js, webassembly/wasm, C)") .desc("target type (javascript/js, webassembly/wasm, C)")
.create('t')); .build());
options.addOption(OptionBuilder options.addOption(Option.builder("d")
.withArgName("directory") .argName("directory")
.hasArg() .hasArg()
.withDescription("a directory where to put generated files (current directory by default)") .desc("a directory where to put generated files (current directory by default)")
.withLongOpt("targetdir") .longOpt("targetdir")
.create('d')); .build());
options.addOption(OptionBuilder options.addOption(Option.builder("f")
.withArgName("file") .argName("file")
.hasArg() .hasArg()
.withDescription("a file where to put decompiled classes (classes.js by default)") .desc("a file where to put decompiled classes (classes.js by default)")
.withLongOpt("targetfile") .longOpt("targetfile")
.create('f')); .build());
options.addOption(OptionBuilder options.addOption(Option.builder("m")
.withDescription("causes TeaVM to generate minimized JavaScript file") .desc("causes TeaVM to generate minimized JavaScript file")
.withLongOpt("minify") .longOpt("minify")
.create("m")); .build());
options.addOption(OptionBuilder options.addOption(Option.builder()
.withDescription("causes TeaVM to produce code that is as close to Java semantics as possible " .longOpt("strict")
.desc("causes TeaVM to produce code that is as close to Java semantics as possible "
+ "(in cost of performance)") + "(in cost of performance)")
.create("strict")); .build());
options.addOption(OptionBuilder options.addOption(Option.builder("O")
.withDescription("optimization level (1-3)") .desc("optimization level (1-3)")
.hasArg() .hasArg()
.withArgName("number") .argName("number")
.create("O")); .build());
options.addOption(OptionBuilder options.addOption(Option.builder("g")
.withDescription("Generate debug information") .desc("Generate debug information")
.withLongOpt("debug") .longOpt("debug")
.create('g')); .build());
options.addOption(OptionBuilder options.addOption(Option.builder("G")
.withDescription("Generate source maps") .desc("Generate source maps")
.withLongOpt("sourcemaps") .longOpt("sourcemaps")
.create('G')); .build());
options.addOption(OptionBuilder options.addOption(Option.builder("i")
.withDescription("Incremental build") .desc("Incremental build")
.withLongOpt("incremental") .longOpt("incremental")
.create('i')); .build());
options.addOption(OptionBuilder options.addOption(Option.builder("c")
.withArgName("directory") .argName("directory")
.hasArg() .hasArg()
.withDescription("Incremental build cache directory") .desc("Incremental build cache directory")
.withLongOpt("cachedir") .longOpt("cachedir")
.create('c')); .build());
options.addOption(OptionBuilder options.addOption(Option.builder("w")
.withDescription("Wait for command after compilation, in order to enable hot recompilation") .desc("Wait for command after compilation, in order to enable hot recompilation")
.withLongOpt("wait") .longOpt("wait")
.create('w')); .build());
options.addOption(OptionBuilder options.addOption(Option.builder("p")
.withArgName("classpath") .argName("classpath")
.hasArgs() .hasArgs()
.withDescription("Additional classpath that will be reloaded by TeaVM each time in wait mode") .desc("Additional classpath that will be reloaded by TeaVM each time in wait mode")
.withLongOpt("classpath") .longOpt("classpath")
.create('p')); .build());
options.addOption(OptionBuilder options.addOption(Option.builder()
.withArgName("class name") .argName("class name")
.hasArgs() .hasArgs()
.withDescription("Tell optimizer to not remove class, so that it can be found by Class.forName") .desc("Tell optimizer to not remove class, so that it can be found by Class.forName")
.withLongOpt("preserve-class") .longOpt("preserve-class")
.create()); .build());
options.addOption(OptionBuilder options.addOption(Option.builder()
.withLongOpt("wasm-version") .longOpt("wasm-version")
.withArgName("version") .argName("version")
.hasArg() .hasArg()
.withDescription("WebAssembly binary version (currently, only 1 is supported)") .desc("WebAssembly binary version (currently, only 1 is supported)")
.create()); .build());
options.addOption(OptionBuilder options.addOption(Option.builder("e")
.withLongOpt("entry-point") .longOpt("entry-point")
.withArgName("name") .argName("name")
.hasArg() .hasArg()
.withDescription("Entry point name in target language (main by default)") .desc("Entry point name in target language (main by default)")
.create("e")); .build());
options.addOption(OptionBuilder options.addOption(Option.builder()
.withLongOpt("min-heap") .longOpt("min-heap")
.withArgName("size") .argName("size")
.hasArg() .hasArg()
.withDescription("Minimum heap size in megabytes (for C and WebAssembly)") .desc("Minimum heap size in megabytes (for C and WebAssembly)")
.create()); .build());
options.addOption(OptionBuilder options.addOption(Option.builder()
.withLongOpt("max-heap") .longOpt("max-heap")
.withArgName("size") .argName("size")
.hasArg() .hasArg()
.withDescription("Maximum heap size in megabytes (for C and WebAssembly)") .desc("Maximum heap size in megabytes (for C and WebAssembly)")
.create()); .build());
options.addOption(OptionBuilder options.addOption(Option.builder()
.withLongOpt("max-toplevel-names") .longOpt("max-toplevel-names")
.withArgName("number") .argName("number")
.hasArg() .hasArg()
.withDescription("Maximum number of names kept in top-level scope (" .desc("Maximum number of names kept in top-level scope ("
+ "other will be put in a separate object. 10000 by default.") + "other will be put in a separate object. 10000 by default.")
.create()); .build());
options.addOption(OptionBuilder options.addOption(Option.builder()
.withLongOpt("no-longjmp") .longOpt("no-longjmp")
.withDescription("Don't use setjmp/longjmp functions to emulate exceptions (C target)") .desc("Don't use setjmp/longjmp functions to emulate exceptions (C target)")
.create()); .build());
} }
private TeaVMRunner(CommandLine commandLine) { private TeaVMRunner(CommandLine commandLine) {
@ -166,7 +166,7 @@ public final class TeaVMRunner {
printUsage(); printUsage();
return; return;
} }
CommandLineParser parser = new PosixParser(); CommandLineParser parser = new DefaultParser();
CommandLine commandLine; CommandLine commandLine;
try { try {
commandLine = parser.parse(options, args); commandLine = parser.parse(options, args);