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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations