Search in sources :

Example 6 with StreamConsumer

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

the class JazzCheckInCommand method executeCheckInCommand.

protected CheckInScmResult executeCheckInCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion scmVersion) throws ScmException {
    // Call the Add command to perform the checkin into the repository workspace.
    JazzAddCommand addCommand = new JazzAddCommand();
    addCommand.setLogger(getLogger());
    AddScmResult addResult = addCommand.executeAddCommand(repo, fileSet);
    // Now, if it has a flow target, deliver it.
    JazzScmProviderRepository jazzRepo = (JazzScmProviderRepository) repo;
    if (jazzRepo.isPushChangesAndHaveFlowTargets()) {
        // Push if we need too
        JazzScmCommand deliverCmd = createDeliverCommand((JazzScmProviderRepository) repo, fileSet);
        StreamConsumer deliverConsumer = // No need for a dedicated consumer for this
        new DebugLoggerConsumer(getLogger());
        ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
        int status = deliverCmd.execute(deliverConsumer, errConsumer);
        if (status != 0) {
            return new CheckInScmResult(deliverCmd.getCommandString(), "Error code for Jazz SCM deliver command - " + status, errConsumer.getOutput(), false);
        }
    }
    // Return what was added.
    return new CheckInScmResult(addResult.getCommandLine(), addResult.getAddedFiles());
}
Also used : StreamConsumer(org.codehaus.plexus.util.cli.StreamConsumer) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) ErrorConsumer(org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer) JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand) JazzAddCommand(org.apache.maven.scm.provider.jazz.command.add.JazzAddCommand) DebugLoggerConsumer(org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) JazzScmProviderRepository(org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository)

Example 7 with StreamConsumer

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

the class JazzTckUtil method executeCommand.

/* (non-Javadoc)
    * @see org.apache.maven.scm.command.AbstractCommand#executeCommand(org.apache.maven.scm.provider.ScmProviderRepository, org.apache.maven.scm.ScmFileSet, org.apache.maven.scm.CommandParameters)
    */
@Override
protected ScmResult executeCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    JazzScmProviderRepository jazzRepo = (JazzScmProviderRepository) repository;
    StreamConsumer tckConsumer = // No need for a dedicated consumer for this
    new DebugLoggerConsumer(getLogger());
    ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
    String nameWorkspace = jazzRepo.getRepositoryWorkspace();
    // String nameSnapshot = "MavenSCMTestSnapshot";
    String nameSnapshot = getSnapshotName();
    JazzScmCommand tckCreateWorkspaceFromSnapshotCmd = createCreateWorkspaceFromSnapshotCommand(jazzRepo, fileSet, nameWorkspace, nameSnapshot);
    int status = tckCreateWorkspaceFromSnapshotCmd.execute(tckConsumer, errConsumer);
    if (status != 0) {
        return new ScmResult(tckCreateWorkspaceFromSnapshotCmd.getCommandString(), "Error code for Jazz SCM (create workspace --snapshot) command - " + status, errConsumer.getOutput(), false);
    }
    return new ScmResult(tckCreateWorkspaceFromSnapshotCmd.getCommandString(), "All ok", ((DebugLoggerConsumer) tckConsumer).getOutput(), true);
}
Also used : StreamConsumer(org.codehaus.plexus.util.cli.StreamConsumer) ScmResult(org.apache.maven.scm.ScmResult) ErrorConsumer(org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer) DebugLoggerConsumer(org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer) JazzScmProviderRepository(org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository)

Example 8 with StreamConsumer

use of org.codehaus.plexus.util.cli.StreamConsumer in project maven-clean-plugin by apache.

the class Utils method createSymlink.

/**
 * Creates a symbolic link.
 *
 * @param target The target (file or directory) of the link, must not be <code>null</code>.
 * @param link The path to the link, must not be <code>null</code>.
 * @return <code>true</code> if the symlink could be created, <code>false</code> otherwise.
 */
