Search in sources :

Example 91 with PosixParser

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);
    }
}
Also used : Options(org.apache.commons.cli.Options) Scanner(java.util.Scanner) TomEEEmbeddedArgs(org.apache.tomee.embedded.component.TomEEEmbeddedArgs) PosixParser(org.apache.commons.cli.PosixParser) Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) CommandLineParser(org.apache.commons.cli.CommandLineParser) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ParseException(org.apache.commons.cli.ParseException) CommandLine(org.apache.commons.cli.CommandLine) ParseException(org.apache.commons.cli.ParseException) File(java.io.File)

Example 92 with PosixParser

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;
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) File(java.io.File)

Example 93 with PosixParser

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;
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) File(java.io.File)

Example 94 with PosixParser

use of org.apache.commons.cli.PosixParser in project ignite by apache.

the class GridVmNodesStarter method main.

/**
 * Main entry point.
 *
 * @param args Command line arguments.
 * @throws IgniteCheckedException If failed.
 */
public static void main(String[] args) throws IgniteCheckedException {
    System.setProperty(IGNITE_UPDATE_NOTIFIER, "false");
    Options options = createOptions();
    // Create the command line parser.
    CommandLineParser parser = new PosixParser();
    String cfgPath = null;
    Integer nodesCnt = null;
    try {
        CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption(OPTION_CFG))
            cfgPath = cmd.getOptionValue(OPTION_CFG);
        if (cmd.hasOption(OPTION_N))
            try {
                nodesCnt = Integer.parseInt(cmd.getOptionValue(OPTION_N));
            } catch (NumberFormatException ignored) {
            // No-op.
            }
        if (nodesCnt == null)
            nodesCnt = DFLT_NODES_COUNT;
    } catch (ParseException e) {
        exit(e.getMessage(), options, -1);
    }
    System.out.println();
    System.out.println(">>> VM Nodes Starter parameters:");
    System.out.println("  Nodes Count: " + nodesCnt);
    System.out.println("  Config Path: " + cfgPath);
    System.out.println();
    final IgniteConfiguration[] cfgs = new IgniteConfiguration[nodesCnt];
    for (int i = 0; i < nodesCnt; i++) cfgs[i] = getConfigurations(cfgPath).iterator().next();
    final AtomicInteger cfgIdx = new AtomicInteger(0);
    GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            G.start(cfgs[cfgIdx.getAndIncrement()]);
            return null;
        }
    }, nodesCnt, "test-node-starter");
}
Also used : Options(org.apache.commons.cli.Options) PosixParser(org.apache.commons.cli.PosixParser) MalformedURLException(java.net.MalformedURLException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BeansException(org.springframework.beans.BeansException) ParseException(org.apache.commons.cli.ParseException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CommandLine(org.apache.commons.cli.CommandLine) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException)

Example 95 with PosixParser

use of org.apache.commons.cli.PosixParser in project metron by apache.

the class SampleDataGenerator method main.

public static void main(String[] args) throws org.apache.commons.cli.ParseException, IOException, ParseException {
    CommandLineParser parser = new PosixParser();
    CommandLine cli = parser.parse(getOptions(), args);
    Integer num = Integer.parseInt(cli.getOptionValue("n", "-1"));
    String selectedSensorType = cli.getOptionValue("s");
    Integer delay = Integer.parseInt(cli.getOptionValue("d", "1000"));
    String path = cli.getOptionValue("p");
    if (selectedSensorType == null || path == null) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("sample_data_generator", getOptions());
    } else {
        SampleDataGenerator sampleDataGenerator = new SampleDataGenerator();
        sampleDataGenerator.setNum(num);
        sampleDataGenerator.setSelectedSensorType(selectedSensorType);
        sampleDataGenerator.setDelay(delay);
        sampleDataGenerator.generateSampleData(path);
    }
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) CommandLineParser(org.apache.commons.cli.CommandLineParser)

Aggregations

PosixParser (org.apache.commons.cli.PosixParser)103 CommandLine (org.apache.commons.cli.CommandLine)97 CommandLineParser (org.apache.commons.cli.CommandLineParser)67 Options (org.apache.commons.cli.Options)56 ParseException (org.apache.commons.cli.ParseException)51 File (java.io.File)24 IOException (java.io.IOException)20 HelpFormatter (org.apache.commons.cli.HelpFormatter)16 Optional (java.util.Optional)10 Test (org.junit.Test)9 List (java.util.List)8 Configuration (org.apache.hadoop.conf.Configuration)8 GenericOptionsParser (org.apache.hadoop.util.GenericOptionsParser)7 SystemExitException (org.apache.openejb.cli.SystemExitException)7 Option (org.apache.commons.cli.Option)6 Parser (org.apache.commons.cli.Parser)6 Properties (java.util.Properties)5 Path (org.apache.hadoop.fs.Path)5 ArrayList (java.util.ArrayList)4 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)4