List of usage examples for org.apache.maven.lifecycle LifecycleExecutor ROLE
String ROLE
To view the source code for org.apache.maven.lifecycle LifecycleExecutor ROLE.
Click Source Link
From source file:com.cedarsoft.fish.maven.HelpUtil.java
License:Apache License
/** * Invoke the following private method <code> * DefaultLifecycleExecutor#getMojoDescriptor(String, MavenSession, MavenProject, String, boolean, boolean)</code> * * @param task not null//from www . ja v a2s. com * @param session not null * @param project not null * @param invokedVia not null * @param canUsePrefix not null * @param isOptionalMojo not null * @return MojoDescriptor for the task * @throws MojoFailureException if can not invoke the method. * @throws MojoExecutionException if no descriptor was found for <code>task</code>. * @see DefaultLifecycleExecutor#getMojoDescriptor(String, MavenSession, MavenProject, String, boolean, boolean) */ protected static MojoDescriptor getMojoDescriptor(String task, MavenSession session, MavenProject project, String invokedVia, boolean canUsePrefix, boolean isOptionalMojo) throws MojoFailureException, MojoExecutionException { try { DefaultLifecycleExecutor lifecycleExecutor = (DefaultLifecycleExecutor) session .lookup(LifecycleExecutor.ROLE); Method m = lifecycleExecutor.getClass().getDeclaredMethod("getMojoDescriptor", new Class[] { String.class, MavenSession.class, MavenProject.class, String.class, Boolean.TYPE, Boolean.TYPE }); m.setAccessible(true); MojoDescriptor mojoDescriptor = (MojoDescriptor) m.invoke(lifecycleExecutor, new Object[] { task, session, project, invokedVia, Boolean.valueOf(canUsePrefix), Boolean.valueOf(isOptionalMojo) }); if (mojoDescriptor == null) { throw new MojoExecutionException("No MOJO exists for '" + task + "'."); } return mojoDescriptor; } catch (SecurityException e) { throw new MojoFailureException("SecurityException: " + e.getMessage()); } catch (IllegalArgumentException e) { throw new MojoFailureException("IllegalArgumentException: " + e.getMessage()); } catch (ComponentLookupException e) { throw new MojoFailureException("ComponentLookupException: " + e.getMessage()); } catch (NoSuchMethodException e) { throw new MojoFailureException("NoSuchMethodException: " + e.getMessage()); } catch (IllegalAccessException e) { throw new MojoFailureException("IllegalAccessException: " + e.getMessage()); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); if (cause instanceof BuildFailureException) { throw new MojoFailureException("BuildFailureException: " + cause.getMessage()); } else if (cause instanceof LifecycleExecutionException) { throw new MojoFailureException("LifecycleExecutionException: " + cause.getMessage()); } else if (cause instanceof PluginNotFoundException) { throw new MojoFailureException("PluginNotFoundException: " + cause.getMessage()); } StringWriter s = new StringWriter(); PrintWriter writer = new PrintWriter(s); e.printStackTrace(writer); throw new MojoFailureException("InvocationTargetException: " + e.getMessage() + "\n" + s.toString()); } }
From source file:org.nuxeo.build.maven.MavenEmbedder.java
License:Open Source License
public List<String> getLifecyclePhases() throws MavenEmbedderException { List<String> phases = new ArrayList<String>(); ComponentDescriptor descriptor = embedder.getContainer().getComponentDescriptor(LifecycleExecutor.ROLE); PlexusConfiguration configuration = descriptor.getConfiguration(); PlexusConfiguration[] phasesConfigurations = configuration.getChild("lifecycles").getChild(0) .getChild("phases").getChildren("phase"); try {/*from w ww. j a v a 2s . c o m*/ for (int i = 0; i < phasesConfigurations.length; i++) { phases.add(phasesConfigurations[i].getValue()); } } catch (PlexusConfigurationException e) { throw new MavenEmbedderException("Cannot retrieve default lifecycle phasesConfigurations.", e); } return phases; }
From source file:org.nuxeo.build.maven.MavenEmbedder.java
License:Open Source License
public void start() throws MavenEmbedderException { detectUserInstallation();//from w w w.j av a2 s .c o m // ---------------------------------------------------------------------- // Set the maven.home system property which is need by components like // the plugin registry builder. // ---------------------------------------------------------------------- if (classLoader == null) { throw new IllegalStateException("A classloader must be specified using setClassLoader(ClassLoader)."); } embedder = new Embedder(); if (logger != null) { embedder.setLoggerManager(new MavenEmbedderLoggerManager(new PlexusLoggerAdapter(logger))); } try { ClassWorld classWorld = new ClassWorld(); classWorld.newRealm("plexus.core", classLoader); embedder.start(classWorld); // ---------------------------------------------------------------------- // Lookup each of the components we need to provide the desired // client interface. // ---------------------------------------------------------------------- modelReader = new MavenXpp3Reader(); modelWriter = new MavenXpp3Writer(); pluginDescriptorBuilder = new PluginDescriptorBuilder(); profileManager = new DefaultProfileManager(embedder.getContainer(), (Properties) null); mavenProjectBuilder = (MavenProjectBuilder) embedder.lookup(MavenProjectBuilder.ROLE); // ---------------------------------------------------------------------- // Artifact related components // ---------------------------------------------------------------------- artifactRepositoryFactory = (ArtifactRepositoryFactory) embedder.lookup(ArtifactRepositoryFactory.ROLE); artifactFactory = (ArtifactFactory) embedder.lookup(ArtifactFactory.ROLE); artifactResolver = (ArtifactResolver) embedder.lookup(ArtifactResolver.ROLE); artifactMetadataSource = (ArtifactMetadataSource) embedder.lookup(ArtifactMetadataSource.ROLE); defaultArtifactRepositoryLayout = (ArtifactRepositoryLayout) embedder .lookup(ArtifactRepositoryLayout.ROLE, DEFAULT_LAYOUT_ID); lifecycleExecutor = (LifecycleExecutor) embedder.lookup(LifecycleExecutor.ROLE); wagonManager = (WagonManager) embedder.lookup(WagonManager.ROLE); createMavenSettings(); profileManager.loadSettingsProfiles(settings); localRepository = createLocalRepository(); } catch (PlexusContainerException e) { throw new MavenEmbedderException("Cannot start Plexus embedder.", e); } catch (DuplicateRealmException e) { throw new MavenEmbedderException("Cannot create Classworld realm for the embedder.", e); } catch (ComponentLookupException e) { throw new MavenEmbedderException("Cannot lookup required component.", e); } }