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

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

Introduction

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

Prototype

public void setArtifacts(List<Artifact> artifacts) 

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();
        }//  w  w w  . j  a v  a  2s .  c  om

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