Search in sources :

Example 1 with MojoExecution

use of org.apache.maven.plugin.MojoExecution in project maven-plugins by apache.

the class PdfMojo method getMavenReport.

/**
     * @param mojoDescriptor not null
     * @return the MavenReport instance for the given mojoDescriptor.
     * @throws MojoExecutionException if any
     * @since 1.1
     */
private MavenReport getMavenReport(MojoDescriptor mojoDescriptor) throws MojoExecutionException {
    ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(mojoDescriptor.getPluginDescriptor().getClassRealm().getClassLoader());
        MojoExecution mojoExecution = new MojoExecution(mojoDescriptor);
        return pluginManager.getReport(project, mojoExecution, session);
    } catch (ArtifactNotFoundException e) {
        throw new MojoExecutionException("ArtifactNotFoundException: " + e.getMessage(), e);
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException("ArtifactResolutionException: " + e.getMessage(), e);
    } catch (PluginConfigurationException e) {
        throw new MojoExecutionException("PluginConfigurationException: " + e.getMessage(), e);
    } catch (PluginManagerException e) {
        throw new MojoExecutionException("PluginManagerException: " + e.getMessage(), e);
    } finally {
        Thread.currentThread().setContextClassLoader(oldClassLoader);
    }
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoExecution(org.apache.maven.plugin.MojoExecution) PluginConfigurationException(org.apache.maven.plugin.PluginConfigurationException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) PluginManagerException(org.apache.maven.plugin.PluginManagerException)

Example 2 with MojoExecution

use of org.apache.maven.plugin.MojoExecution in project intellij-plugins by JetBrains.

the class Maven method createMojoExecution.

public MojoExecution createMojoExecution(Plugin plugin, String goal, MavenProject project) throws Exception {
    if (plugin.getVersion() == null) {
        plugin.setVersion(plexusContainer.lookup(PluginVersionResolver.class).resolve(new DefaultPluginVersionRequest(plugin, session)).getVersion());
    }
    MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor(plugin, goal, project.getRemotePluginRepositories(), session.getRepositorySession());
    List<PluginExecution> executions = plugin.getExecutions();
    MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, executions.isEmpty() ? null : executions.get(executions.size() - 1).getId(), MojoExecution.Source.CLI);
    plexusContainer.lookup(LifecycleExecutionPlanCalculator.class).setupMojoExecution(session, project, mojoExecution);
    return mojoExecution;
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) PluginVersionResolver(org.apache.maven.plugin.version.PluginVersionResolver) MojoExecution(org.apache.maven.plugin.MojoExecution) DefaultPluginVersionRequest(org.apache.maven.plugin.version.DefaultPluginVersionRequest) LifecycleExecutionPlanCalculator(org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator)

Example 3 with MojoExecution

use of org.apache.maven.plugin.MojoExecution in project liferay-ide by liferay.

the class MavenUtil method executeGoals.

public static IStatus executeGoals(IMavenProjectFacade facade, IMavenExecutionContext context, List<String> goals, IProgressMonitor monitor) throws CoreException {
    IMaven maven = MavenPlugin.getMaven();
    MavenProject mavenProject = facade.getMavenProject(monitor);
    MavenExecutionPlan plan = maven.calculateExecutionPlan(mavenProject, goals, true, monitor);
    List<MojoExecution> mojos = plan.getMojoExecutions();
    ResolverConfiguration configuration = facade.getResolverConfiguration();
    configuration.setResolveWorkspaceProjects(true);
    for (MojoExecution mojo : mojos) {
        maven.execute(mavenProject, mojo, monitor);
    }
    return Status.OK_STATUS;
}
Also used : ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) MavenProject(org.apache.maven.project.MavenProject) MojoExecution(org.apache.maven.plugin.MojoExecution) MavenExecutionPlan(org.apache.maven.lifecycle.MavenExecutionPlan) IMaven(org.eclipse.m2e.core.embedder.IMaven)

Example 4 with MojoExecution

use of org.apache.maven.plugin.MojoExecution in project liferay-ide by liferay.

the class ThemePluginBuildParticipant method executeThemeMojo.

