Search in sources :

Example 26 with TagScmResult

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);
}
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 27 with TagScmResult

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);
    }
}
Also used : ScmException(org.apache.maven.scm.ScmException) ArrayList(java.util.ArrayList) RevWalk(org.eclipse.jgit.revwalk.RevWalk) ScmException(org.apache.maven.scm.ScmException) ScmFile(org.apache.maven.scm.ScmFile) Ref(org.eclipse.jgit.lib.Ref) Git(org.eclipse.jgit.api.Git) RefSpec(org.eclipse.jgit.transport.RefSpec) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 28 with TagScmResult

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);
}
Also used : SynergyScmProviderRepository(org.apache.maven.scm.provider.synergy.repository.SynergyScmProviderRepository) ArrayList(java.util.ArrayList) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 29 with TagScmResult

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);
}
Also used : TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) SynergyTagCommand(org.apache.maven.scm.provider.synergy.command.tag.SynergyTagCommand)

Example 30 with TagScmResult

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());
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) StarteamScmProviderRepository(org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository) StarteamCommandLineUtils(org.apache.maven.scm.provider.starteam.command.StarteamCommandLineUtils) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult)

Aggregations

TagScmResult (org.apache.maven.scm.command.tag.TagScmResult)32 File (java.io.File)12 ScmException (org.apache.maven.scm.ScmException)11 ArrayList (java.util.ArrayList)6 ScmFile (org.apache.maven.scm.ScmFile)6 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)6 Commandline (org.codehaus.plexus.util.cli.Commandline)5 ScmFileSet (org.apache.maven.scm.ScmFileSet)4 IOException (java.io.IOException)3 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)3 AccuRevInfo (org.apache.maven.scm.provider.accurev.AccuRevInfo)3 CommandParameters (org.apache.maven.scm.CommandParameters)2 ScmFileMatcher.assertHasScmFile (org.apache.maven.scm.ScmFileMatcher.assertHasScmFile)2 ScmResult (org.apache.maven.scm.ScmResult)2 ScmTag (org.apache.maven.scm.ScmTag)2 ScmTagParameters (org.apache.maven.scm.ScmTagParameters)2 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)2 AccuRevScmProviderRepository (org.apache.maven.scm.provider.accurev.AccuRevScmProviderRepository)2 AbstractAccuRevCommandTest (org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)2 CvsTagConsumer (org.apache.maven.scm.provider.cvslib.command.tag.CvsTagConsumer)2