public static Collection<MojoDescriptor> readMojos(InputStream is) throws IOException, XmlPullParserException { Reader reader = ReaderFactory.newXmlReader(is); org.apache.maven.plugin.descriptor.PluginDescriptor pluginDescriptor; try { pluginDescriptor = new PluginDescriptorBuilder().build(reader); } catch (PlexusConfigurationException e) { Throwables.propagateIfPossible(e.getCause(), IOException.class, XmlPullParserException.class); throw Throwables.propagate(e); } List<MojoDescriptor> result = new ArrayList<>(); for (org.apache.maven.plugin.descriptor.MojoDescriptor mojo : pluginDescriptor.getMojos()) { result.add(toMojoDescriptor(mojo)); } return result; }
public PluginDescriptor getPluginDescriptor(File file) throws IOException, PlexusConfigurationException { PluginDescriptor descriptor = null; if (file.exists()) { JarFile jarFile = new JarFile(file); ZipEntry entry = jarFile.getEntry("META-INF/maven/plugin.xml"); InputStream plugin = jarFile.getInputStream(entry); BufferedReader in = new BufferedReader(new InputStreamReader(plugin)); descriptor = new PluginDescriptorBuilder().build(in); } return descriptor; }