Search in sources :

Example 6 with ErrorConsumer

use of org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer in project maven-scm by apache.

the class JazzDiffCommand method executeDiffCommand.

/**
 * {@inheritDoc}
 */
protected DiffScmResult executeDiffCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion startRevision, ScmVersion endRevision) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("Executing diff command...");
    }
    File baseDir = fileSet.getBasedir();
    File parentFolder = (baseDir.getParentFile() != null) ? baseDir.getParentFile() : baseDir;
    // First execute the status command to get the list of changed files.
    JazzStatusCommand statusCmd = new JazzStatusCommand();
    statusCmd.setLogger(getLogger());
    StatusScmResult statusCmdResult = statusCmd.executeStatusCommand(repo, fileSet);
    List<ScmFile> statusScmFiles = statusCmdResult.getChangedFiles();
    // In this case, we also use it across multiple calls to "scm diff" so that we
    // sum all output into on.
    JazzScmCommand diffCmd = null;
    StringBuilder patch = new StringBuilder();
    Map<String, CharSequence> differences = new HashMap<String, CharSequence>();
    // Now lets iterate through them
    for (ScmFile file : statusScmFiles) {
        if (file.getStatus() == ScmFileStatus.MODIFIED) {
            // The "scm status" command returns files relative to the sandbox root.
            // Whereas the "scm diff" command needs them relative to the working directory.
            File fullPath = new File(parentFolder, file.getPath());
            String relativePath = fullPath.toString().substring(baseDir.toString().length());
            getLogger().debug("Full Path     : '" + fullPath + "'");
            getLogger().debug("Relative Path : '" + relativePath + "'");
            // Now call "scm diff on it"
            // In this case, we use the DebugLoggerConsumer's ability to store captured output
            DebugLoggerConsumer diffConsumer = new DebugLoggerConsumer(getLogger());
            ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
            diffCmd = createDiffCommand(repo, fileSet, relativePath);
            int status = diffCmd.execute(diffConsumer, errConsumer);
            if (status != 0) {
                // Return a false result (not the usual SCMResult)
                return new DiffScmResult(diffCmd.toString(), "The scm diff command failed.", errConsumer.getOutput(), false);
            }
            // Append to patch (all combined)
            patch.append(diffConsumer.getOutput());
            // Set the differences map <File, <CharSequence>
            differences.put(relativePath, diffConsumer.getOutput());
        }
    }
    return new DiffScmResult(diffCmd.toString(), statusCmdResult.getChangedFiles(), differences, patch.toString());
}
Also used : StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) HashMap(java.util.HashMap) ErrorConsumer(org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer) JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand) ScmFile(org.apache.maven.scm.ScmFile) JazzStatusCommand(org.apache.maven.scm.provider.jazz.command.status.JazzStatusCommand) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) DebugLoggerConsumer(org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer) DiffScmResult(org.apache.maven.scm.command.diff.DiffScmResult)

Example 7 with ErrorConsumer

use of org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer 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 ErrorConsumer

use of org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer in project maven-scm by apache.

the class JazzCheckInCommand method executeCheckInCommand.

/**
 * {@inheritDoc}
 */
protected CheckInScmResult executeCheckInCommand(ScmProviderRepository repository, ScmFileSet fileSet, String message, ScmVersion scmVersion) throws ScmException {
    if (scmVersion != null && StringUtils.isNotEmpty(scmVersion.getName())) {
        throw new ScmException("This provider command can't handle tags.");
    }
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("Executing checkin command...");
    }
    // Create a changeset. We need to do this, as otherwise the information contained in the message
    // will be lost forever.
    JazzScmCommand createChangesetCmd = createCreateChangesetCommand(repository, fileSet, message);
    DebugLoggerConsumer outputConsumer = new DebugLoggerConsumer(getLogger());
    ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
    int status = createChangesetCmd.execute(outputConsumer, errConsumer);
    if (status != 0) {
        return new CheckInScmResult(createChangesetCmd.getCommandString(), "Error code for Jazz SCM create changeset command - " + status, errConsumer.getOutput(), false);
    }
    // As we just created a change set, we now need to call the status command so we can parse the
    // newly created change set.
    JazzStatusCommand statusCommand = new JazzStatusCommand();
    statusCommand.setLogger(getLogger());
    statusCommand.executeStatusCommand(repository, fileSet);
    // NOTE: For isPushChangesAndHaveFlowTargets() to work, a scm status call must have been called first!!!
    // As the Workspace name and alias, and the Flow Target name and alias are needed.
    // Check to see if we've got a flow target and had a workItem defined (via -DworkItem=XXXX)
    JazzScmProviderRepository jazzRepo = (JazzScmProviderRepository) repository;
    if (jazzRepo.isPushChangesAndHaveFlowTargets() && StringUtils.isNotEmpty(jazzRepo.getWorkItem())) {
        List<Integer> changeSetAliases = jazzRepo.getOutgoingChangeSetAliases();
        if (changeSetAliases != null && !changeSetAliases.isEmpty()) {
            for (Integer changeSetAlias : changeSetAliases) {
                // Associate a work item if we need too.
                JazzScmCommand changesetAssociateCmd = createChangesetAssociateCommand(repository, changeSetAlias);
                outputConsumer = new DebugLoggerConsumer(getLogger());
                errConsumer = new ErrorConsumer(getLogger());
                status = changesetAssociateCmd.execute(outputConsumer, errConsumer);
                if (status != 0) {
                    return new CheckInScmResult(changesetAssociateCmd.getCommandString(), "Error code for Jazz SCM changeset associate command - " + status, errConsumer.getOutput(), false);
                }
            }
        }
    }
    // Now check in the files themselves.
    return executeCheckInCommand(repository, fileSet, scmVersion);
}
Also used : ScmException(org.apache.maven.scm.ScmException) JazzStatusCommand(org.apache.maven.scm.provider.jazz.command.status.JazzStatusCommand) ErrorConsumer(org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer) JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand) 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 9 with ErrorConsumer

