use of org.apache.maven.scm.provider.bazaar.command.BazaarConsumer in project maven-scm by apache.
the class BazaarCheckInCommand method executeCheckInCommand.
/**
* {@inheritDoc}
*/
protected CheckInScmResult executeCheckInCommand(ScmProviderRepository repo, ScmFileSet fileSet, String message, ScmVersion version) throws ScmException {
if (version != null && StringUtils.isNotEmpty(version.getName())) {
throw new ScmException("This provider can't handle tags.");
}
// Get files that will be committed (if not specified in fileSet)
List<ScmFile> commitedFiles = new ArrayList<ScmFile>();
List<File> files = fileSet.getFileList();
if (files.isEmpty()) {
// Either commit all changes
BazaarStatusCommand statusCmd = new BazaarStatusCommand();
statusCmd.setLogger(getLogger());
StatusScmResult status = statusCmd.executeStatusCommand(repo, fileSet);
List<ScmFile> statusFiles = status.getChangedFiles();
for (ScmFile file : statusFiles) {
if (file.getStatus() == ScmFileStatus.ADDED || file.getStatus() == ScmFileStatus.DELETED || file.getStatus() == ScmFileStatus.MODIFIED) {
commitedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.CHECKED_IN));
}
}
} else {
// Or commit spesific files
for (File file : files) {
commitedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.CHECKED_IN));
}
}
// Commit to local branch
String[] commitCmd = new String[] { BazaarConstants.COMMIT_CMD, BazaarConstants.MESSAGE_OPTION, message };
commitCmd = BazaarUtils.expandCommandLine(commitCmd, fileSet);
ScmResult result = BazaarUtils.execute(new BazaarConsumer(getLogger()), getLogger(), fileSet.getBasedir(), commitCmd);
// Push to parent branch if any
BazaarScmProviderRepository repository = (BazaarScmProviderRepository) repo;
if (!repository.getURI().equals(fileSet.getBasedir().getAbsolutePath()) && repo.isPushChanges()) {
String[] pushCmd = new String[] { BazaarConstants.PUSH_CMD, BazaarConstants.NO_STRICT_OPTION, repository.getURI() };
result = BazaarUtils.execute(new BazaarConsumer(getLogger()), getLogger(), fileSet.getBasedir(), pushCmd);
}
return new CheckInScmResult(commitedFiles, result);
}
use of org.apache.maven.scm.provider.bazaar.command.BazaarConsumer in project maven-scm by apache.
the class BazaarTagCommand method executeTagCommand.
protected ScmResult executeTagCommand(ScmProviderRepository repository, ScmFileSet fileSet, String tagName, ScmTagParameters scmTagParameters) throws ScmException {
if (tagName == null || StringUtils.isEmpty(tagName.trim())) {
throw new ScmException("tag name must be specified");
}
if (!fileSet.getFileList().isEmpty()) {
throw new ScmException("tagging specific files is not allowed");
}
// Perform the tagging operation
File bazaarRoot = fileSet.getBasedir();
BazaarConsumer consumer = new BazaarConsumer(getLogger());
String[] tagCmd = new String[] { BazaarConstants.TAG_CMD, tagName };
ScmResult tagResult = BazaarUtils.execute(consumer, getLogger(), bazaarRoot, tagCmd);
if (!tagResult.isSuccess()) {
return new TagScmResult(null, tagResult);
}
// Do "bzr ls -R -r tag:tagName" to get a list of the tagged files
BazaarLsConsumer lsConsumer = new BazaarLsConsumer(getLogger(), bazaarRoot, ScmFileStatus.TAGGED);
String[] lsCmd = new String[] { BazaarConstants.LS_CMD, BazaarConstants.RECURSIVE_OPTION, BazaarConstants.REVISION_OPTION, "tag:" + tagName };
ScmResult lsResult = BazaarUtils.execute(lsConsumer, getLogger(), bazaarRoot, lsCmd);
if (!lsResult.isSuccess()) {
return new TagScmResult(null, lsResult);
}
// Push new tags to parent branch if any
BazaarScmProviderRepository bazaarRepository = (BazaarScmProviderRepository) repository;
if (!bazaarRepository.getURI().equals(fileSet.getBasedir().getAbsolutePath()) && repository.isPushChanges()) {
String[] pushCmd = new String[] { BazaarConstants.PUSH_CMD, bazaarRepository.getURI() };
ScmResult pushResult = BazaarUtils.execute(new BazaarConsumer(getLogger()), getLogger(), fileSet.getBasedir(), pushCmd);
if (!pushResult.isSuccess()) {
return new TagScmResult(null, pushResult);
}
}
return new TagScmResult(lsConsumer.getListedFiles(), tagResult);
}
use of org.apache.maven.scm.provider.bazaar.command.BazaarConsumer in project maven-scm by apache.
the class BazaarCheckOutCommand method executeCheckOutCommand.
/**
* {@inheritDoc}
*/
protected CheckOutScmResult executeCheckOutCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version, boolean recursive, boolean shallow) throws ScmException {
BazaarScmProviderRepository repository = (BazaarScmProviderRepository) repo;
String url = repository.getURI();
File checkoutDir = fileSet.getBasedir();
try {
if (getLogger().isInfoEnabled()) {
getLogger().info("Removing " + checkoutDir);
}
FileUtils.deleteDirectory(checkoutDir);
} catch (IOException e) {
throw new ScmException("Cannot remove " + checkoutDir);
}
// Do the actual checkout
List<String> checkoutCmd = new ArrayList<String>();
checkoutCmd.add(BazaarConstants.BRANCH_CMD);
checkoutCmd.add(url);
checkoutCmd.add(checkoutDir.getAbsolutePath());
if (version != null && StringUtils.isNotEmpty(version.getName())) {
checkoutCmd.add(BazaarConstants.REVISION_OPTION);
checkoutCmd.add("tag:" + version.getName());
}
BazaarConsumer checkoutConsumer = new BazaarConsumer(getLogger());
BazaarUtils.execute(checkoutConsumer, getLogger(), checkoutDir.getParentFile(), (String[]) checkoutCmd.toArray(new String[0]));
// Do inventory to find list of checkedout files
String[] inventoryCmd = new String[] { BazaarConstants.INVENTORY_CMD };
BazaarCheckOutConsumer consumer = new BazaarCheckOutConsumer(getLogger(), checkoutDir);
ScmResult result = BazaarUtils.execute(consumer, getLogger(), checkoutDir, inventoryCmd);
if (!result.isSuccess()) {
throw new ScmException(result.getProviderMessage());
}
return new CheckOutScmResult(consumer.getCheckedOutFiles(), result);
}
use of org.apache.maven.scm.provider.bazaar.command.BazaarConsumer 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);
}
Aggregations