use of org.apache.maven.scm.provider.hg.command.inventory.HgListConsumer in project maven-scm by apache.
the class HgBranchCommand method executeBranchCommand.
/**
* {@inheritDoc}
*/
protected ScmResult executeBranchCommand(ScmProviderRepository scmProviderRepository, ScmFileSet fileSet, String branch, ScmBranchParameters scmBranchParameters) throws ScmException {
if (StringUtils.isBlank(branch)) {
throw new ScmException("branch must be specified");
}
if (!fileSet.getFileList().isEmpty()) {
throw new ScmException("This provider doesn't support branchging subsets of a directory");
}
File workingDir = fileSet.getBasedir();
// build the command
String[] branchCmd = new String[] { HgCommandConstants.BRANCH_CMD, branch };
// keep the command about in string form for reporting
HgConsumer branchConsumer = new HgConsumer(getLogger()) {
public void doConsume(ScmFileStatus status, String trimmedLine) {
// noop
}
};
ScmResult result = HgUtils.execute(branchConsumer, getLogger(), workingDir, branchCmd);
HgScmProviderRepository repository = (HgScmProviderRepository) scmProviderRepository;
if (!result.isSuccess()) {
throw new ScmException("Error while executing command " + joinCmd(branchCmd));
}
// First commit.
String[] commitCmd = new String[] { HgCommandConstants.COMMIT_CMD, HgCommandConstants.MESSAGE_OPTION, scmBranchParameters.getMessage() };
result = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), workingDir, commitCmd);
if (!result.isSuccess()) {
throw new ScmException("Error while executing command " + joinCmd(commitCmd));
}
if (repository.isPushChanges()) {
if (!repository.getURI().equals(fileSet.getBasedir().getAbsolutePath())) {
String[] pushCmd = new String[] { HgCommandConstants.PUSH_CMD, HgCommandConstants.NEW_BRANCH_OPTION, repository.getURI() };
result = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), fileSet.getBasedir(), pushCmd);
if (!result.isSuccess()) {
throw new ScmException("Error while executing command " + joinCmd(pushCmd));
}
}
}
// do an inventory to return the files branched (all of them)
String[] listCmd = new String[] { HgCommandConstants.INVENTORY_CMD };
HgListConsumer listconsumer = new HgListConsumer(getLogger());
result = HgUtils.execute(listconsumer, getLogger(), fileSet.getBasedir(), listCmd);
if (!result.isSuccess()) {
throw new ScmException("Error while executing command " + joinCmd(listCmd));
}
List<ScmFile> files = listconsumer.getFiles();
List<ScmFile> fileList = new ArrayList<ScmFile>();
for (ScmFile f : files) {
fileList.add(new ScmFile(f.getPath(), ScmFileStatus.TAGGED));
}
return new BranchScmResult(fileList, result);
}
use of org.apache.maven.scm.provider.hg.command.inventory.HgListConsumer in project maven-scm by apache.
the class HgTagCommand method executeTagCommand.
/**
* {@inheritDoc}
*/
protected ScmResult executeTagCommand(ScmProviderRepository scmProviderRepository, ScmFileSet fileSet, String tag, ScmTagParameters scmTagParameters) throws ScmException {
if (tag == null || StringUtils.isEmpty(tag.trim())) {
throw new ScmException("tag must be specified");
}
if (!fileSet.getFileList().isEmpty()) {
throw new ScmException("This provider doesn't support tagging subsets of a directory : " + fileSet.getFileList());
}
File workingDir = fileSet.getBasedir();
// build the command
String[] tagCmd = new String[] { HgCommandConstants.TAG_CMD, HgCommandConstants.MESSAGE_OPTION, scmTagParameters.getMessage(), tag };
// keep the command about in string form for reporting
StringBuilder cmd = joinCmd(tagCmd);
HgTagConsumer consumer = new HgTagConsumer(getLogger());
ScmResult result = HgUtils.execute(consumer, getLogger(), workingDir, tagCmd);
HgScmProviderRepository repository = (HgScmProviderRepository) scmProviderRepository;
if (result.isSuccess()) {
if (repository.isPushChanges()) {
if (!repository.getURI().equals(fileSet.getBasedir().getAbsolutePath())) {
String branchName = HgUtils.getCurrentBranchName(getLogger(), workingDir);
boolean differentOutgoingBranch = HgUtils.differentOutgoingBranchFound(getLogger(), workingDir, branchName);
String[] pushCmd = new String[] { HgCommandConstants.PUSH_CMD, differentOutgoingBranch ? HgCommandConstants.REVISION_OPTION + branchName : null, repository.getURI() };
result = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), fileSet.getBasedir(), pushCmd);
}
}
} else {
throw new ScmException("Error while executing command " + cmd.toString());
}
// do an inventory to return the files tagged (all of them)
String[] listCmd = new String[] { HgCommandConstants.INVENTORY_CMD };
HgListConsumer listconsumer = new HgListConsumer(getLogger());
result = HgUtils.execute(listconsumer, getLogger(), fileSet.getBasedir(), listCmd);
if (result.isSuccess()) {
List<ScmFile> files = listconsumer.getFiles();
List<ScmFile> fileList = new ArrayList<ScmFile>();
for (ScmFile f : files) {
if (!f.getPath().endsWith(".hgtags")) {
fileList.add(new ScmFile(f.getPath(), ScmFileStatus.TAGGED));
}
}
return new TagScmResult(fileList, result);
} else {
throw new ScmException("Error while executing command " + cmd.toString());
}
}
Aggregations