use of org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer in project maven-scm by apache.
the class JazzTagCommand method executeTagCommand.
/**
* {@inheritDoc}
*/
protected ScmResult executeTagCommand(ScmProviderRepository repo, ScmFileSet fileSet, String tag, ScmTagParameters scmTagParameters) throws ScmException {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Executing tag command...");
}
JazzScmProviderRepository jazzRepo = (JazzScmProviderRepository) repo;
getLogger().debug("Creating Snapshot...");
StreamConsumer tagConsumer = // No need for a dedicated consumer for this
new DebugLoggerConsumer(getLogger());
ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
JazzScmCommand tagCreateSnapshotCmd = createTagCreateSnapshotCommand(jazzRepo, fileSet, tag, scmTagParameters);
int status = tagCreateSnapshotCmd.execute(tagConsumer, errConsumer);
if (status != 0) {
return new TagScmResult(tagCreateSnapshotCmd.getCommandString(), "Error code for Jazz SCM tag (SNAPSHOT) command - " + status, errConsumer.getOutput(), false);
}
// ------------------------------------------------------------------
// We create the workspace based on the tag here, as the scm tool
// can not currently check directly out from a snapshot (only a workspace).
getLogger().debug("Creating Workspace from Snapshot...");
JazzScmCommand tagCreateWorkspaceCmd = createTagCreateWorkspaceCommand(jazzRepo, fileSet, tag);
errConsumer = new ErrorConsumer(getLogger());
status = tagCreateWorkspaceCmd.execute(tagConsumer, errConsumer);
if (status != 0) {
return new TagScmResult(tagCreateWorkspaceCmd.getCommandString(), "Error code for Jazz SCM tag (WORKSPACE) command - " + status, errConsumer.getOutput(), false);
}
if (jazzRepo.isPushChangesAndHaveFlowTargets()) {
// isPushChanges = true, and we have something to deliver and promote to.
getLogger().debug("Promoting and delivering...");
// So we deliver the code to the target stream (or workspace)
getLogger().debug("Delivering...");
JazzScmCommand tagDeliverCommand = createTagDeliverCommand(jazzRepo, fileSet, tag);
errConsumer = new ErrorConsumer(getLogger());
status = tagDeliverCommand.execute(tagConsumer, errConsumer);
if (status != 0) {
return new TagScmResult(tagDeliverCommand.getCommandString(), "Error code for Jazz SCM deliver command - " + status, errConsumer.getOutput(), false);
}
// And now we promote the snapshot to the target stream (or workspace)
getLogger().debug("Promoting snapshot...");
JazzScmCommand tagSnapshotPromoteCommand = createTagSnapshotPromoteCommand(jazzRepo, fileSet, tag);
errConsumer = new ErrorConsumer(getLogger());
status = tagSnapshotPromoteCommand.execute(tagConsumer, errConsumer);
if (status != 0) {
return new TagScmResult(tagSnapshotPromoteCommand.getCommandString(), "Error code for Jazz SCM snapshot promote command - " + status, errConsumer.getOutput(), false);
}
}
// We don't have a JazzTagConsumer so just build up all the files...
List<ScmFile> taggedFiles = new ArrayList<ScmFile>(fileSet.getFileList().size());
for (File f : fileSet.getFileList()) {
taggedFiles.add(new ScmFile(f.getPath(), ScmFileStatus.TAGGED));
}
// So we return tagSnapshotCmd and not tagWorkspaceCmd.
return new TagScmResult(tagCreateSnapshotCmd.getCommandString(), taggedFiles);
}
use of org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer 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());
}
use of org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer 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.DebugLoggerConsumer 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.DebugLoggerConsumer 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);
}
Aggregations