use of org.apache.maven.scm.ScmTagParameters in project maven-scm by apache.
the class SvnTagCommand method executeTagCommand.
public ScmResult executeTagCommand(ScmProviderRepository repo, ScmFileSet fileSet, String tag, String message) throws ScmException {
ScmTagParameters scmTagParameters = new ScmTagParameters(message);
// force false to preserve backward comp
scmTagParameters.setRemoteTagging(false);
return executeTagCommand(repo, fileSet, tag, scmTagParameters);
}
use of org.apache.maven.scm.ScmTagParameters 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.ScmTagParameters in project maven-scm by apache.
the class TagMojo method execute.
/**
* {@inheritDoc}
*/
public void execute() throws MojoExecutionException {
super.execute();
try {
SimpleDateFormat dateFormat = null;
String tagTimestamp = "";
String finalTag = tag;
if (addTimestamp) {
try {
getLog().info("Using timestamp pattern '" + timestampFormat + "'");
dateFormat = new SimpleDateFormat(timestampFormat);
tagTimestamp = dateFormat.format(new Date());
getLog().info("Using timestamp '" + tagTimestamp + "'");
} catch (IllegalArgumentException e) {
String msg = "The timestamp format '" + timestampFormat + "' is invalid.";
getLog().error(msg, e);
throw new MojoExecutionException(msg, e);
}
if ("end".equals(timestampPosition)) {
finalTag += timestampPrefix + tagTimestamp;
} else {
finalTag = tagTimestamp + timestampPrefix + finalTag;
}
}
ScmRepository repository = getScmRepository();
ScmProvider provider = getScmManager().getProviderByRepository(repository);
finalTag = provider.sanitizeTagName(finalTag);
getLog().info("Final Tag Name: '" + finalTag + "'");
ScmTagParameters scmTagParameters = new ScmTagParameters(message);
scmTagParameters.setRemoteTagging(remoteTagging);
TagScmResult result = provider.tag(repository, getFileSet(), finalTag, scmTagParameters);
checkResult(result);
} catch (IOException e) {
throw new MojoExecutionException("Cannot run tag command : ", e);
} catch (ScmException e) {
throw new MojoExecutionException("Cannot run tag command : ", e);
}
}
use of org.apache.maven.scm.ScmTagParameters in project maven-scm by apache.
the class JazzTagCommandTest method testCreateTagCreateSnapshotCommand.
public void testCreateTagCreateSnapshotCommand() throws Exception {
ScmTagParameters scmTagParameters = new ScmTagParameters("My Tag Message");
Commandline cmd = new JazzTagCommand().createTagCreateSnapshotCommand(repo, getScmFileSet(), "My_Tag_Name", scmTagParameters).getCommandline();
String expected = "scm create snapshot --repository-uri https://localhost:9443/jazz --username myUserName --password myPassword --name My_Tag_Name --description \"My Tag Message\" \"Dave's Repository Workspace\"";
assertCommandLine(expected, getWorkingDirectory(), cmd);
}
Aggregations