use of org.apache.maven.scm.command.update.UpdateScmResultWithRevision in project maven-scm by apache.
the class PerforceUpdateCommand method executeUpdateCommand.
/**
* {@inheritDoc}
*/
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet files, ScmVersion scmVersion) throws ScmException {
// In Perforce, there is no difference between update and checkout.
// Here we just run the checkout command and map the result onto an
// UpdateScmResult.
PerforceCheckOutCommand command = new PerforceCheckOutCommand();
command.setLogger(getLogger());
CommandParameters params = new CommandParameters();
params.setScmVersion(CommandParameter.SCM_VERSION, scmVersion);
CheckOutScmResult cosr = (CheckOutScmResult) command.execute(repo, files, params);
if (!cosr.isSuccess()) {
return new UpdateScmResult(cosr.getCommandLine(), cosr.getProviderMessage(), cosr.getCommandOutput(), false);
}
PerforceScmProviderRepository p4repo = (PerforceScmProviderRepository) repo;
String clientspec = PerforceScmProvider.getClientspecName(getLogger(), p4repo, files.getBasedir());
Commandline cl = createCommandLine(p4repo, files.getBasedir(), clientspec);
@SuppressWarnings("unused") String location = PerforceScmProvider.getRepoPath(getLogger(), p4repo, files.getBasedir());
PerforceHaveConsumer consumer = new PerforceHaveConsumer(getLogger());
try {
if (getLogger().isDebugEnabled()) {
getLogger().debug(PerforceScmProvider.clean("Executing " + cl.toString()));
}
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
int exitCode = CommandLineUtils.executeCommandLine(cl, consumer, err);
if (exitCode != 0) {
String cmdLine = CommandLineUtils.toString(cl.getCommandline());
StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + err.getOutput());
msg.append('\n');
msg.append("Command line was:" + cmdLine);
throw new CommandLineException(msg.toString());
}
} catch (CommandLineException e) {
if (getLogger().isErrorEnabled()) {
getLogger().error("CommandLineException " + e.getMessage(), e);
}
}
return new UpdateScmResultWithRevision(cosr.getCommandLine(), cosr.getCheckedOutFiles(), String.valueOf(consumer.getHave()));
}
use of org.apache.maven.scm.command.update.UpdateScmResultWithRevision in project maven-scm by apache.
the class HgUpdateCommand method executeUpdateCommand.
/**
* {@inheritDoc}
*/
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion tag) throws ScmException {
File workingDir = fileSet.getBasedir();
String[] updateCmd;
// Update branch
if (repo.isPushChanges()) {
updateCmd = new String[] { HgCommandConstants.PULL_CMD, HgCommandConstants.REVISION_OPTION, tag != null && !StringUtils.isEmpty(tag.getName()) ? tag.getName() : "tip" };
} else {
updateCmd = new String[] { HgCommandConstants.UPDATE_CMD, tag != null && !StringUtils.isEmpty(tag.getName()) ? tag.getName() : "tip", HgCommandConstants.CLEAN_OPTION };
}
ScmResult updateResult = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), workingDir, updateCmd);
if (!updateResult.isSuccess()) {
return new UpdateScmResult(null, null, updateResult);
}
// Find changes from last revision
int currentRevision = HgUtils.getCurrentRevisionNumber(getLogger(), workingDir);
int previousRevision = currentRevision - 1;
String[] diffCmd = new String[] { HgCommandConstants.DIFF_CMD, HgCommandConstants.REVISION_OPTION, "" + previousRevision };
HgDiffConsumer diffConsumer = new HgDiffConsumer(getLogger(), workingDir);
ScmResult diffResult = HgUtils.execute(diffConsumer, getLogger(), workingDir, diffCmd);
// Now translate between diff and update file status
List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
List<CharSequence> changes = new ArrayList<CharSequence>();
List<ScmFile> diffFiles = diffConsumer.getChangedFiles();
Map<String, CharSequence> diffChanges = diffConsumer.getDifferences();
for (ScmFile file : diffFiles) {
changes.add(diffChanges.get(file.getPath()));
if (file.getStatus() == ScmFileStatus.MODIFIED) {
updatedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.PATCHED));
} else {
updatedFiles.add(file);
}
}
if (repo.isPushChanges()) {
String[] hgUpdateCmd = new String[] { HgCommandConstants.UPDATE_CMD };
HgUtils.execute(new HgConsumer(getLogger()), getLogger(), workingDir, hgUpdateCmd);
}
return new UpdateScmResultWithRevision(updatedFiles, new ArrayList<ChangeSet>(0), String.valueOf(currentRevision), diffResult);
}
use of org.apache.maven.scm.command.update.UpdateScmResultWithRevision in project maven-scm by apache.
the class UpdateSubprojectsMojo method execute.
/**
* {@inheritDoc}
*/
public void execute() throws MojoExecutionException {
super.execute();
try {
ScmRepository repository = getScmRepository();
UpdateScmResult result = getScmManager().update(repository, getFileSet(), getScmVersion(scmVersionType, scmVersion));
checkResult(result);
if (result instanceof UpdateScmResultWithRevision) {
getLog().info("Storing revision in '" + revisionKey + "' project property.");
if (// Remove the test when we'll use plugin-test-harness 1.0-alpha-2
project.getProperties() != null) {
project.getProperties().put(revisionKey, ((UpdateScmResultWithRevision) result).getRevision());
}
}
} catch (IOException e) {
throw new MojoExecutionException("Cannot run update command : ", e);
} catch (ScmException e) {
throw new MojoExecutionException("Cannot run update command : ", e);
}
}
use of org.apache.maven.scm.command.update.UpdateScmResultWithRevision in project maven-scm by apache.
the class BazaarUpdateCommand method executeUpdateCommand.
/**
* {@inheritDoc}
*/
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) throws ScmException {
if (version != null && StringUtils.isNotEmpty(version.getName())) {
throw new ScmException("This provider can't handle tags.");
}
File workingDir = fileSet.getBasedir();
// Update branch
String[] updateCmd = new String[] { BazaarConstants.PULL_CMD };
ScmResult updateResult = BazaarUtils.execute(new BazaarConsumer(getLogger()), getLogger(), workingDir, updateCmd);
if (!updateResult.isSuccess()) {
return new UpdateScmResult(null, null, updateResult);
}
// Find changes from last revision
int currentRevision = BazaarUtils.getCurrentRevisionNumber(getLogger(), workingDir);
int previousRevision = currentRevision - 1;
String[] diffCmd = new String[] { BazaarConstants.DIFF_CMD, BazaarConstants.REVISION_OPTION, "" + previousRevision };
BazaarDiffConsumer diffConsumer = new BazaarDiffConsumer(getLogger(), workingDir);
ScmResult diffResult = BazaarUtils.execute(diffConsumer, getLogger(), workingDir, diffCmd);
// Now translate between diff and update file status
List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
List<CharSequence> changes = new ArrayList<CharSequence>();
List<ScmFile> diffFiles = diffConsumer.getChangedFiles();
Map<String, CharSequence> diffChanges = diffConsumer.getDifferences();
for (Iterator<ScmFile> it = diffFiles.iterator(); it.hasNext(); ) {
ScmFile file = it.next();
changes.add(diffChanges.get(file));
if (file.getStatus() == ScmFileStatus.MODIFIED) {
updatedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.PATCHED));
} else {
updatedFiles.add(file);
}
}
return new UpdateScmResultWithRevision(updatedFiles, new ArrayList<ChangeSet>(0), String.valueOf(currentRevision), diffResult);
}
use of org.apache.maven.scm.command.update.UpdateScmResultWithRevision in project maven-scm by apache.
the class SvnUpdateCommand method executeUpdateCommand.
/**
* {@inheritDoc}
*/
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) throws ScmException {
Commandline cl = createCommandLine((SvnScmProviderRepository) repo, fileSet.getBasedir(), version);
SvnUpdateConsumer consumer = new SvnUpdateConsumer(getLogger(), fileSet.getBasedir());
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
if (getLogger().isInfoEnabled()) {
getLogger().info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
getLogger().info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
}
}
int exitCode;
try {
exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger());
} catch (CommandLineException ex) {
throw new ScmException("Error while executing command.", ex);
}
if (exitCode != 0) {
return new UpdateScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
}
UpdateScmResultWithRevision result = new UpdateScmResultWithRevision(cl.toString(), consumer.getUpdatedFiles(), String.valueOf(consumer.getRevision()));
result.setChanges(consumer.getChangeSets());
if (getLogger().isDebugEnabled()) {
getLogger().debug("changeSets " + consumer.getChangeSets());
}
return result;
}
Aggregations