/** * Taken from MojoExecutor of Don Brown. Make it working with Maven 3.1. * * @param plugin * @param goal * @param configuration * @param env * @throws MojoExecutionException * @throws PluginResolutionException * @throws PluginDescriptorParsingException * @throws InvalidPluginDescriptorException * @throws PluginManagerException * @throws PluginConfigurationException * @throws MojoFailureException */ private void executeMojo( Plugin plugin, String goal, Xpp3Dom configuration ) throws MojoExecutionException, PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException, MojoFailureException, PluginConfigurationException, PluginManagerException { if ( configuration == null ) { throw new NullPointerException( "configuration may not be null" ); } PluginDescriptor pluginDescriptor = getPluginDescriptor( plugin ); MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal ); if ( mojoDescriptor == null ) { throw new MojoExecutionException( "Could not find goal '" + goal + "' in plugin " + plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion() ); } MojoExecution exec = mojoExecution( mojoDescriptor, configuration ); pluginManager.executeMojo( getMavenSession(), exec ); }
@SuppressWarnings( { "UnusedDeclaration" } ) public MavenExecutionPlan calculateExecutionPlan( MavenSession session, boolean setup, String... tasks ) throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException, PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException { List<TaskSegment> taskSegments = lifecycleTaskSegmentCalculator.calculateTaskSegments( session, Arrays.asList( tasks ) ); TaskSegment mergedSegment = new TaskSegment( false ); for ( TaskSegment taskSegment : taskSegments ) { mergedSegment.getTasks().addAll( taskSegment.getTasks() ); } return lifecycleExecutionPlanCalculator.calculateExecutionPlan( session, session.getCurrentProject(), mergedSegment.getTasks(), setup ); }
public PluginDescriptor loadPluginFully( Plugin plugin, MavenProject project, MavenSession session ) throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException, InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException, PluginVersionNotFoundException { PluginDescriptor pluginDescriptor = loadPluginDescriptor( plugin, project, session ); try { pluginManager.setupPluginRealm( pluginDescriptor, session, null, null, null ); } catch ( PluginResolutionException e ) { throw new PluginManagerException( plugin, e.getMessage(), e ); } return pluginDescriptor; }
@SuppressWarnings("unchecked") protected void startProject(MavenProject project, String executionId, XmlPlexusConfiguration process) throws InvalidPluginDescriptorException, PluginResolutionException, PluginDescriptorParsingException, PluginNotFoundException, PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException { Plugin plugin = this.project.getPlugin("org.wildfly.swarm:wildfly-swarm-plugin"); Xpp3Dom config = getConfiguration(project, executionId); Xpp3Dom processConfig = getProcessConfiguration(process); Xpp3Dom globalConfig = getGlobalConfig(); Xpp3Dom mergedConfig = Xpp3DomUtils.mergeXpp3Dom(processConfig, config); mergedConfig = Xpp3DomUtils.mergeXpp3Dom(mergedConfig, globalConfig); PluginDescriptor pluginDescriptor = this.pluginManager.loadPlugin(plugin, project.getRemotePluginRepositories(), this.repositorySystemSession); MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo("start"); MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, mergedConfig); mavenSession.setCurrentProject(project); this.pluginManager.executeMojo(mavenSession, mojoExecution); List<SwarmProcess> launched = (List<SwarmProcess>) mavenSession.getPluginContext(pluginDescriptor, project).get(SWARM_PROCESS); List<SwarmProcess> procs = (List<SwarmProcess>) getPluginContext().get(SWARM_PROCESS); if (procs == null) { procs = new ArrayList<>(); getPluginContext().put(SWARM_PROCESS, procs); } procs.addAll(launched); mavenSession.setCurrentProject(this.project); }
@SuppressWarnings("unchecked") protected void startProject(MavenProject project, String executionId, XmlPlexusConfiguration process) throws InvalidPluginDescriptorException, PluginResolutionException, PluginDescriptorParsingException, PluginNotFoundException, PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException { Plugin plugin = this.project.getPlugin("org.wildfly.swarm:wildfly-swarm-plugin"); Xpp3Dom config = getConfiguration(project, executionId); Xpp3Dom processConfig = getProcessConfiguration(process); Xpp3Dom globalConfig = getGlobalConfig(); Xpp3Dom mergedConfig = Xpp3DomUtils.mergeXpp3Dom(processConfig, config); mergedConfig = Xpp3DomUtils.mergeXpp3Dom(mergedConfig, globalConfig); PluginDescriptor pluginDescriptor = this.pluginManager.loadPlugin(plugin, project.getRemotePluginRepositories(), this.repositorySystemSession); MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo("start"); MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, mergedConfig); mavenSession.setCurrentProject(project); this.pluginManager.executeMojo(mavenSession, mojoExecution); List<SwarmProcess> launched = (List<SwarmProcess>) mavenSession.getPluginContext(pluginDescriptor, project).get("swarm-process"); List<SwarmProcess> procs = (List<SwarmProcess>) getPluginContext().get("swarm-process"); if (procs == null) { procs = new ArrayList<>(); getPluginContext().put("swarm-process", procs); } procs.addAll(launched); mavenSession.setCurrentProject(this.project); }
public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks ) throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException, PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException { return calculateExecutionPlan( session, true, tasks ); }
public Object getPluginComponent( Plugin plugin, String role, String roleHint ) throws PluginManagerException, ComponentLookupException { MavenSession session = legacySupport.getSession(); PluginDescriptor pluginDescriptor; try { pluginDescriptor = pluginManager.getPluginDescriptor( plugin, session.getCurrentProject().getRemotePluginRepositories(), session.getRepositorySession() ); pluginManager.setupPluginRealm( pluginDescriptor, session, null, null, null ); } catch ( Exception e ) { throw new PluginManagerException( plugin, e.getMessage(), e ); } ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader( pluginDescriptor.getClassRealm() ); return container.lookup( role, roleHint ); } finally { Thread.currentThread().setContextClassLoader( oldClassLoader ); } }
public Map getPluginComponents( Plugin plugin, String role ) throws ComponentLookupException, PluginManagerException { MavenSession session = legacySupport.getSession(); PluginDescriptor pluginDescriptor; try { pluginDescriptor = pluginManager.getPluginDescriptor( plugin, session.getCurrentProject().getRemotePluginRepositories(), session.getRepositorySession() ); pluginManager.setupPluginRealm( pluginDescriptor, session, null, null, null ); } catch ( Exception e ) { throw new PluginManagerException( plugin, e.getMessage(), e ); } ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader( pluginDescriptor.getClassRealm() ); return container.lookupMap( role ); } finally { Thread.currentThread().setContextClassLoader( oldClassLoader ); } }
public PluginDescriptor loadPluginDescriptor( Plugin plugin, MavenProject project, MavenSession session ) throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException, InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException, PluginVersionNotFoundException { return verifyPlugin( plugin, project, session.getSettings(), session.getLocalRepository() ); }
@NbBundle.Messages({ "TXT_Artifact_Resolution_problem=Artifact Resolution problem", "TXT_Artifact_Not_Found=Artifact Not Found", "TXT_Cannot_Load_Project=Unable to properly load project", "TXT_Cannot_read_model=Error reading project model", "TXT_NoMsg=Exception thrown while loading maven project at {0}. See messages.log for more information." }) private Collection<ProjectProblem> reportExceptions(MavenExecutionResult res) { List<ProjectProblem> toRet = new ArrayList<ProjectProblem>(); for (Throwable e : res.getExceptions()) { LOG.log(Level.FINE, "Error on loading project " + project.getProjectDirectory(), e); if (e instanceof ArtifactResolutionException) { // XXX when does this occur? toRet.add(ProjectProblem.createError(TXT_Artifact_Resolution_problem(), getDescriptionText(e))); problemReporter.addMissingArtifact(((ArtifactResolutionException) e).getArtifact()); } else if (e instanceof ArtifactNotFoundException) { // XXX when does this occur? toRet.add(ProjectProblem.createError(TXT_Artifact_Not_Found(), getDescriptionText(e))); problemReporter.addMissingArtifact(((ArtifactNotFoundException) e).getArtifact()); } else if (e instanceof ProjectBuildingException) { toRet.add(ProjectProblem.createError(TXT_Cannot_Load_Project(), getDescriptionText(e), new SanityBuildAction(project))); if (e.getCause() instanceof ModelBuildingException) { ModelBuildingException mbe = (ModelBuildingException) e.getCause(); for (ModelProblem mp : mbe.getProblems()) { LOG.log(Level.FINE, mp.toString(), mp.getException()); if (mp.getException() instanceof UnresolvableModelException) { // Probably obsoleted by ProblemReporterImpl.checkParent, but just in case: UnresolvableModelException ume = (UnresolvableModelException) mp.getException(); problemReporter.addMissingArtifact(EmbedderFactory.getProjectEmbedder().createProjectArtifact(ume.getGroupId(), ume.getArtifactId(), ume.getVersion())); } else if (mp.getException() instanceof PluginResolutionException) { Plugin plugin = ((PluginResolutionException) mp.getException()).getPlugin(); // XXX this is not actually accurate; should rather pick out the ArtifactResolutionException & ArtifactNotFoundException inside problemReporter.addMissingArtifact(EmbedderFactory.getProjectEmbedder().createArtifact(plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion(), "jar")); } else if (mp.getException() instanceof PluginManagerException) { PluginManagerException ex = (PluginManagerException) mp.getException(); problemReporter.addMissingArtifact(EmbedderFactory.getProjectEmbedder().createArtifact(ex.getPluginGroupId(), ex.getPluginArtifactId(), ex.getPluginVersion(), "jar")); } } } } else { String msg = e.getMessage(); if(msg != null) { LOG.log(Level.INFO, "Exception thrown while loading maven project at " + project.getProjectDirectory(), e); //NOI18N toRet.add(ProjectProblem.createError(TXT_Cannot_read_model(), msg)); } else { String path = project.getProjectDirectory().getPath(); toRet.add(ProjectProblem.createError(TXT_Cannot_read_model(), TXT_NoMsg(path))); LOG.log(Level.WARNING, "Exception thrown while loading maven project at " + path, e); //NOI18N } } } return toRet; }
MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks ) throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException, PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException;
MavenExecutionPlan calculateExecutionPlan( MavenSession session, boolean setup, String... tasks ) throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException, PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException;
public void executeMojo( MavenProject project, MojoExecution execution, MavenSession session ) throws MojoExecutionException, ArtifactResolutionException, MojoFailureException, ArtifactNotFoundException, InvalidDependencyVersionException, PluginManagerException, PluginConfigurationException { throw new UnsupportedOperationException(); }