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, final boolean handleQuoting) 

Source Link

Document

Add a single argument.

Usage

From source file:com.abiquo.nodecollector.service.impl.StonithServiceImpl.java

protected CommandLine buildCommand(final String ip, final Integer port, final String user,
        final String password) {
    CommandLine command = new CommandLine("ipmitool");
    command.addArgument("-H").addArgument(ip, true);
    command.addArgument("-U").addArgument(user, true);
    command.addArgument("-P").addArgument(password, true);
    command.addArgument("chassis", true);

    if (port != null) {
        command.addArgument("-p").addArgument(port.toString(), true);
    }//  w ww .  j a  v a  2  s  . c  o m

    return command;
}

From source file:com.abiquo.nodecollector.service.impl.StonithServiceImpl.java

@Override
public boolean isStonithUp(final String host, final Integer port, final String user, final String password) {
    CommandLine command = buildCommand(host, port, user, password);
    command.addArgument("status", true);

    return executeCommand(command);
}

From source file:io.selendroid.android.impl.DefaultHardwareDeviceTests.java

private String listInstalledPackages() throws Exception {
    CommandLine command = new CommandLine(AndroidSdk.adb().getAbsolutePath());
    command.addArgument("-s", false);
    command.addArgument(serial, false);//from   w ww  . j  a  v a 2 s . com
    command.addArgument("shell", false);
    command.addArgument("pm", false);
    command.addArgument("list", false);
    command.addArgument("packages", false);
    return ShellCommand.exec(command);
}

From source file:com.stratio.explorer.shell.ShellInterpreter.java

@Override
public InterpreterResult interpret(String cmd) {
    logger.info("Run shell command '" + cmd + "'");
    long start = System.currentTimeMillis();
    CommandLine cmdLine = CommandLine.parse("bash");
    cmdLine.addArgument("-c", false);
    cmdLine.addArgument(cmd, false);/*from w ww .  j  av  a2 s .c  o m*/
    DefaultExecutor executor = new DefaultExecutor();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    executor.setStreamHandler(new PumpStreamHandler(outputStream));

    executor.setWatchdog(new ExecuteWatchdog(CMD_TIMEOUT));
    try {
        int exitValue = executor.execute(cmdLine);
        return new InterpreterResult(InterpreterResult.Code.SUCCESS, outputStream.toString());
    } catch (ExecuteException e) {
        logger.error("Can not run " + cmd, e);
        return new InterpreterResult(Code.ERROR, e.getMessage());
    } catch (IOException e) {
        logger.error("Can not run " + cmd, e);
        return new InterpreterResult(Code.ERROR, e.getMessage());
    }
}

From source file:io.selendroid.android.impl.DefaultAndroidApp.java

@Override
public void deleteFileFromWithinApk(String file) throws ShellCommandException, AndroidSdkException {
    CommandLine line = new CommandLine(AndroidSdk.aapt());
    line.addArgument("remove", false);
    line.addArgument(apkFile.getAbsolutePath(), false);
    line.addArgument(file, false);//www.  j a va2  s. c o  m

    ShellCommand.exec(line, 20000);
}

From source file:de.torstenwalter.maven.plugins.AbstractDatapumpMojo.java

protected void addCommonArguments(CommandLine commandLine) throws MojoFailureException {
    commandLine.addArgument("'" + getConnectionIdentifier() + "'", false);

    if (StringUtils.isNotEmpty(content)) {
        commandLine.addArgument("CONTENT=" + content);
    }/*  w w w.j  a  v  a2  s  . c  o  m*/

    commandLine.addArgument("DIRECTORY=" + directory);

    if (StringUtils.isNotEmpty(dumpfile)) {
        commandLine.addArgument("DUMPFILE=" + dumpfile);
    }

    if (StringUtils.isNotEmpty(exclude)) {
        commandLine.addArgument("EXCLUDE=" + exclude);
    }

    if (StringUtils.isNotEmpty(include)) {
        commandLine.addArgument("INCLUDE=" + include);
    }

    if (StringUtils.isNotEmpty(logfile)) {
        commandLine.addArgument("LOGFILE=" + logfile);
    }

    if (StringUtils.isNotEmpty(network_link)) {
        commandLine.addArgument("NETWORK_LINK=" + network_link);
    }

    if (StringUtils.isNotEmpty(schemas)) {
        commandLine.addArgument("SCHEMAS=" + schemas);
    }

    if (StringUtils.isNotEmpty(tables)) {
        commandLine.addArgument("TABLES=" + tables);
    }
}

