List of usage examples for org.apache.maven.plugin.descriptor PluginDescriptorBuilder PluginDescriptorBuilder
PluginDescriptorBuilder
From source file:com.puppetlabs.geppetto.forge.maven.plugin.AbstractForgeTestMojo.java
License:Open Source License
protected PluginDescriptor getPluginDescriptor() { if (pluginDescriptor == null) { try {// w w w.java2s. c o m InputStream is = getClass().getResourceAsStream("/META-INF/maven/plugin.xml"); try { XmlStreamReader reader = ReaderFactory.newXmlReader(is); InterpolationFilterReader interpolationFilterReader = new InterpolationFilterReader( new BufferedReader(reader), container.getContext().getContextData()); PlexusContainer pc = getContainer(); pluginDescriptor = new PluginDescriptorBuilder().build(interpolationFilterReader); Artifact artifact = pc.lookup(RepositorySystem.class).createArtifact( pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId(), pluginDescriptor.getVersion(), ".jar"); artifact.setFile(getBasedir()); pluginDescriptor.setClassRealm(pc.getContainerRealm()); pluginDescriptor.setPluginArtifact(artifact); pluginDescriptor.setArtifacts(Arrays.asList(artifact)); for (ComponentDescriptor<?> desc : pluginDescriptor.getComponents()) pc.addComponentDescriptor(desc); } finally { is.close(); } } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } } return pluginDescriptor; }
From source file:io.takari.maven.testing.Maven30xRuntime.java
License:Open Source License
private Map<String, MojoDescriptor> readPluginXml(DefaultPlexusContainer container) throws Exception { Map<String, MojoDescriptor> mojoDescriptors = new HashMap<String, MojoDescriptor>(); Enumeration<URL> resources = getClass().getClassLoader().getResources(PATH_PLUGINXML); while (resources.hasMoreElements()) { InputStream is = resources.nextElement().openStream(); if (is == null) { return Collections.emptyMap(); }/* www . j a va 2s .c o m*/ XmlStreamReader reader = new XmlStreamReader(is); @SuppressWarnings("rawtypes") Map contextData = container.getContext().getContextData(); @SuppressWarnings("unchecked") InterpolationFilterReader interpolationFilterReader = new InterpolationFilterReader( new BufferedReader(reader), contextData); PluginDescriptor pluginDescriptor = new PluginDescriptorBuilder().build(interpolationFilterReader); Artifact artifact = container.lookup(RepositorySystem.class) // .createArtifact(pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId(), pluginDescriptor.getVersion(), ".jar"); artifact.setFile(getPluginArtifactFile()); pluginDescriptor.setPluginArtifact(artifact); pluginDescriptor.setArtifacts(Arrays.asList(artifact)); for (ComponentDescriptor<?> desc : pluginDescriptor.getComponents()) { container.addComponentDescriptor(desc); } for (MojoDescriptor mojoDescriptor : pluginDescriptor.getMojos()) { // TODO decide how to handle duplicate goals // this is possible when one plugin extends another // for example, Tycho 'compile' goal is an extension of standard maven 'compile' mojoDescriptors.put(mojoDescriptor.getGoal(), mojoDescriptor); } } return mojoDescriptors; }
From source file:org.eclipse.m2e.editor.xml.PomTemplateContextUtil.java
License:Open Source License
public PluginDescriptor getPluginDescriptor(String groupId, String artifactId, String version) { String name = groupId + ":" + artifactId + ":" + version; PluginDescriptor descriptor = descriptors.get(name); if (descriptor != null) { return descriptor; }/*from w w w . ja va 2s .co m*/ try { IMaven embedder = MavenPlugin.getMaven(); List<ArtifactRepository> repositories = embedder.getArtifactRepositories(); Artifact artifact = embedder.resolve(groupId, artifactId, version, "maven-plugin", null, repositories, //$NON-NLS-1$ null); File file = artifact.getFile(); if (file == null) { String msg = "Can't resolve plugin " + name; //$NON-NLS-1$ log.error(msg); } else { InputStream is = null; ZipFile zf = null; try { zf = new ZipFile(file); ZipEntry entry = zf.getEntry("META-INF/maven/plugin.xml"); //$NON-NLS-1$ if (entry != null) { is = zf.getInputStream(entry); PluginDescriptorBuilder builder = new PluginDescriptorBuilder(); descriptor = builder.build(new InputStreamReader(is)); descriptors.put(name, descriptor); return descriptor; } } catch (Exception ex) { String msg = "Can't read configuration for " + name; //$NON-NLS-1$ log.error(msg, ex); } finally { IOUtil.close(is); try { zf.close(); } catch (IOException ex) { // ignore } } } } catch (CoreException ex) { IStatus status = ex.getStatus(); String msg = status.getMessage(); if (status.getException() != null) { msg += "; " + status.getException().getMessage(); } log.error(msg, ex); } return null; }
From source file:org.nuxeo.build.maven.MavenEmbedder.java
License:Open Source License
public void start() throws MavenEmbedderException { detectUserInstallation();//from w ww .ja va 2 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); } }