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

Go to download

Maven plugin for Clover. MIGRATION NOTICE: Since next major Clover release this plugin will be renamed to com.atlassian.maven.plugins:clover-maven-plugin. Thus, goals will also be renamed, e.g. 'clover2:setup' will become 'clover:setup'.

The newest version!
package com.atlassian.maven.plugin.clover.internal.lifecycle;

import com.atlassian.clover.api.CloverException;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
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.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 = Sets.newHashSet();
        for (final MojoExecution mojoExecution : mojoExecutions) {
            phases.addAll(getPhasesFromMojoExecution(mojoExecution));
        }
        return phases;
    }

    protected List getPhasesFromMojoExecution(@NotNull final MojoExecution mojoExecution) {
        final List phases = Lists.newArrayList();
        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