Search in sources :

Example 46 with Commandline

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

the class PerforceUnEditCommand method createCommandLine.

public static Commandline createCommandLine(PerforceScmProviderRepository repo, File workingDirectory, ScmFileSet files) {
    Commandline command = PerforceScmProvider.createP4Command(repo, workingDirectory);
    command.createArg().setValue("revert");
    List<File> fs = files.getFileList();
    for (File file : fs) {
        command.createArg().setValue(file.getName());
    }
    return command;
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) File(java.io.File)

Example 47 with Commandline

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

the class PerforceUnEditCommand method executeUnEditCommand.

/**
 * {@inheritDoc}
 */
protected ScmResult executeUnEditCommand(ScmProviderRepository repo, ScmFileSet files) throws ScmException {
    Commandline cl = createCommandLine((PerforceScmProviderRepository) repo, files.getBasedir(), files);
    PerforceUnEditConsumer consumer = new PerforceUnEditConsumer();
    try {
        CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
        int exitCode = CommandLineUtils.executeCommandLine(cl, consumer, err);
        if (exitCode != 0) {
            String cmdLine = CommandLineUtils.toString(cl.getCommandline());
            StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + err.getOutput());
            msg.append('\n');
            msg.append("Command line was:" + cmdLine);
            throw new CommandLineException(msg.toString());
        }
    } catch (CommandLineException e) {
        if (getLogger().isErrorEnabled()) {
            getLogger().error("CommandLineException " + e.getMessage(), e);
        }
    }
    if (consumer.isSuccess()) {
        return new UnEditScmResult(cl.toString(), consumer.getEdits());
    }
    return new UnEditScmResult(cl.toString(), "Unable to revert", consumer.getOutput(), consumer.isSuccess());
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) UnEditScmResult(org.apache.maven.scm.command.unedit.UnEditScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 48 with Commandline

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

the class PerforceScmProvider method createP4Command.

public static Commandline createP4Command(PerforceScmProviderRepository repo, File workingDir) {
    Commandline command = new Commandline();
    command.setExecutable("p4");
    if (workingDir != null) {
        // SCM-209
        command.createArg().setValue("-d");
        command.createArg().setValue(workingDir.getAbsolutePath());
    }
    if (repo.getHost() != null) {
        command.createArg().setValue("-p");
        String value = "";
        if (!StringUtils.isBlank(repo.getProtocol())) {
            value += repo.getProtocol() + ":";
        }
        value += repo.getHost();
        if (repo.getPort() != 0) {
            value += ":" + Integer.toString(repo.getPort());
        }
        command.createArg().setValue(value);
    }
    if (StringUtils.isNotEmpty(repo.getUser())) {
        command.createArg().setValue("-u");
        command.createArg().setValue(repo.getUser());
    }
    if (StringUtils.isNotEmpty(repo.getPassword())) {
        command.createArg().setValue("-P");
        command.createArg().setValue(repo.getPassword());
    }
    return command;
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline)

Example 49 with Commandline

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

the class PerforceScmProvider method isLive.

public static boolean isLive() {
    if (live == null) {
        if (!Boolean.getBoolean("maven.scm.testing")) {
            // We are not executing in the tests so we are live.
            live = Boolean.TRUE;
        } else {
            // anything that requires an active server connection.
            try {
                Commandline command = new Commandline();
                command.setExecutable("p4");
                Process proc = command.execute();
                BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
                @SuppressWarnings("unused") String line;
                while ((line = br.readLine()) != null) {
                // System.out.println(line);
                }
                int rc = proc.exitValue();
                live = (rc == 0 ? Boolean.TRUE : Boolean.FALSE);
            } catch (Exception e) {
                e.printStackTrace();
                live = Boolean.FALSE;
            }
        }
    }
    return live.booleanValue();
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ScmRepositoryException(org.apache.maven.scm.repository.ScmRepositoryException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ScmException(org.apache.maven.scm.ScmException)

Example 50 with Commandline

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

the class PerforceAddCommand method executeAddCommand.

/**
 * {@inheritDoc}
 */
protected ScmResult executeAddCommand(ScmProviderRepository repo, ScmFileSet files, String message, boolean binary) throws ScmException {
    Commandline cl = createCommandLine((PerforceScmProviderRepository) repo, files.getBasedir(), files);
    PerforceAddConsumer consumer = new PerforceAddConsumer();
    try {
        CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
        int exitCode = CommandLineUtils.executeCommandLine(cl, consumer, err);
        if (exitCode != 0) {
            String cmdLine = CommandLineUtils.toString(cl.getCommandline());
            StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + err.getOutput());
            msg.append('\n');
            msg.append("Command line was:" + cmdLine);
            throw new CommandLineException(msg.toString());
        }
    } catch (CommandLineException e) {
        if (getLogger().isErrorEnabled()) {
            getLogger().error("CommandLineException " + e.getMessage(), e);
        }
    }
    return new AddScmResult(cl.toString(), consumer.getAdditions());
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Aggregations

Commandline (org.codehaus.plexus.util.cli.Commandline)446 File (java.io.File)133 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)117 ScmException (org.apache.maven.scm.ScmException)84 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)70 ScmRepository (org.apache.maven.scm.repository.ScmRepository)51 IOException (java.io.IOException)48 ScmFileSet (org.apache.maven.scm.ScmFileSet)34 Test (org.junit.Test)28 StringStreamConsumer (org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer)26 ArrayList (java.util.ArrayList)22 StarteamScmProviderRepository (org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository)22 PerforceScmProviderRepository (org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository)19 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)18 SvnCommandLineUtils (org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils)17 GitCommandLineUtils (org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils)16 GitScmProviderRepository (org.apache.maven.scm.provider.git.repository.GitScmProviderRepository)16 SvnScmProviderRepository (org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository)16 ScmFile (org.apache.maven.scm.ScmFile)13 CvsScmProviderRepository (org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository)13