Example usage for org.apache.maven.lifecycle MavenExecutionPlan getMojoExecutions

List of usage examples for org.apache.maven.lifecycle MavenExecutionPlan getMojoExecutions

Introduction

In this page you can find the example usage for org.apache.maven.lifecycle MavenExecutionPlan getMojoExecutions.

Prototype

public List<MojoExecution> getMojoExecutions() 

Source Link

Usage

From source file:com.liferay.ide.maven.core.MavenProjectBuilder.java

License:Open Source License

public IStatus execJarMojo(IMavenProjectFacade projectFacade, IProgressMonitor monitor) throws CoreException {

    IStatus retval = null;/*w w w.  jav  a 2 s .  co  m*/

    final ICallable<IStatus> callable = new ICallable<IStatus>() {

        public IStatus call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
            MavenProject mavenProject = projectFacade.getMavenProject();

            if (mavenProject == null) {
                mavenProject = projectFacade.getMavenProject(monitor);
            }

            final IMaven maven = MavenPlugin.getMaven();

            final MavenExecutionPlan plan = maven.calculateExecutionPlan(mavenProject, Arrays.asList("jar:jar"),
                    true, monitor);
            final List<MojoExecution> mojoExecutions = plan.getMojoExecutions();

            if (mojoExecutions != null) {
                for (MojoExecution mojoExecution : mojoExecutions) {
                    MavenPlugin.getMaven().execute(mavenProject, mojoExecution, monitor);
                }
            }

            return Status.OK_STATUS;
        }
    };

    retval = executeMaven(projectFacade, callable, monitor);

    return retval;
}

From source file:com.liferay.ide.maven.core.MavenUtil.java

License:Open Source License

public static IStatus executeGoals(final IMavenProjectFacade facade, final IMavenExecutionContext context,
        final List<String> goals, final IProgressMonitor monitor) throws CoreException {
    final IMaven maven = MavenPlugin.getMaven();
    final MavenProject mavenProject = facade.getMavenProject(monitor);
    final MavenExecutionPlan plan = maven.calculateExecutionPlan(mavenProject, goals, true, monitor);
    final List<MojoExecution> mojos = plan.getMojoExecutions();

    final ResolverConfiguration configuration = facade.getResolverConfiguration();
    configuration.setResolveWorkspaceProjects(true);

    for (MojoExecution mojo : mojos) {
        maven.execute(mavenProject, mojo, monitor);
    }//from   w  w  w . j  a v  a  2s.c o m

    return Status.OK_STATUS;
}

From source file:com.liferay.ide.maven.core.MavenUtil.java

License:Open Source License

public static MojoExecution getExecution(MavenExecutionPlan plan, String artifactId) {
    if (plan != null) {
        for (MojoExecution execution : plan.getMojoExecutions()) {
            if (artifactId.equals(execution.getArtifactId())) {
                return execution;
            }//w  ww. j  ava2s.  c o  m
        }
    }

    return null;
}

From source file:fr.jcgay.maven.plugin.buildplan.ListMojo.java

License:Apache License

public void execute() throws MojoExecutionException, MojoFailureException {

    MavenExecutionPlan plan = calculateExecutionPlan();

    TableDescriptor descriptor = ListTableDescriptor.of(plan.getMojoExecutions());
    String row = descriptor.rowFormat();

    getLog().info(lineSeparator(descriptor));
    getLog().info(tableHead(row));/*ww w .j a v a2s .c om*/
    getLog().info(lineSeparator(descriptor));

    for (MojoExecution execution : plan.getMojoExecutions()) {
        getLog().info(tableRow(row, execution));
    }
}

From source file:org.eclipse.m2e.core.internal.lifecyclemapping.discovery.LifecycleMappingConfiguration.java

License:Open Source License

static LifecycleMappingConfiguration calculate(Collection<MavenProjectInfo> projects,
        IProgressMonitor monitor) {/*from w w w. j  a v  a2s .  c  om*/
    monitor.beginTask("Analysing project execution plan", projects.size());

    LifecycleMappingConfiguration result = new LifecycleMappingConfiguration();

    List<MavenProjectInfo> nonErrorProjects = new ArrayList<MavenProjectInfo>();
    final IMaven maven = MavenPlugin.getMaven();

    for (final MavenProjectInfo projectInfo : projects) {
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        MavenProject mavenProject = null;
        try {
            SubMonitor subMmonitor = SubMonitor.convert(monitor,
                    NLS.bind("Analysing {0}", projectInfo.getLabel()), 1);

            MavenExecutionResult executionResult = maven.execute(new ICallable<MavenExecutionResult>() {
                public MavenExecutionResult call(IMavenExecutionContext context, IProgressMonitor monitor)
                        throws CoreException {
                    return maven.readMavenProject(projectInfo.getPomFile(),
                            context.newProjectBuildingRequest());
                }
            }, subMmonitor);

            mavenProject = executionResult.getProject();

            if (monitor.isCanceled()) {
                throw new OperationCanceledException();
            }

            if (mavenProject != null) {
                if ("pom".equals(projectInfo.getModel().getPackaging())) {
                    // m2e uses a noop lifecycle mapping for packaging=pom
                    List<MojoExecution> mojoExecutions = new ArrayList<MojoExecution>();
                    PackagingTypeMappingConfiguration pkgConfiguration = new PackagingTypeMappingConfiguration(
                            mavenProject.getPackaging(), null /*lifecycleMappingId*/);
                    ProjectLifecycleMappingConfiguration configuration = new ProjectLifecycleMappingConfiguration(
                            projectInfo.getLabel(), mavenProject, mojoExecutions, pkgConfiguration);
                    result.addProject(projectInfo, configuration);
                    nonErrorProjects.add(projectInfo);
                    continue;
                }

                List<MojoExecution> mojoExecutions = new ArrayList<MojoExecution>();
                MavenExecutionPlan executionPlan = maven.calculateExecutionPlan(mavenProject,
                        Arrays.asList(ProjectRegistryManager.LIFECYCLE_CLEAN), false, subMmonitor);
                mojoExecutions.addAll(executionPlan.getMojoExecutions());
                executionPlan = maven.calculateExecutionPlan(mavenProject,
                        Arrays.asList(ProjectRegistryManager.LIFECYCLE_DEFAULT), false, subMmonitor);
                mojoExecutions.addAll(executionPlan.getMojoExecutions());
                executionPlan = maven.calculateExecutionPlan(mavenProject,
                        Arrays.asList(ProjectRegistryManager.LIFECYCLE_SITE), false, subMmonitor);
                mojoExecutions.addAll(executionPlan.getMojoExecutions());

                LifecycleMappingResult lifecycleResult = new LifecycleMappingResult();

                List<MappingMetadataSource> metadataSources;
                try {
                    metadataSources = LifecycleMappingFactory.getProjectMetadataSources(mavenProject,
                            LifecycleMappingFactory.getBundleMetadataSources(), mojoExecutions, true, monitor);
                } catch (LifecycleMappingConfigurationException e) {
                    // could not read/parse/interpret mapping metadata configured in the pom or inherited from parent pom.
                    // record the problem and continue
                    log.error(e.getMessage(), e);
                    continue;
                }

                LifecycleMappingFactory.calculateEffectiveLifecycleMappingMetadata(lifecycleResult,
                        metadataSources, mavenProject, mojoExecutions, false, monitor);
                LifecycleMappingFactory.instantiateLifecycleMapping(lifecycleResult, mavenProject,
                        lifecycleResult.getLifecycleMappingId());
                LifecycleMappingFactory.instantiateProjectConfigurators(mavenProject, lifecycleResult,
                        lifecycleResult.getMojoExecutionMapping());

                PackagingTypeMappingConfiguration pkgConfiguration = new PackagingTypeMappingConfiguration(
                        mavenProject.getPackaging(),
                        isProjectSource(lifecycleResult.getLifecycleMappingMetadata())
                                ? lifecycleResult.getLifecycleMappingId()
                                : null);
                ProjectLifecycleMappingConfiguration configuration = new ProjectLifecycleMappingConfiguration(
                        projectInfo.getLabel(), mavenProject, mojoExecutions, pkgConfiguration);

                if (lifecycleResult.getLifecycleMapping() != null) {
                    result.addInstalledProvider(configuration.getPackagingTypeMappingConfiguration()
                            .getLifecycleMappingRequirement());
                }

                for (Map.Entry<MojoExecutionKey, List<IPluginExecutionMetadata>> entry : lifecycleResult
                        .getMojoExecutionMapping().entrySet()) {
                    MojoExecutionKey key = entry.getKey();
                    List<IPluginExecutionMetadata> mapppings = entry.getValue();
                    IPluginExecutionMetadata primaryMapping = null;
                    if (mapppings != null && !mapppings.isEmpty()) {
                        primaryMapping = mapppings.get(0);
                    }
                    MojoExecutionMappingConfiguration executionConfiguration = new MojoExecutionMappingConfiguration(
                            key, isProjectSource(primaryMapping) ? primaryMapping : null);
                    configuration.addMojoExecution(executionConfiguration);
                    if (primaryMapping != null) {
                        switch (primaryMapping.getAction()) {
                        case configurator:
                            AbstractProjectConfigurator projectConfigurator = lifecycleResult
                                    .getProjectConfigurators()
                                    .get(LifecycleMappingFactory.getProjectConfiguratorId(primaryMapping));
                            if (projectConfigurator != null) {
                                result.addInstalledProvider(
                                        executionConfiguration.getLifecycleMappingRequirement());
                            }
                            break;
                        case error:
                        case execute:
                        case ignore:
                            result.addInstalledProvider(
                                    executionConfiguration.getLifecycleMappingRequirement());
                            break;
                        default:
                            throw new IllegalArgumentException(
                                    "Missing handling for action=" + primaryMapping.getAction());
                        }
                    }
                }
                result.addProject(projectInfo, configuration);
                nonErrorProjects.add(projectInfo);
            } else {
                //XXX mkleint: what shall happen now? we don't have a valid MavenProject instance to play with,
                // currently we skip such project silently, is that ok?
            }

        } catch (OperationCanceledException ex) {
            throw ex;
        } catch (Throwable th) {
            result.addError(projectInfo, th);
        } finally {
            if (mavenProject != null) {
                ((MavenImpl) maven).releaseExtensionsRealm(mavenProject);
            }
        }
    }

    result.setSelectedProjects(nonErrorProjects);

    return result;
}

