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