Search in sources :

Example 1 with RevertCommitsRequest

use of com.itemis.maven.plugins.unleash.scm.requests.RevertCommitsRequest in project unleash-maven-plugin by shillner.

the class SetNextDevVersion method rollback.

@RollbackOnError
public void rollback() throws MojoExecutionException {
    this.log.info("Rollback of all pom changes necessary for setting of the development version as well as reverting any made SCM commits.");
    StringBuilder message = new StringBuilder("Reversion of failed release build (step: setting of next snapshot version).");
    if (StringUtils.isNotBlank(this.scmMessagePrefix)) {
        message.insert(0, this.scmMessagePrefix);
    }
    if (this.metadata.getScmRevisionAfterNextDevVersion() != null) {
        // #49 (https://github.com/shillner/unleash-maven-plugin/issues/49)
        // commit reversion is only performed if the commit didn't fail (revision after dev version setting is not null)
        RevertCommitsRequest revertCommitsRequest = RevertCommitsRequest.builder().fromRevision(this.metadata.getScmRevisionAfterNextDevVersion()).toRevision(this.metadata.getScmRevisionBeforeNextDevVersion()).message(message.toString()).merge().mergeClient(new ScmPomVersionsMergeClient()).push().build();
        this.scmProvider.revertCommits(revertCommitsRequest);
    }
    for (MavenProject project : this.reactorProjects) {
        Document document = this.cachedPOMs.get(ProjectToCoordinates.EMPTY_VERSION.apply(project));
        if (document != null) {
            try {
                PomUtil.writePOM(document, this.project);
            } catch (Throwable t) {
                throw new MojoExecutionException("Could not revert the setting of development versions after a failed release build.", t);
            }
        }
    }
}
Also used : ScmPomVersionsMergeClient(com.itemis.maven.plugins.unleash.util.scm.ScmPomVersionsMergeClient) MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) RevertCommitsRequest(com.itemis.maven.plugins.unleash.scm.requests.RevertCommitsRequest) Document(org.w3c.dom.Document) RollbackOnError(com.itemis.maven.plugins.cdi.annotations.RollbackOnError)

Example 2 with RevertCommitsRequest

use of com.itemis.maven.plugins.unleash.scm.requests.RevertCommitsRequest in project unleash-maven-plugin by shillner.

the class TagScm method rollback.