public static boolean createSymlink(File target, File link) {
    try {
        Commandline cli = new Commandline();
        cli.setExecutable("ln");
        cli.createArg().setValue("-s");
        cli.createArg().setFile(target);
        cli.createArg().setFile(link);
        int code = CommandLineUtils.executeCommandLine(cli, new StreamConsumer() {

            public void consumeLine(String line) {
                System.out.println(line);
            }
        }, new StreamConsumer() {

            public void consumeLine(String line) {
                System.err.println(line);
            }
        });
        return 0 == code;
    } catch (Exception e) {
        return false;
    }
}
Also used : StreamConsumer(org.codehaus.plexus.util.cli.StreamConsumer) Commandline(org.codehaus.plexus.util.cli.Commandline)

Example 9 with StreamConsumer

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

the class Utils method createSymlink.

/**
 * Creates a symbolic link.
 *
 * @param target The target (file or directory) of the link, must not be <code>null</code>.
 * @param link The path to the link, must not be <code>null</code>.
 * @return <code>true</code> if the symlink could be created, <code>false</code> otherwise.
 */
public static boolean createSymlink(File target, File link) {
    try {
        Commandline cli = new Commandline();
        cli.setExecutable("ln");
        cli.createArg().setValue("-s");
        cli.createArg().setFile(target);
        cli.createArg().setFile(link);
        int code = CommandLineUtils.executeCommandLine(cli, new StreamConsumer() {

            public void consumeLine(String line) {
                System.out.println(line);
            }
        }, new StreamConsumer() {

            public void consumeLine(String line) {
                System.err.println(line);
            }
        });
        return 0 == code;
    } catch (Exception e) {
        return false;
    }
}
Also used : StreamConsumer(org.codehaus.plexus.util.cli.StreamConsumer) Commandline(org.codehaus.plexus.util.cli.Commandline)

Example 10 with StreamConsumer

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

the class AbstractInvokerMojo method resolveExternalJreVersion.

private CharSequence resolveExternalJreVersion() {
    Artifact pluginArtifact = mojoExecution.getMojoDescriptor().getPluginDescriptor().getPluginArtifact();
    pluginArtifact.getFile();
    Commandline commandLine = new Commandline();
    commandLine.setExecutable(new File(javaHome, "bin/java").getAbsolutePath());
    commandLine.createArg().setValue("-cp");
    commandLine.createArg().setFile(pluginArtifact.getFile());
    commandLine.createArg().setValue(SystemPropertyPrinter.class.getName());
    commandLine.createArg().setValue("java.version");
    final StringBuilder actualJreVersion = new StringBuilder();
    StreamConsumer consumer = new StreamConsumer() {

        public void consumeLine(String line) {
            actualJreVersion.append(line);
        }
    };
    try {
        CommandLineUtils.executeCommandLine(commandLine, consumer, null);
    } catch (CommandLineException e) {
        getLog().warn(e.getMessage());
    }
    return actualJreVersion;
}
Also used : StreamConsumer(org.codehaus.plexus.util.cli.StreamConsumer) Commandline(org.codehaus.plexus.util.cli.Commandline) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Aggregations

StreamConsumer (org.codehaus.plexus.util.cli.StreamConsumer)17 File (java.io.File)10 Commandline (org.codehaus.plexus.util.cli.Commandline)9 ArrayList (java.util.ArrayList)7 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 Test (org.junit.Test)4 DebugLoggerConsumer (org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer)3 ErrorConsumer (org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer)3 JazzScmProviderRepository (org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository)3 IOException (java.io.IOException)2 URI (java.net.URI)2 AbstractArtifactResolutionException (org.apache.maven.artifact.resolver.AbstractArtifactResolutionException)2 JazzScmCommand (org.apache.maven.scm.provider.jazz.command.JazzScmCommand)2 JarArchiver (org.codehaus.plexus.archiver.jar.JarArchiver)2 Manifest (org.codehaus.plexus.archiver.jar.Manifest)2 Attribute (org.codehaus.plexus.archiver.jar.Manifest.Attribute)2 DefaultConsumer (org.codehaus.plexus.util.cli.DefaultConsumer)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1