com.atlassian.maven.plugin.clover.internal.lifecycle.MavenLifecycleAnalyzer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of clover-maven-plugin Show documentation
Show all versions of clover-maven-plugin Show documentation
Maven plugin for Clover.
MIGRATION NOTICE: Since Clover 4.1.0 this plugin is named com.atlassian.maven.plugins:clover-maven-plugin.
In previous versions it was named com.atlassian.maven.plugins:maven-clover2-plugin.
The newest version!
package com.atlassian.maven.plugin.clover.internal.lifecycle;
import com.atlassian.clover.api.CloverException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public abstract class MavenLifecycleAnalyzer {
protected final LifecycleExecutor lifecycleExecutor;
protected final MavenProject mavenProject;
protected final MavenSession mavenSession;
public MavenLifecycleAnalyzer(@NotNull final LifecycleExecutor lifecycleExecutor,
@NotNull final MavenProject mavenProject,
@NotNull final MavenSession mavenSession) {
this.lifecycleExecutor = lifecycleExecutor;
this.mavenProject = mavenProject;
this.mavenSession = mavenSession;
}
/**
* Return true
if current Maven version is compatible with this analyzer.
*
* @return boolean
*/
public abstract boolean isCompatibleVersion();
/**
* Return list of build phases which will be executed. It may also return goals passed from a command line.
*
* @return Set<String>
* @throws CloverException in case when build analysis has failed
*/
public abstract Set getPhasesToBeExecuted() throws CloverException;
protected Set getPhasesFromMojoExecutions(@NotNull final List mojoExecutions) {
final Set phases = new HashSet<>();
for (final MojoExecution mojoExecution : mojoExecutions) {
phases.addAll(getPhasesFromMojoExecution(mojoExecution));
}
return phases;
}
protected List getPhasesFromMojoExecution(@NotNull final MojoExecution mojoExecution) {
final List phases = new ArrayList<>();
final String defaultPhase = mojoExecution.getMojoDescriptor().getPhase();
if (defaultPhase != null) {
phases.add(defaultPhase);
}
final String forkedPhase = mojoExecution.getMojoDescriptor().getExecutePhase();
if (forkedPhase != null) {
phases.add(forkedPhase);
}
return phases;
}
}