@RollbackOnError
private void rollback() throws MojoExecutionException {
    this.log.info("Rollback of SCM tag creation and POM modifications due to a processing exception.");
    String scmTagName = this.metadata.getScmTagName();
    StringBuilder deleteTagMessageBuilder = new StringBuilder("Deletion of tag '").append(scmTagName).append("' due to release rollback.");
    if (StringUtils.isNotBlank(this.scmMessagePrefix)) {
        deleteTagMessageBuilder.insert(0, this.scmMessagePrefix);
    }
    DeleteTagRequest.Builder deleteTagRequestBuilder = DeleteTagRequest.builder().message(deleteTagMessageBuilder.toString()).tagName(scmTagName);
    if (this.scmProvider.hasTag(scmTagName)) {
        deleteTagRequestBuilder.push();
    }
    if (!this.tagWasPresent) {
        this.log.debug("\tDeleting scm tag '" + scmTagName + "' since the release build failed.");
        this.scmProvider.deleteTag(deleteTagRequestBuilder.build());
    } else {
        this.log.debug("\tSkipping deletion of SCM tag '" + scmTagName + "' since the tag was already present before the release build was triggered.");
    }
    if (this.commitBeforeTagging) {
        StringBuilder revertCommitsMessageBuilder = new StringBuilder("Reversion of failed release build (step: tag SCM).");
        if (StringUtils.isNotBlank(this.scmMessagePrefix)) {
            revertCommitsMessageBuilder.insert(0, this.scmMessagePrefix);
        }
        String fromRevision = MoreObjects.firstNonNull(this.metadata.getScmRevisionAfterTag(), this.scmProvider.getLocalRevision());
        RevertCommitsRequest revertCommitsRequest = RevertCommitsRequest.builder().fromRevision(fromRevision).toRevision(this.metadata.getScmRevisionBeforeTag()).message(revertCommitsMessageBuilder.toString()).merge().mergeClient(new ScmPomVersionsMergeClient()).build();
        this.scmProvider.revertCommits(revertCommitsRequest);
        try {
            this.scmProvider.push(PushRequest.builder().build());
        } catch (ScmException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
    for (MavenProject project : this.reactorProjects) {
        Document document = this.cachedPOMs.get(ProjectToCoordinates.EMPTY_VERSION.apply(project));
        if (document != null) {
            try {
                PomUtil.writePOM(document, project);
            } catch (Throwable t) {
                throw new MojoExecutionException("Could not revert SCM connection adaption after a failed release build. Tried to reset tag connection URL to initial state.", t);
            }
        }
    }
}
Also used : ScmException(com.itemis.maven.plugins.unleash.scm.ScmException) DeleteTagRequest(com.itemis.maven.plugins.unleash.scm.requests.DeleteTagRequest) ScmPomVersionsMergeClient(com.itemis.maven.plugins.unleash.util.scm.ScmPomVersionsMergeClient) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenProject(org.apache.maven.project.MavenProject) RevertCommitsRequest(com.itemis.maven.plugins.unleash.scm.requests.RevertCommitsRequest) ProjectToString(com.itemis.maven.plugins.unleash.util.functions.ProjectToString) Document(org.w3c.dom.Document) RollbackOnError(com.itemis.maven.plugins.cdi.annotations.RollbackOnError)

Example 3 with RevertCommitsRequest

use of com.itemis.maven.plugins.unleash.scm.requests.RevertCommitsRequest in project unleash-maven-plugin by shillner.

the class SetDevVersionsTycho method rollback.

@Override
@RollbackOnError
public void rollback() throws MojoExecutionException, MojoFailureException {
    this.log.info("Rollback of all version changes necessary for the next development cycle (POMs, MANIFESTs, ...).");
    StringBuilder message = new StringBuilder("Reversion of failed release build (step: setting of next snapshot version).");
    if (StringUtils.isNotBlank(this.scmMessagePrefix)) {
        message.insert(0, this.scmMessagePrefix);
    }
    RevertCommitsRequest revertCommitsRequest = RevertCommitsRequest.builder().fromRevision(this.metadata.getScmRevisionAfterNextDevVersion()).toRevision(this.metadata.getScmRevisionBeforeNextDevVersion()).message(message.toString()).merge().mergeClient(new ScmPomVersionsMergeClient()).push().build();
    this.scmProvider.revertCommits(revertCommitsRequest);
    // rolls back the version changes using tycho
    super.rollback();
}
Also used : ScmPomVersionsMergeClient(com.itemis.maven.plugins.unleash.util.scm.ScmPomVersionsMergeClient) RevertCommitsRequest(com.itemis.maven.plugins.unleash.scm.requests.RevertCommitsRequest) RollbackOnError(com.itemis.maven.plugins.cdi.annotations.RollbackOnError)

Aggregations

RollbackOnError (com.itemis.maven.plugins.cdi.annotations.RollbackOnError)3 RevertCommitsRequest (com.itemis.maven.plugins.unleash.scm.requests.RevertCommitsRequest)3 ScmPomVersionsMergeClient (com.itemis.maven.plugins.unleash.util.scm.ScmPomVersionsMergeClient)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MavenProject (org.apache.maven.project.MavenProject)2 Document (org.w3c.dom.Document)2 ScmException (com.itemis.maven.plugins.unleash.scm.ScmException)1 DeleteTagRequest (com.itemis.maven.plugins.unleash.scm.requests.DeleteTagRequest)1 ProjectToString (com.itemis.maven.plugins.unleash.util.functions.ProjectToString)1