Search in sources :

Example 1 with LifecycleMappingDelegate

use of org.apache.maven.lifecycle.LifecycleMappingDelegate in project fabric8-maven-plugin by fabric8io.

the class GoalFinder method findDelegate.

// Find a delegate
private LifecycleMappingDelegate findDelegate(Lifecycle lifecycle) {
    LifecycleMappingDelegate delegate;
    String lifecycleId = lifecycle.getId();
    if (Arrays.binarySearch(DefaultLifecycles.STANDARD_LIFECYCLES, lifecycleId) >= 0) {
        delegate = standardDelegate;
    } else {
        delegate = delegates.get(lifecycleId);
        if (delegate == null) {
            delegate = standardDelegate;
        }
    }
    return delegate;
}
Also used : LifecycleMappingDelegate(org.apache.maven.lifecycle.LifecycleMappingDelegate) DefaultLifecycleMappingDelegate(org.apache.maven.lifecycle.internal.DefaultLifecycleMappingDelegate)

Example 2 with LifecycleMappingDelegate

use of org.apache.maven.lifecycle.LifecycleMappingDelegate in project fabric8-maven-plugin by fabric8io.

the class GoalFinder method checkGoalInPhase.

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);
    }
    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);
    }
}
Also used : MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoExecution(org.apache.maven.plugin.MojoExecution) Lifecycle(org.apache.maven.lifecycle.Lifecycle) List(java.util.List) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) LifecycleMappingDelegate(org.apache.maven.lifecycle.LifecycleMappingDelegate) DefaultLifecycleMappingDelegate(org.apache.maven.lifecycle.internal.DefaultLifecycleMappingDelegate)

Aggregations

LifecycleMappingDelegate (org.apache.maven.lifecycle.LifecycleMappingDelegate)2 DefaultLifecycleMappingDelegate (org.apache.maven.lifecycle.internal.DefaultLifecycleMappingDelegate)2 List (java.util.List)1 Lifecycle (org.apache.maven.lifecycle.Lifecycle)1 MojoExecution (org.apache.maven.plugin.MojoExecution)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoDescriptor (org.apache.maven.plugin.descriptor.MojoDescriptor)1