use of org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer in project maven-scm by apache.

the class JazzCheckOutCommand method executeCheckOutCommand.

/**
 * {@inheritDoc}
 */
protected CheckOutScmResult executeCheckOutCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion scmVersion, boolean recursive, boolean shallow) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("Executing checkout command...");
    }
    JazzScmProviderRepository jazzRepo = (JazzScmProviderRepository) repo;
    JazzScmCommand checkoutCmd = createJazzLoadCommand(jazzRepo, fileSet, scmVersion);
    JazzCheckOutConsumer checkoutConsumer = new JazzCheckOutConsumer(repo, getLogger());
    ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
    int status = checkoutCmd.execute(checkoutConsumer, errConsumer);
    if (status != 0) {
        return new CheckOutScmResult(checkoutCmd.getCommandString(), "Error code for Jazz SCM checkout (load) command - " + status, errConsumer.getOutput(), false);
    }
    return new CheckOutScmResult(checkoutCmd.getCommandString(), checkoutConsumer.getCheckedOutFiles());
}
Also used : ErrorConsumer(org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer) JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) JazzScmProviderRepository(org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository)

Example 10 with ErrorConsumer

use of org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer in project maven-scm by apache.

the class JazzEditCommand method executeEditCommand.

/**
 * {@inheritDoc}
 */
protected ScmResult executeEditCommand(ScmProviderRepository repo, ScmFileSet fileSet) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("Executing edit command...");
    }
    DebugLoggerConsumer editConsumer = new DebugLoggerConsumer(getLogger());
    ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
    JazzScmCommand editCmd = createEditCommand(repo, fileSet);
    int status = editCmd.execute(editConsumer, errConsumer);
    if (status != 0) {
        return new EditScmResult(editCmd.getCommandString(), "Error code for Jazz SCM edit command - " + status, errConsumer.getOutput(), false);
    }
    return new EditScmResult(editCmd.getCommandString(), "Successfully Completed.", editConsumer.getOutput(), true);
}
Also used : ErrorConsumer(org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer) EditScmResult(org.apache.maven.scm.command.edit.EditScmResult) JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand) DebugLoggerConsumer(org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer)

Aggregations

ErrorConsumer (org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer)14 JazzScmCommand (org.apache.maven.scm.provider.jazz.command.JazzScmCommand)13 DebugLoggerConsumer (org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer)7 JazzScmProviderRepository (org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository)6 ScmFile (org.apache.maven.scm.ScmFile)5 File (java.io.File)3 ArrayList (java.util.ArrayList)3 StatusScmResult (org.apache.maven.scm.command.status.StatusScmResult)3 JazzStatusCommand (org.apache.maven.scm.provider.jazz.command.status.JazzStatusCommand)3 StreamConsumer (org.codehaus.plexus.util.cli.StreamConsumer)3 ScmException (org.apache.maven.scm.ScmException)2 AddScmResult (org.apache.maven.scm.command.add.AddScmResult)2 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)2 HashMap (java.util.HashMap)1 ChangeSet (org.apache.maven.scm.ChangeSet)1 ScmResult (org.apache.maven.scm.ScmResult)1 BlameScmResult (org.apache.maven.scm.command.blame.BlameScmResult)1 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)1 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)1 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)1