Search in sources :

Example 41 with Commandline

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

the class PerforceStatusCommand method readOpened.

private Commandline readOpened(PerforceScmProviderRepository prepo, ScmFileSet files, PerforceStatusConsumer consumer) {
    Commandline cl = createOpenedCommandLine(prepo, files.getBasedir(), actualLocation);
    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);
        }
    }
    return cl;
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 42 with Commandline

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

the class PerforceTagCommand method createLabel.

private void createLabel(ScmProviderRepository repo, ScmFileSet files, String tag, PerforceTagConsumer consumer, boolean lock) {
    Commandline cl = createLabelCommandLine((PerforceScmProviderRepository) repo, files.getBasedir());
    DataOutputStream dos = null;
    InputStreamReader isReader = null;
    InputStreamReader isReaderErr = null;
    try {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(PerforceScmProvider.clean("Executing: " + cl.toString()));
        }
        Process proc = cl.execute();
        OutputStream out = proc.getOutputStream();
        dos = new DataOutputStream(out);
        String label = createLabelSpecification((PerforceScmProviderRepository) repo, tag, lock);
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("LabelSpec: " + NEWLINE + label);
        }
        dos.write(label.getBytes());
        dos.close();
        out.close();
        // TODO find & use a less naive InputStream multiplexer
        isReader = new InputStreamReader(proc.getInputStream());
        isReaderErr = new InputStreamReader(proc.getErrorStream());
        BufferedReader stdout = new BufferedReader(isReader);
        BufferedReader stderr = new BufferedReader(isReaderErr);
        String line;
        while ((line = stdout.readLine()) != null) {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Consuming stdout: " + line);
            }
            consumer.consumeLine(line);
        }
        while ((line = stderr.readLine()) != null) {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Consuming stderr: " + line);
            }
            consumer.consumeLine(line);
        }
        stderr.close();
        stdout.close();
    } catch (CommandLineException e) {
        if (getLogger().isErrorEnabled()) {
            getLogger().error("CommandLineException " + e.getMessage(), e);
        }
    } catch (IOException e) {
        if (getLogger().isErrorEnabled()) {
            getLogger().error("IOException " + e.getMessage(), e);
        }
    } finally {
        IOUtil.close(dos);
        IOUtil.close(isReader);
        IOUtil.close(isReaderErr);
    }
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) InputStreamReader(java.io.InputStreamReader) DataOutputStream(java.io.DataOutputStream) OutputStream(java.io.OutputStream) DataOutputStream(java.io.DataOutputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 43 with Commandline

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

the class PerforceTagCommand method createLabelsyncCommandLine.

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

Example 44 with Commandline

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

the class PerforceTagCommand method syncLabel.

private void syncLabel(ScmProviderRepository repo, ScmFileSet files, String tag, PerforceTagConsumer consumer) {
    Commandline cl = createLabelsyncCommandLine((PerforceScmProviderRepository) repo, files.getBasedir(), files, tag);
    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);
        }
    }
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 45 with Commandline

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

the class PerforceTagCommand method createLabelCommandLine.

public static Commandline createLabelCommandLine(PerforceScmProviderRepository repo, File workingDirectory) {
    Commandline command = PerforceScmProvider.createP4Command(repo, workingDirectory);
    command.createArg().setValue("label");
    command.createArg().setValue("-i");
    return command;
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline)

Aggregations

Commandline (org.codehaus.plexus.util.cli.Commandline)443 File (java.io.File)131 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)116 ScmException (org.apache.maven.scm.ScmException)84 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)67 ScmRepository (org.apache.maven.scm.repository.ScmRepository)51 IOException (java.io.IOException)45 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 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 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)15 ScmFile (org.apache.maven.scm.ScmFile)13 CvsScmProviderRepository (org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository)13