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

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

Introduction

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

Prototype

public Map<String, Artifact> getArtifactMap() 

Source Link

Document

The map of artifacts accessible by the versionlessKey, i.e.

Usage

From source file:com.github.shyiko.jwarpack.maven.PackMojo.java

License:Apache License

private File getESJar() throws MojoExecutionException {
    if (serverLauncherJar != null) {
        return serverLauncherJar;
    }/*from   w  ww  .  ja  v  a 2s.  co m*/
    String key = null;
    PluginDescriptor pluginDescriptor = getPluginDescriptor();
    Plugin plugin = findPlugin(pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId());
    for (Object o : plugin.getDependencies()) {
        Dependency dependency = (Dependency) o;
        String groupId = dependency.getGroupId();
        String artifactId = dependency.getArtifactId();
        if (groupId.startsWith(ES_GROUP_PREFIX) && artifactId.startsWith(ES_ARTIFACT_PREFIX)) {
            if (key != null) {
                throw new MojoExecutionException("Multiple " + ES_ARTIFACT_PREFIX + " artifacts found. "
                        + "Please check <plugin><dependencies>...</dependencies></plugin>.");
            }
            key = groupId + ":" + artifactId;
        }
    }
    if (key == null) {
        throw new MojoExecutionException("No " + ES_ARTIFACT_PREFIX + " artifacts found. "
                + "Please add one inside <plugin><dependencies>...</dependencies></plugin>.");
    }
    Artifact artifact = (Artifact) pluginDescriptor.getArtifactMap().get(key);
    return artifact.getFile();
}

From source file:com.github.shyiko.jwarpack.maven.PackMojo.java

License:Apache License

private File getAppWar() throws MojoExecutionException {
    if (applicationWar != null) {
        return applicationWar;
    }//from   ww w. java  2  s.  com
    String key = null;
    PluginDescriptor pluginDescriptor = getPluginDescriptor();
    Plugin plugin = findPlugin(pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId());
    for (Object o : plugin.getDependencies()) {
        Dependency dependency = (Dependency) o;
        if ("war".equals(dependency.getType())) {
            if (key != null) {
                throw new MojoExecutionException("Multiple WAR artifacts found. "
                        + "Please check <plugin><dependencies>...</dependencies></plugin>.");
            }
            key = dependency.getGroupId() + ":" + dependency.getArtifactId();
        }
    }
    if (key == null) {
        throw new MojoExecutionException("No artifacts with <type>war</type> found. "
                + "Please add one inside <plugin><dependencies>...</dependencies></plugin>.");
    }
    Artifact artifact = (Artifact) pluginDescriptor.getArtifactMap().get(key);
    return artifact.getFile();
}

From source file:org.eclipse.tycho.core.maven.utils.PluginRealmHelper.java

License:Open Source License

public void execute(MavenSession session, MavenProject project, Runnable runnable, PluginFilter filter)
        throws MavenExecutionException {
    for (Plugin plugin : project.getBuildPlugins()) {
        if (plugin.isExtensions()) {
            // due to maven classloading model limitations, build extensions plugins cannot share classes
            // since tycho core, i.e. this code, is loaded as a build extension, no other extensions plugin
            // can load classes from tycho core
            // https://cwiki.apache.org/MAVEN/maven-3x-class-loading.html
            continue;
        }// w  ww  . j a va  2s .c  o m
        try {
            PluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptor(plugin,
                    project.getRemotePluginRepositories(), session.getRepositorySession());

            if (pluginDescriptor != null) {
                if (pluginDescriptor.getArtifactMap().isEmpty()
                        && pluginDescriptor.getDependencies().isEmpty()) {
                    // force plugin descriptor reload to workaround http://jira.codehaus.org/browse/MNG-5212
                    // this branch won't be executed on 3.0.5+, where MNG-5212 is fixed already
                    PluginDescriptorCache.Key descriptorCacheKey = pluginDescriptorCache.createKey(plugin,
                            project.getRemotePluginRepositories(), session.getRepositorySession());
                    pluginDescriptorCache.put(descriptorCacheKey, null);
                    pluginDescriptor = pluginManager.getPluginDescriptor(plugin,
                            project.getRemotePluginRepositories(), session.getRepositorySession());
                }

                if (filter == null || filter.accept(pluginDescriptor)) {
                    ClassRealm pluginRealm;
                    MavenProject oldCurrentProject = session.getCurrentProject();
                    session.setCurrentProject(project);
                    try {
                        pluginRealm = buildPluginManager.getPluginRealm(session, pluginDescriptor);
                    } finally {
                        session.setCurrentProject(oldCurrentProject);
                    }
                    if (pluginRealm != null) {
                        ClassLoader origTCCL = Thread.currentThread().getContextClassLoader();
                        try {
                            Thread.currentThread().setContextClassLoader(pluginRealm);
                            runnable.run();
                        } finally {
                            Thread.currentThread().setContextClassLoader(origTCCL);
                        }
                    }
                }
            }
        } catch (PluginManagerException e) {
            throw newMavenExecutionException(e);
        } catch (PluginResolutionException e) {
            throw newMavenExecutionException(e);
        } catch (PluginDescriptorParsingException e) {
            throw newMavenExecutionException(e);
        } catch (InvalidPluginDescriptorException e) {
            throw newMavenExecutionException(e);
        }
    }

}

From source file:org.eclipse.tycho.p2.resolver.P2DependencyResolver.java

License:Open Source License

protected boolean isTychoP2Plugin(PluginDescriptor pluginDescriptor) {
    if (pluginDescriptor.getArtifactMap().containsKey("org.eclipse.tycho:tycho-p2-facade")) {
        return true;
    }//from  w  ww . ja v a  2 s. c o m
    for (ComponentDependency dependency : pluginDescriptor.getDependencies()) {
        if ("org.eclipse.tycho".equals(dependency.getGroupId())
                && "tycho-p2-facade".equals(dependency.getArtifactId())) {
            return true;
        }
    }
    return false;
}