All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.atlassian.maven.plugin.clover.internal.lifecycle.MavenLifecycleAnalyzer Maven / Gradle / Ivy

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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy