Example usage for org.apache.maven.plugin.descriptor PluginDescriptor setPluginArtifact

List of usage examples for org.apache.maven.plugin.descriptor PluginDescriptor setPluginArtifact

Introduction

In this page you can find the example usage for org.apache.maven.plugin.descriptor PluginDescriptor setPluginArtifact.

Prototype

public void setPluginArtifact(Artifact pluginArtifact) 

Source Link

Usage

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();
        }//from   w w  w . jav a2  s.com

        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;
}