protected IStatus executeThemeMojo(IMavenProjectFacade facade, IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
    IStatus retval = null;
    List<String> goals = Collections.singletonList(getGoal());
    MavenProject mavenProject = facade.getMavenProject(monitor);
    MavenExecutionPlan plan = maven.calculateExecutionPlan(mavenProject, goals, true, monitor);
    monitor.worked(10);
    MojoExecution liferayMojoExecution = MavenUtil.getExecution(plan, ILiferayMavenConstants.LIFERAY_MAVEN_PLUGIN_ARTIFACT_ID);
    Xpp3Dom originalConfig = liferayMojoExecution.getConfiguration();
    Xpp3Dom config = Xpp3DomUtils.mergeXpp3Dom(new Xpp3Dom("configuration"), originalConfig);
    configureExecution(facade, config);
    boolean parentHierarchyLoaded = false;
    try {
        parentHierarchyLoaded = MavenUtil.loadParentHierarchy(facade, monitor);
        monitor.worked(10);
        ResolverConfiguration configuration = facade.getResolverConfiguration();
        configuration.setResolveWorkspaceProjects(true);
        liferayMojoExecution.setConfiguration(config);
        maven.execute(mavenProject, liferayMojoExecution, monitor);
        monitor.worked(50);
        MavenSession mavenSession = context.getSession();
        List<Throwable> exceptions = mavenSession.getResult().getExceptions();
        if (exceptions.size() == 1) {
            retval = LiferayMavenCore.createErrorStatus(exceptions.get(0));
        } else if (exceptions.size() > 1) {
            List<IStatus> statuses = new ArrayList<>();
            for (Throwable t : exceptions) {
                statuses.add(LiferayMavenCore.createErrorStatus(t));
            }
            retval = LiferayMavenCore.createMultiStatus(IStatus.ERROR, statuses.toArray(new IStatus[0]));
        }
        retval = retval == null ? Status.OK_STATUS : retval;
    } catch (CoreException ce) {
        retval = LiferayMavenCore.createErrorStatus(ce);
    } finally {
        liferayMojoExecution.setConfiguration(originalConfig);
        if (parentHierarchyLoaded) {
            mavenProject.setParent(null);
        }
    }
    return retval;
}
Also used : ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) IStatus(org.eclipse.core.runtime.IStatus) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) MavenSession(org.apache.maven.execution.MavenSession) MavenProject(org.apache.maven.project.MavenProject) CoreException(org.eclipse.core.runtime.CoreException) MojoExecution(org.apache.maven.plugin.MojoExecution) ArrayList(java.util.ArrayList) List(java.util.List) MavenExecutionPlan(org.apache.maven.lifecycle.MavenExecutionPlan)

Example 5 with MojoExecution

use of org.apache.maven.plugin.MojoExecution in project m2e-nar by maven-nar.

the class MavenUtils method buildCompileNarExecutions.

public static List<NarExecution> buildCompileNarExecutions(final ConfiguratorContext context, final IMavenProjectFacade facade, final IProgressMonitor monitor) throws CoreException {
    List<NarExecution> narExecutions = new ArrayList<NarExecution>();
    List<MojoExecution> compileExecutions = MavenUtils.getCompileExecutions(context, facade, monitor);
    for (MojoExecution compileExecution : compileExecutions) {
        NarExecution narSettings = MavenUtils.readCompileSettings(context, facade, compileExecution, monitor);
        narExecutions.add(narSettings);
    }
    return narExecutions;
}
Also used : MojoExecution(org.apache.maven.plugin.MojoExecution) ArrayList(java.util.ArrayList) NarExecution(com.github.sdedwards.m2e_nar.internal.model.NarExecution)

Aggregations

MojoExecution (org.apache.maven.plugin.MojoExecution)32 MavenProject (org.apache.maven.project.MavenProject)22 MavenSession (org.apache.maven.execution.MavenSession)13 Test (org.junit.Test)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 List (java.util.List)7 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)7 MavenExecutionPlan (org.apache.maven.lifecycle.MavenExecutionPlan)6 Plugin (org.apache.maven.model.Plugin)6 MojoDescriptor (org.apache.maven.plugin.descriptor.MojoDescriptor)5 IMaven (org.eclipse.m2e.core.embedder.IMaven)5 ResolverConfiguration (org.eclipse.m2e.core.project.ResolverConfiguration)5 Path (java.nio.file.Path)4 MavenProjectStub (org.apache.maven.plugin.testing.stubs.MavenProjectStub)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IStatus (org.eclipse.core.runtime.IStatus)4 IMavenExecutionContext (org.eclipse.m2e.core.embedder.IMavenExecutionContext)4 Set (java.util.Set)3 CoreException (org.eclipse.core.runtime.CoreException)3