From source file:org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.java

License:Open Source License

private List<MojoExecution> calculateExecutionPlan(IFile pom, final MavenProject mavenProject,
        final String lifecycle, final IProgressMonitor monitor) {
    List<MojoExecution> mojoExecutions = null;
    try {/*from w  w  w.ja  v a  2  s .  c o m*/
        MavenExecutionPlan executionPlan = maven.calculateExecutionPlan(mavenProject, Arrays.asList(lifecycle),
                false, monitor);
        return executionPlan.getMojoExecutions();
    } catch (CoreException e) {
        markerManager.addErrorMarkers(pom, IMavenConstants.MARKER_POM_LOADING_ID, e);
    }
    return mojoExecutions;
}

From source file:org.eclipse.m2e.wtp.internal.filtering.ResourceFilteringBuildParticipant.java

License:Open Source License

private MojoExecution getExecution(MavenExecutionPlan executionPlan, String artifactId) {
    if (executionPlan == null)
        return null;
    for (MojoExecution execution : executionPlan.getMojoExecutions()) {
        if (artifactId.equals(execution.getArtifactId())) {
            return execution;
        }/*from ww  w .  j ava  2s.c o  m*/
    }
    return null;
}

From source file:org.eclipse.m2e.wtp.MavenDeploymentDescriptorManagement.java

License:Open Source License

private MojoExecution getExecution(MavenExecutionPlan executionPlan, String artifactId, String goal)
        throws CoreException {
    for (MojoExecution execution : executionPlan.getMojoExecutions()) {
        if (artifactId.equals(execution.getArtifactId()) && goal.equals(execution.getGoal())) {
            return execution;
        }/*from  w w w . j a  v  a 2s  .  com*/
    }
    return null;
}

From source file:org.eclipse.m2e.wtp.MavenSessionHelper.java

License:Open Source License

public static MojoExecution getExecution(MavenExecutionPlan executionPlan, String artifactId)
        throws CoreException {
    if (executionPlan == null)
        return null;
    for (MojoExecution execution : executionPlan.getMojoExecutions()) {
        if (artifactId.equals(execution.getArtifactId())) {
            return execution;
        }/*from  w ww  .  ja  v a 2s. c  o m*/
    }
    return null;
}

From source file:org.maven.ide.eclipse.extensions.shared.util.MavenPluginWrapper.java

License:Open Source License

public static MojoExecution findMojoExecution(IProgressMonitor monitor, IMavenProjectFacade mavenProjectFacade,
        final String pluginGroupId, final String pluginArtifactId, final String[] pluginGoal)
        throws CoreException {
    MavenExecutionPlan executionPlan = mavenProjectFacade.getExecutionPlan(monitor);
    List<MojoExecution> mojoExecutions = executionPlan.getMojoExecutions();
    MojoExecution exec = searchExecutions(pluginGroupId, pluginArtifactId, pluginGoal, mojoExecutions);
    if (exec != null) {
        return exec;
    }/* www.  ja va2s.c  o m*/
    // maybe it's bound to a phase after 'package', we have to do this the slow way.
    IMaven maven = MavenPlugin.getDefault().getMaven();
    MavenExecutionRequest mer = maven.createExecutionRequest(monitor);
    List<String> goals = Collections.singletonList("deploy");
    mer.setGoals(goals);
    MavenExecutionPlan fullPlan = maven.calculateExecutionPlan(mer, mavenProjectFacade.getMavenProject(monitor),
            monitor);
    mojoExecutions = fullPlan.getMojoExecutions();
    exec = searchExecutions(pluginGroupId, pluginArtifactId, pluginGoal, mojoExecutions);
    if (exec != null) {
        return exec;
    }
    mer = maven.createExecutionRequest(monitor);
    goals = Collections.singletonList("site:site");
    mer.setGoals(goals);
    fullPlan = maven.calculateExecutionPlan(mer, mavenProjectFacade.getMavenProject(monitor), monitor);
    mojoExecutions = fullPlan.getMojoExecutions();

    return searchExecutions(pluginGroupId, pluginArtifactId, pluginGoal, mojoExecutions);
}