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());
}
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);
}
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);
}
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());
}
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);
}
Aggregations