Example usage for org.apache.maven.lifecycle LifecycleMappingDelegate calculateLifecycleMappings

List of usage examples for org.apache.maven.lifecycle LifecycleMappingDelegate calculateLifecycleMappings

Introduction

In this page you can find the example usage for org.apache.maven.lifecycle LifecycleMappingDelegate calculateLifecycleMappings.

Prototype

Map<String, List<MojoExecution>> calculateLifecycleMappings(MavenSession session, MavenProject project,
            Lifecycle lifecycle, String lifecyclePhase) throws PluginNotFoundException, PluginResolutionException,
            PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException;

Source Link

Usage

From source file:io.fabric8.maven.core.util.GoalFinder.java

License:Apache License

private boolean checkGoalInPhase(MavenProject project, MavenSession session, String goal, String phase)
        throws MojoExecutionException {
    Lifecycle lifecycle = defaultLifeCycles.get(phase);
    if (lifecycle == null) {
        throw new MojoExecutionException("Cannot find lifecycle phase " + phase);
    }//w  ww . j  a v a  2  s . c  o  m
    LifecycleMappingDelegate delegate = findDelegate(lifecycle);
    try {
        Map<String, List<MojoExecution>> executionsMap = delegate.calculateLifecycleMappings(session, project,
                lifecycle, phase);
        boolean foundPhase = false;
        boolean foundGoal = false;

        for (String p : lifecycle.getPhases()) {
            List<MojoExecution> executions = executionsMap.get(p);
            if (executions != null) {
                for (MojoExecution execution : executions) {
                    MojoDescriptor desc = execution.getMojoDescriptor();
                    if (desc != null && desc.getFullGoalName().equals(goal)) {
                        foundGoal = true;
                        break;
                    }
                }
            }
            if (phase.equals(p)) {
                foundPhase = true;
                break;
            }
        }
        return foundPhase && foundGoal;
    } catch (Exception e) {
        throw new MojoExecutionException("Interna: Cannot extract executions", e);
    }
}