Example usage for org.apache.commons.exec CommandLine addArgument

List of usage examples for org.apache.commons.exec CommandLine addArgument

Introduction

In this page you can find the example usage for org.apache.commons.exec CommandLine addArgument.

Prototype

public CommandLine addArgument(final String argument) 

Source Link

Document

Add a single argument.

Usage

From source file:org.lucidj.launcher.Launcher.java

private void launch(String[] args) {
    System.out.println("Exec: " + java_exe);

    CommandLine cmdline = new CommandLine(java_exe);

    //----------//from   www  .  j av a  2s .c o  m
    // JVM args
    //----------

    cmdline.addArgument("-server");
    cmdline.addArgument("-Xms128M");
    cmdline.addArgument("-Xmx1024M");
    cmdline.addArgument("-XX:+UnlockDiagnosticVMOptions");
    cmdline.addArgument("-XX:+UnsyncloadClass");
    cmdline.addArgument("-Djava.awt.headless=true");
    cmdline.addArgument("-Dcom.sun.management.jmxremote");

    //-----------
    // Classpath
    //-----------

    List<String> path_elements = new ArrayList<>();

    String classpath_extra = karaf_properties.getProperty(".classpath.extra");

    if (classpath_extra != null) {
        // TODO: HANDLE COMPOUND classpath_extra; HANDLE MULTIPLE .classpath.*
        // Get all exported classpath files
        File[] file_list = new File(classpath_extra).listFiles();

        // And add to classpath if found
        if (file_list != null) {
            for (int i = 0; i < file_list.length; i++) {
                if (file_list[i].isFile() && file_list[i].getName().toLowerCase().endsWith(".jar")) {
                    path_elements.add(file_list[i].getAbsolutePath());
                }
            }
        }
    }

    cmdline.addArgument("-classpath");
    cmdline.addArgument(string_join(path_separator, path_elements), false);

    //-------------
    // LucidJ args
    //-------------

    addArgument(cmdline, "system.home", System.getProperty("system.home"));
    addArgument(cmdline, "system.conf", System.getProperty("system.conf"));
    addArgument(cmdline, "system.bootstrap", System.getProperty("system.bootstrap"));
    addArgument(cmdline, "system.deploy", System.getProperty("system.deploy"));

    // Copy the parsed properties to command line
    for (String key : karaf_properties.stringPropertyNames()) {
        if (!key.startsWith(".")) {
            addArgument(cmdline, key, karaf_properties.getProperty(key));
        }
    }

    if (System.getProperty("user.conf") != null) {
        addArgument(cmdline, "user.conf", System.getProperty("user.conf"));
    }

    // Class to exec
    cmdline.addArgument(main_class);

    // Add class arguments
    if (args != null) {
        for (String arg : args) {
            cmdline.addArgument(arg);
        }
    }

    //------------------
    // Ready to launch!
    //------------------

    if (verbose) {
        String[] argv = cmdline.toStrings();

        for (int i = 0; i < argv.length; i++) {
            System.out.println("argv[" + i + "] = '" + argv[i] + "'");
        }
    }

    launch_cmdline(cmdline);
}

From source file:org.lucidj.launcher.Launcher.java

public boolean launch_gui() {
    try {/*  w w w  .ja v a  2s . com*/
        CommandLine cmdline = new CommandLine(java_exe);
        cmdline.addArgument("-jar");
        cmdline.addArgument(System.getProperty("app.launcher.jar"));
        launch_cmdline(cmdline);
        return (true);
    } catch (Exception ignore) {
    }
    ;

    return (false);
}

From source file:org.mule.test.infrastructure.process.Controller.java

private int executeSyncCommand(String command, String[] args, Map<Object, Object> newEnv, int timeout)
        throws MuleControllerException {
    CommandLine commandLine = new CommandLine(muleBin);
    commandLine.addArgument(command);
    commandLine.addArguments(args);//  w  w  w  . j a  va2  s . com
    DefaultExecutor executor = new DefaultExecutor();
    ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
    executor.setWatchdog(watchdog);
    executor.setStreamHandler(new PumpStreamHandler());
    return doExecution(executor, commandLine, newEnv);
}

From source file:org.nanoko.coffee.mill.mojos.reporting.JsDocMojo.java

private void generateJSDOC() throws MavenReportException {
    if (skipJSDOC) {
        getLog().info("JSDoc report generation skipped");
        return;// w  w w  . ja v a  2  s  . com
    }

    File jsdocExec = ExecUtils.findExecutableInPath("jsdoc");
    if (jsdocExec == null) {
        getLog().error("Cannot build jsdoc report - jsdoc not in the system path, the report is ignored.");
        return;
    } else {
        getLog().info("Invoking jsdoc : " + jsdocExec.getAbsolutePath());
        getLog().info("Output directory : " + getOutputDirectory());
    }

    File out = new File(getOutputDirectory());
    out.mkdirs();

    CommandLine cmdLine = CommandLine.parse(jsdocExec.getAbsolutePath());

    // Destination
    cmdLine.addArgument("--destination");
    cmdLine.addArgument(out.getAbsolutePath());

    if (jsdocIncludePrivate) {
        cmdLine.addArgument("--private");
    }

    File input = new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".js");
    if (!input.exists()) {
        throw new MavenReportException("Cannot find the project's artifact : " + input.getAbsolutePath());
    }
    cmdLine.addArgument(input.getAbsolutePath());

    DefaultExecutor executor = new DefaultExecutor();

    executor.setWorkingDirectory(project.getBasedir());
    executor.setExitValue(0);
    try {
        getLog().info("Executing " + cmdLine.toString());
        executor.execute(cmdLine);
    } catch (IOException e) {
        throw new MavenReportException("Error during jsdoc report generation", e);
    }

}

