Search in sources :

Example 1 with StringStreamConsumer

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

the class TfsTagCommand method executeTagCommand.

protected ScmResult executeTagCommand(ScmProviderRepository r, ScmFileSet f, String tag, ScmTagParameters scmTagParameters) throws ScmException {
    TfsCommand command = createCommand(r, f, tag, scmTagParameters);
    StringStreamConsumer out = new StringStreamConsumer();
    ErrorStreamConsumer err = new ErrorStreamConsumer();
    int status = command.execute(out, err);
    if (status != 0 || err.hasBeenFed()) {
        return new TagScmResult(command.getCommandString(), "Error code for TFS label command - " + status, err.getOutput(), false);
    }
    List<ScmFile> files = new ArrayList<ScmFile>(f.getFileList().size());
    for (File file : f.getFileList()) {
        files.add(new ScmFile(file.getPath(), ScmFileStatus.TAGGED));
    }
    return new TagScmResult(command.getCommandString(), files);
}
Also used : ArrayList(java.util.ArrayList) StringStreamConsumer(org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) ErrorStreamConsumer(org.apache.maven.scm.provider.tfs.command.consumer.ErrorStreamConsumer) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 2 with StringStreamConsumer

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

the class TfsBranchCommand method executeBranchCommand.

protected ScmResult executeBranchCommand(ScmProviderRepository r, ScmFileSet f, String branch, String message) throws ScmException {
    TfsCommand command = createCommand(r, f, branch);
    StringStreamConsumer out = new StringStreamConsumer();
    ErrorStreamConsumer err = new ErrorStreamConsumer();
    int status = command.execute(out, err);
    getLogger().info("status of branch command is= " + status + "; err= " + err.getOutput());
    if (status != 0 || err.hasBeenFed()) {
        return new BranchScmResult(command.getCommandString(), "Error code for TFS branch command - " + status, err.getOutput(), false);
    }
    return new BranchScmResult(command.getCommandString(), new ArrayList<ScmFile>(0));
}
Also used : StringStreamConsumer(org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer) ErrorStreamConsumer(org.apache.maven.scm.provider.tfs.command.consumer.ErrorStreamConsumer) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult) ScmFile(org.apache.maven.scm.ScmFile)

Example 3 with StringStreamConsumer

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

the class TfsCommand method execute.

public int execute(StreamConsumer out, ErrorStreamConsumer err) throws ScmException {
    info("Command line - " + getCommandString());
    int status;
    try {
        status = CommandLineUtils.executeCommandLine(command, out, err);
    } catch (CommandLineException e) {
        throw new ScmException("Error while executing TFS command line - " + getCommandString(), e);
    }
    info("err - " + err.getOutput());
    if (out instanceof StringStreamConsumer) {
        StringStreamConsumer sc = (StringStreamConsumer) out;
        debug(sc.getOutput());
    }
    if (out instanceof FileListConsumer) {
        FileListConsumer f = (FileListConsumer) out;
        for (Iterator<ScmFile> i = f.getFiles().iterator(); i.hasNext(); ) {
            ScmFile file = i.next();
            debug(file.getPath());
        }
    }
    return status;
}
Also used : FileListConsumer(org.apache.maven.scm.provider.tfs.command.consumer.FileListConsumer) ScmException(org.apache.maven.scm.ScmException) StringStreamConsumer(org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) ScmFile(org.apache.maven.scm.ScmFile)

Example 4 with StringStreamConsumer

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

the class ScmTestCase method execute.

/**
 * Execute the command line
 *
 * @param workingDirectory not null
 * @param executable       not null, should be a system command
 * @param arguments        not null
 * @throws Exception if any
 * @see CommandLineUtils#executeCommandLine(Commandline, org.codehaus.plexus.util.cli.StreamConsumer,
 *      org.codehaus.plexus.util.cli.StreamConsumer)
 */
public static void execute(File workingDirectory, String executable, String arguments) throws Exception {
    Commandline cl = new Commandline();
    cl.setExecutable(executable);
    cl.setWorkingDirectory(workingDirectory.getAbsolutePath());
    cl.addArguments(CommandLineUtils.translateCommandline(arguments));
    StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
    StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    System.out.println("Test command line: " + cl);
    int exitValue = CommandLineUtils.executeCommandLine(cl, stdout, stderr);
    if (debugExecute || exitValue != 0) {
        System.err.println("-----------------------------------------");
        System.err.println("Command line: " + cl);
        System.err.println("Working directory: " + cl.getWorkingDirectory());
        System.err.println("-----------------------------------------");
        System.err.println("Standard output: ");
        System.err.println("-----------------------------------------");
        System.err.println(stdout.getOutput());
        System.err.println("-----------------------------------------");
        System.err.println("Standard error: ");
        System.err.println("-----------------------------------------");
        System.err.println(stderr.getOutput());
        System.err.println("-----------------------------------------");
    }
    if (exitValue != 0) {
        fail("Exit value wasn't 0, was:" + exitValue);
    }
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) StringStreamConsumer(org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer)

Aggregations

StringStreamConsumer (org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer)4 ScmFile (org.apache.maven.scm.ScmFile)3 ErrorStreamConsumer (org.apache.maven.scm.provider.tfs.command.consumer.ErrorStreamConsumer)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 ScmException (org.apache.maven.scm.ScmException)1 BranchScmResult (org.apache.maven.scm.command.branch.BranchScmResult)1 TagScmResult (org.apache.maven.scm.command.tag.TagScmResult)1 FileListConsumer (org.apache.maven.scm.provider.tfs.command.consumer.FileListConsumer)1 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)1 Commandline (org.codehaus.plexus.util.cli.Commandline)1