com.itemis.maven.plugins.unleash.steps.actions.tycho.SetDevVersionsTycho Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unleash-maven-plugin Show documentation
Show all versions of unleash-maven-plugin Show documentation
This plugin provides a generic alternative to the error-prone default release plugin provided by Maven. It is designed to require a minimal effort of work for releasing modules and being extensible to integrate in every project setup.
package com.itemis.maven.plugins.unleash.steps.actions.tycho;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.w3c.dom.Document;
import com.itemis.maven.plugins.cdi.CDIMojoProcessingStep;
import com.itemis.maven.plugins.cdi.ExecutionContext;
import com.itemis.maven.plugins.cdi.annotations.ProcessingStep;
import com.itemis.maven.plugins.cdi.annotations.RollbackOnError;
import com.itemis.maven.plugins.cdi.logging.Logger;
import com.itemis.maven.plugins.unleash.ReleaseMetadata;
import com.itemis.maven.plugins.unleash.ReleasePhase;
import com.itemis.maven.plugins.unleash.scm.ScmProvider;
import com.itemis.maven.plugins.unleash.scm.requests.RevertCommitsRequest;
import com.itemis.maven.plugins.unleash.util.DevVersionUtil;
import com.itemis.maven.plugins.unleash.util.PomUtil;
import com.itemis.maven.plugins.unleash.util.scm.ScmPomVersionsMergeClient;
import com.itemis.maven.plugins.unleash.util.scm.ScmProviderRegistry;
/**
* Uses Eclipse Tycho features to upgrade the POMs and MANIFESTs with the next development versions. It also updates
* versions of bundle references.
*
* @author Stanley Hillner
* @since 1.1.0
*/
@ProcessingStep(id = "setDevVersionTycho", description = "Uses the tycho-versions-plugin to update the POM and MANIFEST versions for the next development cycle.", requiresOnline = true)
public class SetDevVersionsTycho extends AbstractTychoVersionsStep implements CDIMojoProcessingStep {
@Inject
private Logger log;
@Inject
@Named("reactorProjects")
private List reactorProjects;
@Inject
private ReleaseMetadata metadata;
@Inject
@Named("scmMessagePrefix")
private String scmMessagePrefix;
@Inject
private ScmProviderRegistry scmProviderRegistry;
private ScmProvider scmProvider;
@Inject
private DevVersionUtil util;
@Override
public void execute(ExecutionContext context) throws MojoExecutionException, MojoFailureException {
this.log.info("Updating project modules with release versions (POM and MANIFEST versions)");
super.execute(context);
this.scmProvider = this.scmProviderRegistry.getProvider();
for (MavenProject project : this.reactorProjects) {
try {
Document document = PomUtil.parsePOM(project);
this.util.revertScmSettings(project, document);
PomUtil.writePOM(document, project);
} catch (Throwable t) {
throw new MojoFailureException("Could not update versions for next development cycle.", t);
}
}
this.util.commitChanges(false);
}
@Override
protected ReleasePhase currentReleasePhase() {
return ReleasePhase.POST_RELEASE;
}
@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();
}
}