List of usage examples for org.apache.maven.plugin.descriptor PluginDescriptorBuilder build
public PluginDescriptor build(Reader reader) throws PlexusConfigurationException
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. c o 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; }