use of org.apache.maven.scm.command.tag.TagScmResult in project maven-scm by apache.
the class SvnTagCommand method executeTagCommand.
/**
* {@inheritDoc}
*/
public ScmResult executeTagCommand(ScmProviderRepository repo, ScmFileSet fileSet, String tag, ScmTagParameters scmTagParameters) throws ScmException {
// NPE free
if (scmTagParameters == null) {
getLogger().debug("SvnTagCommand :: scmTagParameters is null create an empty one");
scmTagParameters = new ScmTagParameters();
scmTagParameters.setRemoteTagging(false);
} else {
getLogger().debug("SvnTagCommand :: scmTagParameters.remoteTagging : " + scmTagParameters.isRemoteTagging());
}
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");
}
SvnScmProviderRepository repository = (SvnScmProviderRepository) repo;
File messageFile = FileUtils.createTempFile("maven-scm-", ".commit", null);
try {
FileUtils.fileWrite(messageFile.getAbsolutePath(), scmTagParameters == null ? "" : scmTagParameters.getMessage());
} catch (IOException ex) {
return new TagScmResult(null, "Error while making a temporary file for the commit message: " + ex.getMessage(), null, false);
}
Commandline cl = createCommandLine(repository, fileSet.getBasedir(), tag, messageFile, scmTagParameters);
CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
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, stdout, stderr, getLogger());
} catch (CommandLineException ex) {
throw new ScmException("Error while executing command.", ex);
} finally {
try {
FileUtils.forceDelete(messageFile);
} catch (IOException ex) {
// ignore
}
}
if (exitCode != 0) {
// TODO: Improve this error message
return new TagScmResult(cl.toString(), "The svn tag command failed.", stderr.getOutput(), false);
}
List<ScmFile> fileList = new ArrayList<ScmFile>();
List<File> files = null;
try {
if (StringUtils.isNotEmpty(fileSet.getExcludes())) {
@SuppressWarnings("unchecked") List<File> list = FileUtils.getFiles(fileSet.getBasedir(), (StringUtils.isEmpty(fileSet.getIncludes()) ? "**" : fileSet.getIncludes()), fileSet.getExcludes() + ",**/.svn/**", false);
files = list;
} else {
@SuppressWarnings("unchecked") List<File> list = FileUtils.getFiles(fileSet.getBasedir(), (StringUtils.isEmpty(fileSet.getIncludes()) ? "**" : fileSet.getIncludes()), "**/.svn/**", false);
files = list;
}
} catch (IOException e) {
throw new ScmException("Error while executing command.", e);
}
for (Iterator<File> i = files.iterator(); i.hasNext(); ) {
File f = i.next();
fileList.add(new ScmFile(f.getPath(), ScmFileStatus.TAGGED));
}
return new TagScmResult(cl.toString(), fileList);
}
use of org.apache.maven.scm.command.tag.TagScmResult in project maven-scm by apache.
the class JGitTagCommand method executeTagCommand.
/**
* {@inheritDoc}
*/
public ScmResult executeTagCommand(ScmProviderRepository repo, ScmFileSet fileSet, String tag, ScmTagParameters scmTagParameters) throws ScmException {
if (tag == null || StringUtils.isEmpty(tag.trim())) {
throw new ScmException("tag name must be specified");
}
if (!fileSet.getFileList().isEmpty()) {
throw new ScmException("This provider doesn't support tagging subsets of a directory");
}
String escapedTagName = tag.trim().replace(' ', '_');
Git git = null;
try {
git = JGitUtils.openRepo(fileSet.getBasedir());
// tag the revision
String tagMessage = scmTagParameters.getMessage();
Ref tagRef = git.tag().setName(escapedTagName).setMessage(tagMessage).setForceUpdate(false).call();
if (repo.isPushChanges()) {
getLogger().info("push tag [" + escapedTagName + "] to remote...");
JGitUtils.push(getLogger(), git, (GitScmProviderRepository) repo, new RefSpec(Constants.R_TAGS + escapedTagName));
}
// search for the tagged files
RevWalk revWalk = new RevWalk(git.getRepository());
RevCommit commit = revWalk.parseCommit(tagRef.getObjectId());
revWalk.release();
final TreeWalk walk = new TreeWalk(git.getRepository());
// drop the first empty tree, which we do not need here
walk.reset();
walk.setRecursive(true);
walk.addTree(commit.getTree());
List<ScmFile> taggedFiles = new ArrayList<ScmFile>();
while (walk.next()) {
taggedFiles.add(new ScmFile(walk.getPathString(), ScmFileStatus.CHECKED_OUT));
}
walk.release();
return new TagScmResult("JGit tag", taggedFiles);
} catch (Exception e) {
throw new ScmException("JGit tag failure!", e);
} finally {
JGitUtils.closeRepo(git);
}
}
use of org.apache.maven.scm.command.tag.TagScmResult in project maven-scm by apache.
the class SynergyTagCommand method executeTagCommand.
/**
* {@inheritDoc}
*/
protected ScmResult executeTagCommand(ScmProviderRepository repository, ScmFileSet fileSet, String tag, ScmTagParameters scmTagParameters) throws ScmException {
if (getLogger().isDebugEnabled()) {
getLogger().debug("executing tag command...");
}
SynergyScmProviderRepository repo = (SynergyScmProviderRepository) repository;
if (getLogger().isDebugEnabled()) {
getLogger().debug("basedir: " + fileSet.getBasedir());
}
String ccmAddr = SynergyUtil.start(getLogger(), repo.getUser(), repo.getPassword(), SynergyRole.BUILD_MGR);
try {
// Make sure, that all changes made until now are reflected in the prep project
// this is especially true for all changes made by maven (ie versions in the poms).
SynergyUtil.reconfigureProperties(getLogger(), repo.getProjectSpec(), ccmAddr);
SynergyUtil.reconfigure(getLogger(), repo.getProjectSpec(), ccmAddr);
SynergyUtil.createBaseline(getLogger(), repo.getProjectSpec(), tag, repo.getProjectRelease(), repo.getProjectPurpose(), ccmAddr);
} finally {
SynergyUtil.stop(getLogger(), ccmAddr);
}
List<ScmFile> files = new ArrayList<ScmFile>(fileSet.getFileList().size());
for (File f : fileSet.getFileList()) {
files.add(new ScmFile(f.getPath(), ScmFileStatus.TAGGED));
}
return new TagScmResult("", files);
}
use of org.apache.maven.scm.command.tag.TagScmResult in project maven-scm by apache.
the class SynergyScmProvider method tag.
/**
* {@inheritDoc}
*/
public TagScmResult tag(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
SynergyTagCommand command = new SynergyTagCommand();
command.setLogger(getLogger());
return (TagScmResult) command.execute(repository, fileSet, parameters);
}
use of org.apache.maven.scm.command.tag.TagScmResult in project maven-scm by apache.
the class StarteamTagCommand method executeTagCommand.
/**
* {@inheritDoc}
*/
protected ScmResult executeTagCommand(ScmProviderRepository repo, ScmFileSet fileSet, String tag, ScmTagParameters scmTagParameters) throws ScmException {
if (fileSet.getFileList().isEmpty()) {
throw new ScmException("This provider doesn't support tagging subsets of a directory");
}
if (tag == null || tag.trim().length() == 0) {
throw new ScmException("tag must be specified");
}
if (getLogger().isInfoEnabled()) {
getLogger().info("Working directory: " + fileSet.getBasedir().getAbsolutePath());
}
StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo;
StarteamTagConsumer consumer = new StarteamTagConsumer(getLogger());
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
Commandline cl = createCommandLine(repository, fileSet.getBasedir(), tag);
int exitCode = StarteamCommandLineUtils.executeCommandline(cl, consumer, stderr, getLogger());
if (exitCode != 0) {
return new TagScmResult(cl.toString(), "The starteam command failed.", stderr.getOutput(), false);
}
return new TagScmResult(cl.toString(), consumer.getTaggedFiles());
}
Aggregations