Search in sources :

Example 1 with PluginDescriptorParsingException

use of org.apache.maven.plugin.PluginDescriptorParsingException in project tycho by eclipse.

the class PluginRealmHelper method execute.

public void execute(MavenSession session, MavenProject project, Runnable runnable, PluginFilter filter) throws MavenExecutionException {
    for (Plugin plugin : project.getBuildPlugins()) {
        if (plugin.isExtensions()) {
            // https://cwiki.apache.org/MAVEN/maven-3x-class-loading.html
            continue;
        }
        try {
            lifecyclePluginResolver.resolveMissingPluginVersions(project, session);
            PluginDescriptor pluginDescriptor;
            try {
                pluginDescriptor = compatibilityHelper.getPluginDescriptor(plugin, project, session);
            } catch (PluginResolutionException e) {
                // if the plugin really does not exist, the Maven build will fail later on anyway -> ignore for now (cf. bug #432957)
                logger.debug("PluginResolutionException while looking for components from " + plugin, e);
                continue;
            }
            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 = compatibilityHelper.createKey(plugin, project, session);
                    pluginDescriptorCache.put(descriptorCacheKey, null);
                    pluginDescriptor = compatibilityHelper.getPluginDescriptor(plugin, project, session);
                }
                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 (PluginVersionResolutionException e) {
            throw newMavenExecutionException(e);
        } catch (PluginDescriptorParsingException e) {
            throw newMavenExecutionException(e);
        } catch (InvalidPluginDescriptorException e) {
            throw newMavenExecutionException(e);
        }
    }
}
Also used : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) ClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm) PluginVersionResolutionException(org.apache.maven.plugin.version.PluginVersionResolutionException) PluginResolutionException(org.apache.maven.plugin.PluginResolutionException) MavenProject(org.apache.maven.project.MavenProject) InvalidPluginDescriptorException(org.apache.maven.plugin.InvalidPluginDescriptorException) PluginDescriptorParsingException(org.apache.maven.plugin.PluginDescriptorParsingException) PluginManagerException(org.apache.maven.plugin.PluginManagerException) PluginDescriptorCache(org.apache.maven.plugin.PluginDescriptorCache) Plugin(org.apache.maven.model.Plugin)

Aggregations

Plugin (org.apache.maven.model.Plugin)1 InvalidPluginDescriptorException (org.apache.maven.plugin.InvalidPluginDescriptorException)1 PluginDescriptorCache (org.apache.maven.plugin.PluginDescriptorCache)1 PluginDescriptorParsingException (org.apache.maven.plugin.PluginDescriptorParsingException)1 PluginManagerException (org.apache.maven.plugin.PluginManagerException)1 PluginResolutionException (org.apache.maven.plugin.PluginResolutionException)1 PluginDescriptor (org.apache.maven.plugin.descriptor.PluginDescriptor)1 PluginVersionResolutionException (org.apache.maven.plugin.version.PluginVersionResolutionException)1 MavenProject (org.apache.maven.project.MavenProject)1 ClassRealm (org.codehaus.plexus.classworlds.realm.ClassRealm)1