Search in sources :

Example 81 with CommandLineException

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

the class PerforceCheckInCommand method executeCheckInCommand.

/**
 * {@inheritDoc}
 */
@Override
protected CheckInScmResult executeCheckInCommand(ScmProviderRepository repo, ScmFileSet files, String message, ScmVersion version) throws ScmException {
    Commandline cl = createCommandLine((PerforceScmProviderRepository) repo, files.getBasedir());
    PerforceCheckInConsumer consumer = new PerforceCheckInConsumer();
    try {
        String jobs = System.getProperty("maven.scm.jobs");
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(PerforceScmProvider.clean("Executing " + cl.toString()));
        }
        PerforceScmProviderRepository prepo = (PerforceScmProviderRepository) repo;
        String changes = createChangeListSpecification(prepo, files, message, PerforceScmProvider.getRepoPath(getLogger(), prepo, files.getBasedir()), jobs);
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Sending changelist:\n" + changes);
        }
        CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
        int exitCode = CommandLineUtils.executeCommandLine(cl, new ByteArrayInputStream(changes.getBytes()), 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 CheckInScmResult(cl.toString(), consumer.isSuccess() ? "Checkin successful" : "Unable to submit", consumer.getOutput(), consumer.isSuccess());
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) ByteArrayInputStream(java.io.ByteArrayInputStream) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) PerforceScmProviderRepository(org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 82 with CommandLineException

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

the class PerforceDiffCommand method executeDiffCommand.

/**
 * {@inheritDoc}
 */
protected DiffScmResult executeDiffCommand(ScmProviderRepository repo, ScmFileSet files, ScmVersion startRev, ScmVersion endRev) throws ScmException {
    Commandline cl = createCommandLine((PerforceScmProviderRepository) repo, files.getBasedir(), startRev, endRev);
    PerforceDiffConsumer consumer = new PerforceDiffConsumer();
    if (getLogger().isInfoEnabled()) {
        getLogger().info("Executing: " + PerforceScmProvider.clean(cl.toString()));
    }
    boolean success = false;
    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 DiffScmResult(cl.toString(), success ? "Diff successful" : "Unable to diff", consumer.getOutput(), success);
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) DiffScmResult(org.apache.maven.scm.command.diff.DiffScmResult)

Example 83 with CommandLineException

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

the class PerforceEditCommand method executeEditCommand.

/**
 * {@inheritDoc}
 */
@Override
protected ScmResult executeEditCommand(ScmProviderRepository repo, ScmFileSet files) throws ScmException {
    Commandline cl = createCommandLine((PerforceScmProviderRepository) repo, files.getBasedir(), files);
    PerforceEditConsumer consumer = new PerforceEditConsumer();
    try {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(PerforceScmProvider.clean("Executing " + cl.toString()));
        }
        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 EditScmResult(cl.toString(), consumer.getEdits());
    }
    return new EditScmResult(cl.toString(), "Unable to edit file(s)", consumer.getErrorMessage(), false);
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) EditScmResult(org.apache.maven.scm.command.edit.EditScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 84 with CommandLineException

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

the class PerforceLoginCommand method executeLoginCommand.

/**
 * {@inheritDoc}
 */
public LoginScmResult executeLoginCommand(ScmProviderRepository repo, ScmFileSet files, CommandParameters params) throws ScmException {
    Commandline cl = createCommandLine((PerforceScmProviderRepository) repo, files.getBasedir());
    PerforceLoginConsumer consumer = new PerforceLoginConsumer();
    boolean isSuccess = false;
    try {
        String password = repo.getPassword();
        if (StringUtils.isEmpty(password)) {
            if (getLogger().isInfoEnabled()) {
                getLogger().info("No password found, proceeding without it.");
            }
            isSuccess = true;
        } else {
            CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
            int exitCode = CommandLineUtils.executeCommandLine(cl, new ByteArrayInputStream(password.getBytes()), consumer, err);
            isSuccess = consumer.isSuccess();
            if (!isSuccess) {
                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) {
        throw new ScmException(e.getMessage(), e);
    }
    return new LoginScmResult(cl.toString(), isSuccess ? "Login successful" : "Login failed", consumer.getOutput(), isSuccess);
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) LoginScmResult(org.apache.maven.scm.command.login.LoginScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) ByteArrayInputStream(java.io.ByteArrayInputStream) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils)

Example 85 with CommandLineException

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

the class PerforceInfoCommand method executeCommand.

/**
 * {@inheritDoc}
 */
protected ScmResult executeCommand(ScmProviderRepository repo, ScmFileSet scmFileSet, CommandParameters commandParameters) throws ScmException {
    if (!PerforceScmProvider.isLive()) {
        return null;
    }
    InputStreamReader isReader = null;
    try {
        Commandline command = PerforceScmProvider.createP4Command((PerforceScmProviderRepository) repo, null);
        command.createArg().setValue("info");
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(PerforceScmProvider.clean("Executing: " + command.toString()));
        }
        Process proc = command.execute();
        isReader = new InputStreamReader(proc.getInputStream());
        BufferedReader br = new BufferedReader(isReader);
        String line;
        entries = new HashMap<String, String>();
        while ((line = br.readLine()) != null) {
            int idx = line.indexOf(':');
            if (idx == -1) {
                if (line.indexOf("Client unknown.") == -1) {
                    throw new IllegalStateException("Unexpected results from 'p4 info' command: " + line);
                }
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("Cannot find client.");
                }
                entries.put("Client root", "");
            } else {
                String key = line.substring(0, idx);
                String value = line.substring(idx + 1).trim();
                entries.put(key, value);
            }
        }
    } catch (CommandLineException e) {
        throw new ScmException(e.getLocalizedMessage());
    } catch (IOException e) {
        throw new ScmException(e.getLocalizedMessage());
    } finally {
        IOUtil.close(isReader);
    }
    return null;
}
Also used : ScmException(org.apache.maven.scm.ScmException) InputStreamReader(java.io.InputStreamReader) Commandline(org.codehaus.plexus.util.cli.Commandline) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Aggregations

CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)94 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)76 Commandline (org.codehaus.plexus.util.cli.Commandline)67 ScmException (org.apache.maven.scm.ScmException)56 IOException (java.io.IOException)20 SvnCommandLineUtils (org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils)18 File (java.io.File)14 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)13 BufferedReader (java.io.BufferedReader)6 BlameScmResult (org.apache.maven.scm.command.blame.BlameScmResult)6 StatusScmResult (org.apache.maven.scm.command.status.StatusScmResult)6 SvnScmProviderRepository (org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository)6 InputStreamReader (java.io.InputStreamReader)5 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)5 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)5 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)5 StreamConsumer (org.codehaus.plexus.util.cli.StreamConsumer)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 StringTokenizer (java.util.StringTokenizer)4 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)4