Search in sources :

Example 11 with TagScmResult

use of org.apache.maven.scm.command.tag.TagScmResult in project maven-scm by apache.

the class JazzScmProvider method tag.

/**
 * {@inheritDoc}
 */
protected TagScmResult tag(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    getLogger().debug("JazzScmProvider:tag()");
    // We need to call the status command first, so that we can get the details of the stream etc.
    // This is needed for workspace deliveries and snapshot promotions.
    JazzStatusCommand statusCommand = new JazzStatusCommand();
    statusCommand.setLogger(getLogger());
    statusCommand.execute(repository, fileSet, parameters);
    JazzTagCommand command = new JazzTagCommand();
    command.setLogger(getLogger());
    return (TagScmResult) command.execute(repository, fileSet, parameters);
}
Also used : JazzStatusCommand(org.apache.maven.scm.provider.jazz.command.status.JazzStatusCommand) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) JazzTagCommand(org.apache.maven.scm.provider.jazz.command.tag.JazzTagCommand)

Example 12 with TagScmResult

use of org.apache.maven.scm.command.tag.TagScmResult in project maven-scm by apache.

the class JazzTagCommand method executeTagCommand.

/**
 * {@inheritDoc}
 */
protected ScmResult executeTagCommand(ScmProviderRepository repo, ScmFileSet fileSet, String tag, ScmTagParameters scmTagParameters) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("Executing tag command...");
    }
    JazzScmProviderRepository jazzRepo = (JazzScmProviderRepository) repo;
    getLogger().debug("Creating Snapshot...");
    StreamConsumer tagConsumer = // No need for a dedicated consumer for this
    new DebugLoggerConsumer(getLogger());
    ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
    JazzScmCommand tagCreateSnapshotCmd = createTagCreateSnapshotCommand(jazzRepo, fileSet, tag, scmTagParameters);
    int status = tagCreateSnapshotCmd.execute(tagConsumer, errConsumer);
    if (status != 0) {
        return new TagScmResult(tagCreateSnapshotCmd.getCommandString(), "Error code for Jazz SCM tag (SNAPSHOT) command - " + status, errConsumer.getOutput(), false);
    }
    // ------------------------------------------------------------------
    // We create the workspace based on the tag here, as the scm tool
    // can not currently check directly out from a snapshot (only a workspace).
    getLogger().debug("Creating Workspace from Snapshot...");
    JazzScmCommand tagCreateWorkspaceCmd = createTagCreateWorkspaceCommand(jazzRepo, fileSet, tag);
    errConsumer = new ErrorConsumer(getLogger());
    status = tagCreateWorkspaceCmd.execute(tagConsumer, errConsumer);
    if (status != 0) {
        return new TagScmResult(tagCreateWorkspaceCmd.getCommandString(), "Error code for Jazz SCM tag (WORKSPACE) command - " + status, errConsumer.getOutput(), false);
    }
    if (jazzRepo.isPushChangesAndHaveFlowTargets()) {
        // isPushChanges = true, and we have something to deliver and promote to.
        getLogger().debug("Promoting and delivering...");
        // So we deliver the code to the target stream (or workspace)
        getLogger().debug("Delivering...");
        JazzScmCommand tagDeliverCommand = createTagDeliverCommand(jazzRepo, fileSet, tag);
        errConsumer = new ErrorConsumer(getLogger());
        status = tagDeliverCommand.execute(tagConsumer, errConsumer);
        if (status != 0) {
            return new TagScmResult(tagDeliverCommand.getCommandString(), "Error code for Jazz SCM deliver command - " + status, errConsumer.getOutput(), false);
        }
        // And now we promote the snapshot to the target stream (or workspace)
        getLogger().debug("Promoting snapshot...");
        JazzScmCommand tagSnapshotPromoteCommand = createTagSnapshotPromoteCommand(jazzRepo, fileSet, tag);
        errConsumer = new ErrorConsumer(getLogger());
        status = tagSnapshotPromoteCommand.execute(tagConsumer, errConsumer);
        if (status != 0) {
            return new TagScmResult(tagSnapshotPromoteCommand.getCommandString(), "Error code for Jazz SCM snapshot promote command - " + status, errConsumer.getOutput(), false);
        }
    }
    // We don't have a JazzTagConsumer so just build up all the files...
    List<ScmFile> taggedFiles = new ArrayList<ScmFile>(fileSet.getFileList().size());
    for (File f : fileSet.getFileList()) {
        taggedFiles.add(new ScmFile(f.getPath(), ScmFileStatus.TAGGED));
    }
    // So we return tagSnapshotCmd and not tagWorkspaceCmd.
    return new TagScmResult(tagCreateSnapshotCmd.getCommandString(), taggedFiles);
}
Also used : StreamConsumer(org.codehaus.plexus.util.cli.StreamConsumer) ErrorConsumer(org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer) ArrayList(java.util.ArrayList) JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) DebugLoggerConsumer(org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) JazzScmProviderRepository(org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository) ScmFile(org.apache.maven.scm.ScmFile)

Example 13 with TagScmResult

