Search in sources :

Example 1 with DefaultConsumer

use of org.codehaus.plexus.util.cli.DefaultConsumer in project maven-scm by apache.

the class BootstrapMojo method runGoals.

/**
 * @param relativePathProjectDirectory the project directory's path relative to the checkout
 *                                     directory; or "" if they are the same
 * @throws MojoExecutionException if any
 */
private void runGoals(String relativePathProjectDirectory) throws MojoExecutionException {
    Commandline cl = new Commandline();
    try {
        cl.addSystemEnvironment();
    } catch (Exception e) {
        throw new MojoExecutionException("Can't add system environment variables to mvn command line.", e);
    }
    cl.addEnvironment("MAVEN_TERMINATE_CMD", "on");
    if (this.mavenHome == null) {
        // none windows only
        cl.setExecutable("mvn");
    } else {
        String mvnPath = this.mavenHome.getAbsolutePath() + "/bin/mvn";
        if (Os.isFamily("windows")) {
            String winMvnPath = mvnPath + ".cmd";
            if (!new File(winMvnPath).exists()) {
                winMvnPath = mvnPath + ".bat";
            }
            mvnPath = winMvnPath;
        }
        cl.setExecutable(mvnPath);
    }
    cl.setWorkingDirectory(determineWorkingDirectoryPath(// 
    this.getCheckoutDirectory(), relativePathProjectDirectory, goalsDirectory));
    if (this.goals != null) {
        String[] tokens = StringUtils.split(this.goals, ", ");
        for (int i = 0; i < tokens.length; ++i) {
            cl.createArg().setValue(tokens[i]);
        }
    }
    if (!StringUtils.isEmpty(this.profiles)) {
        cl.createArg().setValue("-P" + this.profiles);
    }
    StreamConsumer consumer = new DefaultConsumer();
    try {
        int result = CommandLineUtils.executeCommandLine(cl, consumer, consumer);
        if (result != 0) {
            throw new MojoExecutionException("Result of mvn execution is: \'" + result + "\'. Release failed.");
        }
    } catch (CommandLineException e) {
        throw new MojoExecutionException("Can't run goal " + goals, e);
    }
}
Also used : StreamConsumer(org.codehaus.plexus.util.cli.StreamConsumer) Commandline(org.codehaus.plexus.util.cli.Commandline) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultConsumer(org.codehaus.plexus.util.cli.DefaultConsumer) File(java.io.File) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 2 with DefaultConsumer

use of org.codehaus.plexus.util.cli.DefaultConsumer in project tycho by eclipse.

the class SymbolicLinkTest method createSymbolicLink.

private static boolean createSymbolicLink(File target, File link) {
    Commandline commandline = new Commandline();
    commandline.setWorkingDirectory(link.getParentFile());
    commandline.addArguments(new String[] { "ln", "-s", target.getAbsolutePath(), link.getAbsolutePath() });
    try {
        int result = CommandLineUtils.executeCommandLine(commandline, new DefaultConsumer(), new DefaultConsumer());
        return 0 == result && link.exists();
    } catch (Throwable e) {
        return false;
    }
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) DefaultConsumer(org.codehaus.plexus.util.cli.DefaultConsumer)

Example 3 with DefaultConsumer

use of org.codehaus.plexus.util.cli.DefaultConsumer in project maven-scm by apache.

the class StarteamUpdateCommand method deleteLocal.

private void deleteLocal(StarteamScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) throws ScmException {
    if (fileSet.getFileList().size() != 0) {
        return;
    }
    Commandline cl = createDeleteLocalCommand(repo, fileSet, version);
    StreamConsumer consumer = new DefaultConsumer();
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode = StarteamCommandLineUtils.executeCommandline(cl, consumer, stderr, getLogger());
    if (exitCode != 0) {
        throw new ScmException("Error executing delete-local: " + stderr.toString());
    }
}
Also used : StreamConsumer(org.codehaus.plexus.util.cli.StreamConsumer) ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) DefaultConsumer(org.codehaus.plexus.util.cli.DefaultConsumer) StarteamCommandLineUtils(org.apache.maven.scm.provider.starteam.command.StarteamCommandLineUtils) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils)