From source file:org.nanoko.coffee.mill.processors.JpegTranProcessor.java

private void optimize(File file) throws ProcessorException {
    File dir = file.getParentFile();

    // Build command line
    CommandLine cmdLine = CommandLine.parse(jpegTranExec.getAbsolutePath());

    if (verbose) {
        cmdLine.addArgument("-verbose");
    }//from ww w  .ja  v a 2  s . c  om

    cmdLine.addArgument("-copy");
    cmdLine.addArgument("none");

    cmdLine.addArgument("-optimize");

    cmdLine.addArgument("-outfile");
    cmdLine.addArgument("out.jpeg");

    cmdLine.addArgument(file.getName());

    DefaultExecutor executor = new DefaultExecutor();

    executor.setWorkingDirectory(dir);
    executor.setExitValue(0);
    try {
        getLog().info("Executing " + cmdLine.toString());
        executor.execute(cmdLine);

        // Overwrite the original file
        File out = new File(dir, "out.jpeg");
        if (out.exists()) {
            FileUtils.copyFile(new File(dir, "out.jpeg"), file);
        } else {
            throw new IOException("Output file not found : " + out.getAbsolutePath());
        }

        getLog().info(file.getName() + " optimized");
    } catch (IOException e) {
        throw new ProcessorException("Error during JPG optimization of " + file.getAbsolutePath(), e);
    }
}

From source file:org.nanoko.coffee.mill.processors.OptiPNGProcessor.java

private void optimize(File file) throws ProcessorException {
    File dir = file.getParentFile();

    // Build command line
    CommandLine cmdLine = CommandLine.parse(optiPNGExec.getAbsolutePath());
    cmdLine.addArgument(file.getName());

    if (verbose) {
        cmdLine.addArgument("-v");
    }//from   w ww.  j a  v a  2s. c  o m

    cmdLine.addArgument("-o" + level);

    DefaultExecutor executor = new DefaultExecutor();

    executor.setWorkingDirectory(dir);
    executor.setExitValue(0);
    try {
        getLog().info("Executing " + cmdLine.toString());
        executor.execute(cmdLine);
        getLog().info(file.getName() + " optimized");
    } catch (IOException e) {
        throw new ProcessorException("Error during PNG optimization of " + file.getAbsolutePath(), e);
    }
}

From source file:org.nanoko.coffeemill.mojos.processresources.OptiJpegMojo.java

private void optimize(File file) throws WatchingException {
    File dir = file.getParentFile();

    // Build command line
    CommandLine cmdLine = CommandLine.parse(jpegTranExec.getAbsolutePath());

    if (verbose) {
        cmdLine.addArgument("-verbose");
    }/* w w w .j av  a  2  s . co  m*/

    cmdLine.addArgument("-copy");
    cmdLine.addArgument("none");

    cmdLine.addArgument("-optimize");

    cmdLine.addArgument("-outfile");
    cmdLine.addArgument("__out.jpeg");

    cmdLine.addArgument(file.getName());

    DefaultExecutor executor = new DefaultExecutor();

    executor.setWorkingDirectory(dir);
    executor.setExitValue(0);
    try {
        getLog().info("Executing " + cmdLine.toString());
        executor.execute(cmdLine);

        // Overwrite the original file
        File out = new File(dir, "__out.jpeg");

        getLog().info("output jpeg file : " + out.getAbsolutePath());
        if (out.exists()) {
            FileUtils.copyFile(out, file);
            FileUtils.deleteQuietly(out);
        } else {
            throw new IOException("Output file not found : " + out.getAbsolutePath());
        }

        getLog().info(file.getName() + " optimized");
    } catch (IOException e) {
        throw new WatchingException("Error during JPG optimization of " + file.getAbsolutePath(), e);
    }
}

From source file:org.nanoko.coffeemill.mojos.processresources.OptiPngMojo.java

private void optimize(File file) throws WatchingException {
    File dir = file.getParentFile();

    // Build command line
    CommandLine cmdLine = CommandLine.parse(optiPNGExec.getAbsolutePath());
    cmdLine.addArgument(file.getName());

    if (verbose) {
        cmdLine.addArgument("-v");
    }/*from w ww  . ja  v  a 2  s .  co m*/

    cmdLine.addArgument("-o" + level);

    DefaultExecutor executor = new DefaultExecutor();

    executor.setWorkingDirectory(dir);
    executor.setExitValue(0);
    try {
        getLog().info("Executing " + cmdLine.toString());
        executor.execute(cmdLine);
        getLog().info(file.getName() + " optimized");
    } catch (IOException e) {
        throw new WatchingException("Error during PNG optimization of " + file.getAbsolutePath(), e);
    }
}

From source file:org.nanoko.playframework.mojo.Play2DebugMojo.java

public void execute() throws MojoExecutionException {

    String line = getPlay2().getAbsolutePath();

    CommandLine cmdLine = CommandLine.parse(line);

    cmdLine.addArgument("debug");
    cmdLine.addArguments(getPlay2SystemPropertiesArguments(), false);
    cmdLine.addArgument("run");
    DefaultExecutor executor = new DefaultExecutor();

    // As where not linked to a project, we can't set the working directory.
    // So it will use the directory where mvn was launched.

    executor.setExitValue(0);/*from w w  w  .  j  a v a  2s  . c  o  m*/
    try {
        executor.execute(cmdLine, getEnvironment());
    } catch (IOException e) {
        // Ignore.
    }
}

From source file:org.nanoko.playframework.mojo.Play2EclipseMojo.java

@Override
protected void addCommandLineArgs(CommandLine cmdLine) {
    cmdLine.addArgument("eclipse");
}