use of org.apache.maven.scm.command.tag.TagScmResult in project maven-scm by apache.

the class IntegrityScmProvider method tag.

/**
 * Maps to si checkpoint
 */
@Override
protected TagScmResult tag(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params) throws ScmException {
    IntegrityTagCommand command = new IntegrityTagCommand();
    command.setLogger(getLogger());
    return (TagScmResult) command.execute(repository, fileSet, params);
}
Also used : IntegrityTagCommand(org.apache.maven.scm.provider.integrity.command.tag.IntegrityTagCommand) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult)

Example 14 with TagScmResult

use of org.apache.maven.scm.command.tag.TagScmResult in project maven-scm by apache.

the class TagCommandTckTest method testTagCommandTest.

public void testTagCommandTest() throws Exception {
    String tag = getTagName();
    @SuppressWarnings("deprecation") TagScmResult tagResult = getScmManager().getProviderByUrl(getScmUrl()).tag(getScmRepository(), new ScmFileSet(getWorkingCopy()), tag);
    assertResultIsSuccess(tagResult);
    // see https://issues.apache.org/jira/browse/SCM-754
    // assertEquals( "check all 4 files tagged", 4, tagResult.getTaggedFiles().size() );
    File readmeTxt = new File(getWorkingCopy(), "readme.txt");
    assertEquals("check readme.txt contents", "/readme.txt", FileUtils.fileRead(readmeTxt));
    this.edit(getWorkingCopy(), "readme.txt", null, getScmRepository());
    changeReadmeTxt(readmeTxt);
    CheckInScmResult checkinResult = getScmManager().checkIn(getScmRepository(), new ScmFileSet(getWorkingCopy()), "commit message");
    assertResultIsSuccess(checkinResult);
    CheckOutScmResult checkoutResult = getScmManager().checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy()));
    assertResultIsSuccess(checkoutResult);
    readmeTxt = new File(getAssertionCopy(), "readme.txt");
    assertEquals("check readme.txt contents", "changed file", FileUtils.fileRead(readmeTxt));
    deleteDirectory(getAssertionCopy());
    assertFalse("check previous assertion copy deleted", getAssertionCopy().exists());
    checkoutResult = getScmManager().getProviderByUrl(getScmUrl()).checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy()), new ScmTag(tag));
    assertResultIsSuccess(checkoutResult);
    assertEquals("check readme.txt contents is from tagged version", "/readme.txt", FileUtils.fileRead(readmeTxt));
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmTag(org.apache.maven.scm.ScmTag) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) File(java.io.File) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult)

Example 15 with TagScmResult

use of org.apache.maven.scm.command.tag.TagScmResult in project maven-scm by apache.

the class GitTagCommand 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");
    }
    GitScmProviderRepository repository = (GitScmProviderRepository) repo;
    File messageFile = FileUtils.createTempFile("maven-scm-", ".commit", null);
    try {
        FileUtils.fileWrite(messageFile.getAbsolutePath(), scmTagParameters.getMessage());
    } catch (IOException ex) {
        return new TagScmResult(null, "Error while making a temporary file for the commit message: " + ex.getMessage(), null, false);
    }
    try {
        CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
        CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
        int exitCode;
        Commandline clTag = createCommandLine(repository, fileSet.getBasedir(), tag, messageFile);
        exitCode = GitCommandLineUtils.execute(clTag, stdout, stderr, getLogger());
        if (exitCode != 0) {
            return new TagScmResult(clTag.toString(), "The git-tag command failed.", stderr.getOutput(), false);
        }
        if (repo.isPushChanges()) {
            // and now push the tag to the configured upstream repository
            Commandline clPush = createPushCommandLine(repository, fileSet, tag);
            exitCode = GitCommandLineUtils.execute(clPush, stdout, stderr, getLogger());
            if (exitCode != 0) {
                return new TagScmResult(clPush.toString(), "The git-push command failed.", stderr.getOutput(), false);
            }
        }
        // plus search for the tagged files
        GitListConsumer listConsumer = new GitListConsumer(getLogger(), fileSet.getBasedir(), ScmFileStatus.TAGGED);
        Commandline clList = GitListCommand.createCommandLine(repository, fileSet.getBasedir());
        exitCode = GitCommandLineUtils.execute(clList, listConsumer, stderr, getLogger());
        if (exitCode != 0) {
            return new CheckOutScmResult(clList.toString(), "The git-ls-files command failed.", stderr.getOutput(), false);
        }
        return new TagScmResult(clTag.toString(), listConsumer.getListedFiles());
    } finally {
        try {
            FileUtils.forceDelete(messageFile);
        } catch (IOException ex) {
        // ignore
        }
    }
}
Also used : ScmException(org.apache.maven.scm.ScmException) GitScmProviderRepository(org.apache.maven.scm.provider.git.repository.GitScmProviderRepository) Commandline(org.codehaus.plexus.util.cli.Commandline) GitCommandLineUtils(org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) GitListConsumer(org.apache.maven.scm.provider.git.gitexe.command.list.GitListConsumer) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) IOException(java.io.IOException) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) File(java.io.File)

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