Search in sources :

Example 1 with RollbackOnError

use of com.itemis.maven.plugins.cdi.annotations.RollbackOnError 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 RollbackOnError

use of com.itemis.maven.plugins.cdi.annotations.RollbackOnError in project unleash-maven-plugin by shillner.

the class SetReleaseVersions method rollback.

@RollbackOnError
public void rollback() throws MojoExecutionException {
    this.log.info("Rollback of release version updating for all project modules");
    for (MavenProject project : this.reactorProjects) {
        this.log.debug("\tRolling back modifications on POM of module '" + ProjectToString.INSTANCE.apply(project) + "'");
        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 the setting of release versions after a failed release build.", t);
            }
        }
    }
}
Also used : MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Document(org.w3c.dom.Document) RollbackOnError(com.itemis.maven.plugins.cdi.annotations.RollbackOnError)

Example 3 with RollbackOnError

use of com.itemis.maven.plugins.cdi.annotations.RollbackOnError 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 4 with RollbackOnError

use of com.itemis.maven.plugins.cdi.annotations.RollbackOnError in project unleash-maven-plugin by shillner.

the class AbstractTychoVersionsStep method rollback.

@RollbackOnError
public void rollback() throws MojoExecutionException, MojoFailureException {
    VersionsEngine versionsEngine = initializeVersionsEngine();
    try {
        // first add all module version changes to the versions engine of tycho and execute the change command
        for (MavenProject module : this.reactorProjects) {
            String version = this.cachedModuleVersions.get(ProjectToCoordinates.EMPTY_VERSION.apply(module));
            versionsEngine.addVersionChange(module.getArtifactId(), version);
        }
        versionsEngine.apply();
        // second step is to revert all pom changes by simply replacing the poms
        for (MavenProject module : this.reactorProjects) {
            this.log.debug("\tRolling back modifications on POM of module '" + ProjectToString.INSTANCE.apply(this.project) + "'");
            ArtifactCoordinates coordinates = ProjectToCoordinates.EMPTY_VERSION.apply(module);
            Document document = this.cachedPOMs.get(coordinates);
            if (document != null) {
                try {
                    PomUtil.writePOM(document, this.project);
                } catch (Throwable t) {
                    throw new MojoExecutionException("Could not revert the version update after a failed release build.", t);
                }
            }
            String version = this.cachedModuleVersions.get(coordinates);
            if (module.getModel().getVersion() != null) {
                module.getModel().setVersion(version);
            }
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Could not revert the version update after a failed release build.", e);
    }
}
Also used : MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactCoordinates(com.itemis.maven.aether.ArtifactCoordinates) ProjectToString(com.itemis.maven.plugins.unleash.util.functions.ProjectToString) IOException(java.io.IOException) VersionsEngine(org.eclipse.tycho.versions.engine.VersionsEngine) Document(org.w3c.dom.Document) RollbackOnError(com.itemis.maven.plugins.cdi.annotations.RollbackOnError)

Example 5 with RollbackOnError

use of com.itemis.maven.plugins.cdi.annotations.RollbackOnError 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)6 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 MavenProject (org.apache.maven.project.MavenProject)4 Document (org.w3c.dom.Document)4 RevertCommitsRequest (com.itemis.maven.plugins.unleash.scm.requests.RevertCommitsRequest)3 ScmPomVersionsMergeClient (com.itemis.maven.plugins.unleash.util.scm.ScmPomVersionsMergeClient)3 ProjectToString (com.itemis.maven.plugins.unleash.util.functions.ProjectToString)2 IOException (java.io.IOException)2 ArtifactCoordinates (com.itemis.maven.aether.ArtifactCoordinates)1 ScmException (com.itemis.maven.plugins.unleash.scm.ScmException)1 DeleteTagRequest (com.itemis.maven.plugins.unleash.scm.requests.DeleteTagRequest)1 AetherToMavenArtifact (com.itemis.maven.plugins.unleash.util.functions.AetherToMavenArtifact)1 File (java.io.File)1 Artifact (org.eclipse.aether.artifact.Artifact)1 VersionsEngine (org.eclipse.tycho.versions.engine.VersionsEngine)1