use of org.apache.commons.cli.PosixParser in project tomee by apache.
the class Main method main.
public static void main(final String[] args) {
final CommandLineParser parser = new PosixParser();
final Options options = createOptions();
// parse command line
final CommandLine line;
try {
line = parser.parse(options, args, true);
} catch (final ParseException exp) {
help(options);
return;
}
if (line.hasOption(HELP)) {
help(options);
return;
}
final Collection<Closeable> post = new ArrayList<>();
for (final LifecycleTask task : ServiceLoader.load(LifecycleTask.class)) {
final Closeable closeable = task.beforeContainerStartup();
if (closeable != null) {
post.add(closeable);
}
}
if (line.hasOption(PRE_TASK)) {
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
for (final String type : line.getOptionValues(PRE_TASK)) {
final Object task;
try {
task = loader.loadClass(type).newInstance();
} catch (final Exception e) {
throw new IllegalArgumentException(e);
}
if (Runnable.class.isInstance(task)) {
Runnable.class.cast(task).run();
} else if (LifecycleTask.class.isInstance(task)) {
final Closeable closeable = LifecycleTask.class.cast(task).beforeContainerStartup();
if (closeable != null) {
post.add(closeable);
}
} else {
throw new IllegalArgumentException(task + " can't be executed");
}
}
}
// run TomEE
try {
final Container container = new Container(createConfiguration(line));
final String[] contexts;
if (line.hasOption(CONTEXT)) {
contexts = line.getOptionValues(CONTEXT);
} else {
contexts = null;
}
SystemInstance.get().setComponent(TomEEEmbeddedArgs.class, new TomEEEmbeddedArgs(args, line));
boolean autoWar;
if (line.hasOption(PATH)) {
int i = 0;
for (final String path : line.getOptionValues(PATH)) {
final Set<String> locations = ProvisioningUtil.realLocation(path);
for (final String location : locations) {
final File file = new File(location);
if (!file.exists()) {
System.err.println(file.getAbsolutePath() + " does not exist, skipping");
continue;
}
String name = file.getName().replaceAll("\\.[A-Za-z]+$", "");
if (contexts != null) {
name = contexts[i++];
}
container.deploy(name, file, true);
}
}
autoWar = false;
} else if (line.hasOption(AS_WAR)) {
deployClasspath(line, container, contexts);
autoWar = false;
} else {
// nothing to deploy
autoWar = true;
}
if (autoWar) {
// nothing deployed check if we are a war and deploy ourself then
final File me = jarLocation(Main.class);
if (me.getName().endsWith(".war")) {
container.deploy(contexts == null || 0 == contexts.length ? "" : contexts[0], me, line.hasOption(RENAMING));
} else {
deployClasspath(line, container, contexts);
}
}
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
container.stop();
} catch (final Exception e) {
// just log the exception
e.printStackTrace();
} finally {
close(post);
}
}
});
if (options.hasOption(INTERACTIVE)) {
String l;
final Scanner scanner = new Scanner(System.in);
while ((l = scanner.nextLine()) != null) {
switch(l.trim()) {
case "quit":
case "exit":
return;
default:
System.out.println("Unknown command '" + l + "', supported commands: 'quit', 'exist'");
}
}
}
container.await();
} catch (final Exception e) {
e.printStackTrace();
} finally {
close(post);
}
}
use of org.apache.commons.cli.PosixParser in project compiler by boalang.
the class BoaEvaluator method main.
public static void main(final String[] args) {
final Options options = new Options();
options.addOption("i", "input", true, "input Boa source file (*.boa)");
options.addOption("d", "data", true, "path to local data directory");
options.addOption("o", "output", true, "output directory");
options.getOption("i").setRequired(true);
options.getOption("d").setRequired(true);
try {
if (args.length == 0) {
printHelp(options, null);
return;
} else {
final CommandLine cl = new PosixParser().parse(options, args);
if (cl.hasOption('i') && cl.hasOption('d')) {
final BoaEvaluator evaluator;
try {
if (cl.hasOption('o')) {
evaluator = new BoaEvaluator(cl.getOptionValue('i'), cl.getOptionValue('d'), cl.getOptionValue('o'));
} else {
evaluator = new BoaEvaluator(cl.getOptionValue('i'), cl.getOptionValue('d'));
}
} catch (final IOException e) {
System.err.print(e);
return;
}
if (!evaluator.compile()) {
System.err.println("Compilation Failed");
return;
}
final long start = System.currentTimeMillis();
evaluator.evaluate();
final long end = System.currentTimeMillis();
System.out.println("Total Time Taken: " + (end - start));
System.out.println(evaluator.getResults());
} else {
printHelp(options, "missing required options: -i <arg> and -d <arg>");
return;
}
}
} catch (final org.apache.commons.cli.ParseException e) {
printHelp(options, e.getMessage());
}
}
use of org.apache.commons.cli.PosixParser in project compiler by boalang.
the class BoaCompiler method processParseCommandLineOptions.
private static CommandLine processParseCommandLineOptions(final String[] args) {
// parse the command line options
final Options options = new Options();
options.addOption("l", "libs", true, "extra jars (functions/aggregators) to be compiled in");
options.addOption("i", "in", true, "file(s) to be parsed (comma-separated list)");
final CommandLine cl;
try {
cl = new PosixParser().parse(options, args);
} catch (final org.apache.commons.cli.ParseException e) {
printHelp(options, e.getMessage());
return null;
}
// get the filename of the program we will be compiling
inputFiles = new ArrayList<File>();
if (cl.hasOption('i')) {
final String[] inputPaths = cl.getOptionValue('i').split(",");
for (final String s : inputPaths) {
final File f = new File(s);
if (!f.exists())
System.err.println("File '" + s + "' does not exist, skipping");
else
inputFiles.add(new File(s));
}
}
if (inputFiles.size() == 0) {
printHelp(options, "no valid input files found - did you use the --in option?");
return null;
}
return cl;
}
use of org.apache.commons.cli.PosixParser in project compiler by boalang.
the class BoaCompiler method processCommandLineOptions.
private static CommandLine processCommandLineOptions(final String[] args) {
// parse the command line options
final Options options = new Options();
options.addOption("l", "libs", true, "extra jars (functions/aggregators) to be compiled in");
options.addOption("i", "in", true, "file(s) to be compiled (comma-separated list)");
options.addOption("o", "out", true, "the name of the resulting jar");
options.addOption("j", "rtjar", true, "the path to the Boa runtime jar");
options.addOption("v", "visitors-fused", true, "number of visitors to fuse");
options.addOption("n", "name", true, "the name of the generated main class");
options.addOption("ast", "ast-parsed", false, "print the AST immediately after parsing (debug)");
options.addOption("ast2", "ast-transformed", false, "print the AST after transformations, before code generation (debug)");
options.addOption("pp", "pretty-print", false, "pretty print the AST before code generation (debug)");
options.addOption("cd", "compilation-dir", true, "directory to store all generated files");
final CommandLine cl;
try {
cl = new PosixParser().parse(options, args);
} catch (final org.apache.commons.cli.ParseException e) {
System.err.println(e.getMessage());
new HelpFormatter().printHelp("Boa Compiler", options);
return null;
}
// get the filename of the program we will be compiling
inputFiles = new ArrayList<File>();
if (cl.hasOption('i')) {
final String[] inputPaths = cl.getOptionValue('i').split(",");
for (final String s : inputPaths) {
final File f = new File(s);
if (!f.exists())
System.err.println("File '" + s + "' does not exist, skipping");
else
inputFiles.add(new File(s));
}
}
if (inputFiles.size() == 0) {
System.err.println("no valid input files found - did you use the --in option?");
//new HelpFormatter().printHelp("BoaCompiler", options);
new HelpFormatter().printHelp("Boa Compiler", options);
return null;
}
return cl;
}
Aggregations