From source file:io.selendroid.android.impl.DefaultAndroidApp.java

private String extractApkDetails(String regex) throws ShellCommandException, AndroidSdkException {
    CommandLine line = new CommandLine(AndroidSdk.aapt());

    line.addArgument("dump", false);
    line.addArgument("badging", false);
    line.addArgument(apkFile.getAbsolutePath(), false);
    String output = ShellCommand.exec(line, 20000);

    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(output);
    if (matcher.find()) {
        return matcher.group(1);
    }/*w  w w  .  j  a va2s  .c om*/

    return null;
}

From source file:io.selendroid.builder.SelendroidServerBuilderTest.java

@Test
public void testShouldBeAbleToCreateCustomizedSelendroidServerAndCleantTUp() throws Exception {
    SelendroidServerBuilder builder = getDefaultBuilder();
    builder.init(new DefaultAndroidApp(new File(APK_FILE)));
    builder.cleanUpPrebuildServer();/*from   ww w.ja  v a2s. c  om*/

    // Verify apk, if the files have been removed
    CommandLine cmd = new CommandLine(AndroidSdk.aapt());
    cmd.addArgument("list", false);
    cmd.addArgument(builder.getSelendroidServer().getAbsolutePath(), false);

    String output = ShellCommand.exec(cmd);

    assertResultDoesNotContainFile(output, "META-INF/CERT.RSA");
    assertResultDoesNotContainFile(output, "META-INF/CERT.SF");
    assertResultDoesNotContainFile(output, "AndroidManifest.xml");
    // just double check that dexed classes are there

    assertResultDoesContainFile(output, "classes.dex");
}

From source file:io.selendroid.builder.SelendroidServerBuilderTest.java

@Test
public void testShouldBeAbleToResignAnSignedApp() throws Exception {
    SelendroidServerBuilder builder = getDefaultBuilder();
    File androidApp = File.createTempFile("testapp", ".apk");
    FileUtils.copyFile(new File(APK_FILE), androidApp);
    AndroidApp app = builder.resignApp(androidApp);
    Assert.assertEquals("resigned-" + androidApp.getName(), new File(app.getAbsolutePath()).getName());
    // Verify that apk is signed
    CommandLine cmd = new CommandLine(AndroidSdk.aapt());
    cmd.addArgument("list", false);
    cmd.addArgument(app.getAbsolutePath(), false);

    String output = ShellCommand.exec(cmd);

    assertResultDoesNotContainFile(output, "META-INF/CERT.RSA");
    assertResultDoesNotContainFile(output, "META-INF/CERT.SF");
    assertResultDoesContainFile(output, "META-INF/ANDROIDD.SF");
    assertResultDoesContainFile(output, "META-INF/ANDROIDD.RSA");
    assertResultDoesContainFile(output, "AndroidManifest.xml");
}

From source file:io.selendroid.builder.SelendroidServerBuilderTest.java

@Test
public void testShouldBeAbleToCreateCustomizedAndroidApplicationXML() throws Exception {
    SelendroidServerBuilder builder = getDefaultBuilder();
    builder.init(new DefaultAndroidApp(new File(APK_FILE)));
    builder.cleanUpPrebuildServer();/*from   w  ww. jav a2s. c  o m*/
    File file = builder.createAndAddCustomizedAndroidManifestToSelendroidServer();
    ZipFile zipFile = new ZipFile(file);
    ZipArchiveEntry entry = zipFile.getEntry("AndroidManifest.xml");
    Assert.assertEquals(entry.getName(), "AndroidManifest.xml");
    Assert.assertTrue("Expecting non empty AndroidManifest.xml file", entry.getSize() > 700);

    // Verify that apk is not yet signed
    CommandLine cmd = new CommandLine(AndroidSdk.aapt());
    cmd.addArgument("list", false);
    cmd.addArgument(builder.getSelendroidServer().getAbsolutePath(), false);

    String output = ShellCommand.exec(cmd);

    assertResultDoesNotContainFile(output, "META-INF/CERT.RSA");
    assertResultDoesNotContainFile(output, "META-INF/CERT.SF");
}