com.itemis.maven.plugins.unleash.steps.checks.CheckProjectVersions 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.checks;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import com.google.common.collect.Collections2;
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.logging.Logger;
import com.itemis.maven.plugins.unleash.util.functions.ProjectToString;
import com.itemis.maven.plugins.unleash.util.predicates.IsSnapshotProject;
/**
* Checks that at least one of the projects is releasable which means that at least one of the projects must have
* a snapshot version assigned.
*
* @author Stanley Hillner
* @since 1.0.0
*/
@ProcessingStep(id = "checkProjectVersions", description = "Checks that at least one of the projects as a SNAPSHOT version assigned and is thus releasable.", requiresOnline = false)
public class CheckProjectVersions implements CDIMojoProcessingStep {
@Inject
private Logger log;
@Inject
@Named("reactorProjects")
private List reactorProjects;
@Override
public void execute(ExecutionContext context) throws MojoExecutionException, MojoFailureException {
this.log.debug("Checking that at least one of the reactor projects has a SNAPSHOT version assigned.");
boolean hasSnapshotProjects = !Collections2.filter(this.reactorProjects, IsSnapshotProject.INSTANCE).isEmpty();
if (!hasSnapshotProjects) {
String errorTitle = "There are no snapshot projects that could be released!";
this.log.error(errorTitle);
this.log.error("\tThe reactor project list must contain at least one project with a SNAPSHOT version assigned.");
for (MavenProject p : this.reactorProjects) {
this.log.error("\t" + ProjectToString.INSTANCE.apply(p));
}
throw new IllegalStateException(errorTitle);
}
}
}