use of org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer in project maven-scm by apache.
the class JazzAddCommand method executeAddCommand.
public AddScmResult executeAddCommand(ScmProviderRepository repo, ScmFileSet fileSet) throws ScmException {
// NOTE: THIS IS ALSO CALLED DIRECTLY FROM THE CHECKIN COMMAND.
//
// The "checkin" command does not produce consumable output as to which individual files were checked in. (in
// 2.0.0.2 at least). Since only "locally modified" changes get checked in, we call a "status" command to
// generate a list of these files.
File baseDir = fileSet.getBasedir();
File parentFolder = (baseDir.getParentFile() != null) ? baseDir.getParentFile() : baseDir;
List<ScmFile> changedScmFiles = new ArrayList<ScmFile>();
List<File> changedFiles = new ArrayList<File>();
List<ScmFile> commitedFiles = new ArrayList<ScmFile>();
JazzStatusCommand statusCmd = new JazzStatusCommand();
statusCmd.setLogger(getLogger());
StatusScmResult statusCmdResult = statusCmd.executeStatusCommand(repo, fileSet);
List<ScmFile> statusScmFiles = statusCmdResult.getChangedFiles();
for (ScmFile file : statusScmFiles) {
getLogger().debug("Iterating over statusScmFiles: " + file);
if (file.getStatus() == ScmFileStatus.ADDED || file.getStatus() == ScmFileStatus.DELETED || file.getStatus() == ScmFileStatus.MODIFIED) {
changedScmFiles.add(new ScmFile(file.getPath(), ScmFileStatus.CHECKED_IN));
changedFiles.add(new File(parentFolder, file.getPath()));
}
}
List<File> files = fileSet.getFileList();
if (files.size() == 0) {
// Either commit all local changes
commitedFiles = changedScmFiles;
} else {
// Or commit specific files
for (File file : files) {
if (fileExistsInFileList(file, changedFiles)) {
commitedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.CHECKED_IN));
}
}
}
// Now that we have a list of files to process, we can "add" (scm checkin) them.
JazzAddConsumer addConsumer = new JazzAddConsumer(repo, getLogger());
ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
JazzScmCommand command = createAddCommand(repo, fileSet);
int status = command.execute(addConsumer, errConsumer);
if (status != 0) {
return new AddScmResult(command.getCommandString(), "Error code for Jazz SCM add (checkin) command - " + status, errConsumer.getOutput(), false);
}
return new AddScmResult(command.getCommandString(), addConsumer.getFiles());
}
use of org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer in project maven-scm by apache.
the class JazzChangeLogCommand method executeChangeLogCommand.
/**
* {@inheritDoc}
*/
protected ChangeLogScmResult executeChangeLogCommand(ScmProviderRepository repo, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern) throws ScmException {
if (branch != null && StringUtils.isNotEmpty(branch.getName())) {
throw new ScmException("This SCM provider doesn't support branches.");
}
if (getLogger().isDebugEnabled()) {
getLogger().debug("Executing changelog command...");
}
// This acts as a two phase operation.
// The first pass is to call the "scm history" command to get a list
// of the changeSets from Jazz SCM. It is stored in the revision of the
// changeSets array.
List<ChangeSet> changeSets = new ArrayList<ChangeSet>();
JazzScmCommand historyCommand = createHistoryCommand(repo, fileSet);
JazzHistoryConsumer changeLogConsumer = new JazzHistoryConsumer(repo, getLogger(), changeSets);
ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
int status = historyCommand.execute(changeLogConsumer, errConsumer);
if (status != 0) {
return new ChangeLogScmResult(historyCommand.getCommandString(), "Error code for Jazz SCM history command - " + status, errConsumer.getOutput(), false);
}
// Now, call the "scm list changesets" command, passing in the list of changesets from the first pass.
JazzScmCommand listChangesetsCommand = createListChangesetCommand(repo, fileSet, changeSets);
JazzListChangesetConsumer listChangesetConsumer = new JazzListChangesetConsumer(repo, getLogger(), changeSets, datePattern);
errConsumer = new ErrorConsumer(getLogger());
status = listChangesetsCommand.execute(listChangesetConsumer, errConsumer);
if (status != 0) {
return new ChangeLogScmResult(listChangesetsCommand.getCommandString(), "Error code for Jazz SCM list changesets command - " + status, errConsumer.getOutput(), false);
}
// Build the result and return it.
ChangeLogSet changeLogSet = new ChangeLogSet(changeSets, startDate, endDate);
// Return the "main" command used, namely "scm history"
return new ChangeLogScmResult(historyCommand.getCommandString(), changeLogSet);
}
use of org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer 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.ErrorConsumer in project maven-scm by apache.
the class JazzUpdateCommand method executeUpdateCommand.
/**
* {@inheritDoc}
*/
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) throws ScmException {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Executing update command...");
}
JazzUpdateConsumer updateConsumer = new JazzUpdateConsumer(repo, getLogger());
ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
JazzScmCommand updateCmd = createAcceptCommand(repo, fileSet);
int status = updateCmd.execute(updateConsumer, errConsumer);
if (status != 0) {
return new UpdateScmResult(updateCmd.getCommandString(), "Error code for Jazz SCM update command - " + status, errConsumer.getOutput(), false);
}
if (getLogger().isDebugEnabled()) {
if (!updateConsumer.getUpdatedFiles().isEmpty()) {
getLogger().debug("Iterating over \"Update\" results");
for (ScmFile file : updateConsumer.getUpdatedFiles()) {
getLogger().debug(file.getPath() + " : " + file.getStatus());
}
} else {
getLogger().debug("There are no updated files");
}
}
// We can use the checkout directory for this.
return new UpdateScmResult(updateCmd.getCommandString(), updateConsumer.getUpdatedFiles());
}
use of org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer 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());
}
Aggregations