Search in sources :

Example 6 with ScmTagParameters

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);
}
Also used : ScmTagParameters(org.apache.maven.scm.ScmTagParameters)

Example 7 with 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);
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) ScmTagParameters(org.apache.maven.scm.ScmTagParameters) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) ScmFile(org.apache.maven.scm.ScmFile) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) SvnCommandLineUtils(org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils) SvnScmProviderRepository(org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File)

Example 8 with ScmTagParameters

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);
    }
}
Also used : ScmProvider(org.apache.maven.scm.provider.ScmProvider) ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmException(org.apache.maven.scm.ScmException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ScmTagParameters(org.apache.maven.scm.ScmTagParameters) IOException(java.io.IOException) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 9 with ScmTagParameters

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);
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) ScmTagParameters(org.apache.maven.scm.ScmTagParameters)

Aggregations

ScmTagParameters (org.apache.maven.scm.ScmTagParameters)9 File (java.io.File)3 Commandline (org.codehaus.plexus.util.cli.Commandline)3 IOException (java.io.IOException)2 ScmException (org.apache.maven.scm.ScmException)2 TagScmResult (org.apache.maven.scm.command.tag.TagScmResult)2 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 CommandParameters (org.apache.maven.scm.CommandParameters)1 ScmFile (org.apache.maven.scm.ScmFile)1 ScmProvider (org.apache.maven.scm.provider.ScmProvider)1 SvnScmProviderRepository (org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository)1 SvnCommandLineUtils (org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils)1 TfsScmProviderRepository (org.apache.maven.scm.provider.tfs.TfsScmProviderRepository)1 ScmRepository (org.apache.maven.scm.repository.ScmRepository)1 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)1 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)1