Example 4 with DefaultConsumer

use of org.codehaus.plexus.util.cli.DefaultConsumer in project maven-plugins by apache.

the class GpgSigner method generateSignatureForFile.

/**
 * {@inheritDoc}
 */
@Override
protected void generateSignatureForFile(File file, File signature) throws MojoExecutionException {
    // ----------------------------------------------------------------------------
    // Set up the command line
    // ----------------------------------------------------------------------------
    Commandline cmd = new Commandline();
    if (StringUtils.isNotEmpty(executable)) {
        cmd.setExecutable(executable);
    } else {
        cmd.setExecutable("gpg" + (Os.isFamily(Os.FAMILY_WINDOWS) ? ".exe" : ""));
    }
    if (args != null) {
        for (String arg : args) {
            cmd.createArg().setValue(arg);
        }
    }
    if (homeDir != null) {
        cmd.createArg().setValue("--homedir");
        cmd.createArg().setFile(homeDir);
    }
    if (useAgent) {
        cmd.createArg().setValue("--use-agent");
    } else {
        cmd.createArg().setValue("--no-use-agent");
    }
    InputStream in = null;
    if (null != passphrase) {
        // make --passphrase-fd effective in gpg2
        cmd.createArg().setValue("--batch");
        cmd.createArg().setValue("--passphrase-fd");
        cmd.createArg().setValue("0");
        // Prepare the input stream which will be used to pass the passphrase to the executable
        in = new ByteArrayInputStream(passphrase.getBytes());
    }
    if (null != keyname) {
        cmd.createArg().setValue("--local-user");
        cmd.createArg().setValue(keyname);
    }
    cmd.createArg().setValue("--armor");
    cmd.createArg().setValue("--detach-sign");
    if (!isInteractive) {
        cmd.createArg().setValue("--no-tty");
    }
    if (!defaultKeyring) {
        cmd.createArg().setValue("--no-default-keyring");
    }
    if (StringUtils.isNotEmpty(secretKeyring)) {
        cmd.createArg().setValue("--secret-keyring");
        cmd.createArg().setValue(secretKeyring);
    }
    if (StringUtils.isNotEmpty(publicKeyring)) {
        cmd.createArg().setValue("--keyring");
        cmd.createArg().setValue(publicKeyring);
    }
    if ("once".equalsIgnoreCase(lockMode)) {
        cmd.createArg().setValue("--lock-once");
    } else if ("multiple".equalsIgnoreCase(lockMode)) {
        cmd.createArg().setValue("--lock-multiple");
    } else if ("never".equalsIgnoreCase(lockMode)) {
        cmd.createArg().setValue("--lock-never");
    }
    cmd.createArg().setValue("--output");
    cmd.createArg().setFile(signature);
    cmd.createArg().setFile(file);
    try {
        int exitCode = CommandLineUtils.executeCommandLine(cmd, in, new DefaultConsumer(), new DefaultConsumer());
        if (exitCode != 0) {
            throw new MojoExecutionException("Exit code: " + exitCode);
        }
    } catch (CommandLineException e) {
        throw new MojoExecutionException("Unable to execute gpg command", e);
    }
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) DefaultConsumer(org.codehaus.plexus.util.cli.DefaultConsumer) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Aggregations

Commandline (org.codehaus.plexus.util.cli.Commandline)4 DefaultConsumer (org.codehaus.plexus.util.cli.DefaultConsumer)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)2 StreamConsumer (org.codehaus.plexus.util.cli.StreamConsumer)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 ScmException (org.apache.maven.scm.ScmException)1 StarteamCommandLineUtils (org.apache.maven.scm.provider.starteam.command.StarteamCommandLineUtils)1 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)1