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);
}
}
}
}
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);
}
}
}
}
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);
}
}
}
}
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);
}
}
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();
}
Aggregations