Search in sources :

Example 26 with Plugin

use of org.apache.maven.model.Plugin in project tycho by eclipse.

the class TychoMavenLifecycleParticipantTest method addTychoPlugin.

private void addTychoPlugin(MavenProject project, String artifactId, String version) {
    Plugin plugin = new Plugin();
    plugin.setGroupId("org.eclipse.tycho");
    plugin.setArtifactId(artifactId);
    plugin.setVersion(version);
    project.getBuild().addPlugin(plugin);
}
Also used : Plugin(org.apache.maven.model.Plugin)

Example 27 with Plugin

use of org.apache.maven.model.Plugin in project tycho by eclipse.

the class OsgiSourceMojo method isRelevantProjectImpl.

protected static boolean isRelevantProjectImpl(MavenProject project, BuildPropertiesParser buildPropertiesParser) {
    String packaging = project.getPackaging();
    boolean relevant = PackagingType.TYPE_ECLIPSE_PLUGIN.equals(packaging) || PackagingType.TYPE_ECLIPSE_TEST_PLUGIN.equals(packaging);
    if (!relevant) {
        return false;
    }
    // this assumes that sources generation has to be explicitly enabled in pom.xml
    Plugin plugin = project.getPlugin("org.eclipse.tycho:tycho-source-plugin");
    if (plugin == null) {
        return false;
    }
    for (PluginExecution execution : plugin.getExecutions()) {
        if (execution.getGoals().contains(GOAL)) {
            boolean requireSourceRoots = Boolean.parseBoolean(getParameterValue(execution, "requireSourceRoots", "false"));
            if (requireSourceRoots) {
                return true;
            }
            boolean hasAdditionalFilesets = getConfigurationElement((Xpp3Dom) execution.getConfiguration(), "additionalFileSets") != null;
            if (hasAdditionalFilesets) {
                return true;
            }
            BuildProperties buildProperties = buildPropertiesParser.parse(project.getBasedir());
            if (buildProperties.getJarToSourceFolderMap().size() > 0 || buildProperties.getSourceIncludes().size() > 0) {
                return true;
            }
        }
    }
    return false;
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) BuildProperties(org.eclipse.tycho.core.shared.BuildProperties) Plugin(org.apache.maven.model.Plugin)

Example 28 with Plugin

use of org.apache.maven.model.Plugin in project tycho by eclipse.

the class OsgiSourceMojoTest method createStubProject.

private MavenProject createStubProject(String packaging, String testResourceFolder, boolean enableSourePlugin, boolean requireSourceRoots) {
    MavenProject stubProject = new MavenProject();
    stubProject.setPackaging(packaging);
    if (enableSourePlugin) {
        Build build = new Build();
        stubProject.setBuild(build);
        Plugin tychoSourcePlugin = new Plugin();
        tychoSourcePlugin.setGroupId("org.eclipse.tycho");
        tychoSourcePlugin.setArtifactId("tycho-source-plugin");
        PluginExecution execution = new PluginExecution();
        execution.setGoals(asList("plugin-source"));
        if (requireSourceRoots) {
            Xpp3Dom config = new Xpp3Dom("configuration");
            Xpp3Dom requireSourceRootsDom = new Xpp3Dom("requireSourceRoots");
            requireSourceRootsDom.setValue("true");
            config.addChild(requireSourceRootsDom);
            execution.setConfiguration(config);
        }
        tychoSourcePlugin.setExecutions(asList(execution));
        build.setPlugins(asList(tychoSourcePlugin));
    }
    stubProject.setFile(new File("src/test/resources/sourceMojo/" + testResourceFolder + "/pom.xml"));
    return stubProject;
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) MavenProject(org.apache.maven.project.MavenProject) Build(org.apache.maven.model.Build) File(java.io.File) Plugin(org.apache.maven.model.Plugin)

Example 29 with Plugin

use of org.apache.maven.model.Plugin in project mule by mulesoft.

the class DeployableMavenClassLoaderModelLoader method exportSharedLibrariesResourcesAndPackages.

private void exportSharedLibrariesResourcesAndPackages(File applicationFolder, ClassLoaderModelBuilder classLoaderModelBuilder, Set<BundleDependency> dependencies) {
    Model model = loadPomModel(applicationFolder);
    Build build = model.getBuild();
    if (build != null) {
        List<Plugin> plugins = build.getPlugins();
        if (plugins != null) {
            Optional<Plugin> packagingPluginOptional = plugins.stream().filter(plugin -> plugin.getArtifactId().equals(MULE_MAVEN_PLUGIN_ARTIFACT_ID) && plugin.getGroupId().equals(MULE_MAVEN_PLUGIN_GROUP_ID)).findFirst();
            packagingPluginOptional.ifPresent(packagingPlugin -> {
                Object configuration = packagingPlugin.getConfiguration();
                if (configuration != null) {
                    Xpp3Dom sharedLibrariesDom = ((Xpp3Dom) configuration).getChild("sharedLibraries");
                    if (sharedLibrariesDom != null) {
                        Xpp3Dom[] sharedLibraries = sharedLibrariesDom.getChildren("sharedLibrary");
                        if (sharedLibraries != null) {
                            FileJarExplorer fileJarExplorer = new FileJarExplorer();
                            for (Xpp3Dom sharedLibrary : sharedLibraries) {
                                String groupId = getSharedLibraryAttribute(applicationFolder, sharedLibrary, "groupId");
                                String artifactId = getSharedLibraryAttribute(applicationFolder, sharedLibrary, "artifactId");
                                Optional<BundleDependency> bundleDependencyOptional = dependencies.stream().filter(bundleDependency -> bundleDependency.getDescriptor().getArtifactId().equals(artifactId) && bundleDependency.getDescriptor().getGroupId().equals(groupId)).findFirst();
                                bundleDependencyOptional.map(bundleDependency -> {
                                    JarInfo jarInfo = fileJarExplorer.explore(bundleDependency.getBundleUri());
                                    classLoaderModelBuilder.exportingPackages(jarInfo.getPackages());
                                    classLoaderModelBuilder.exportingResources(jarInfo.getResources());
                                    return bundleDependency;
                                }).orElseThrow(() -> new MuleRuntimeException(I18nMessageFactory.createStaticMessage(format("Dependency %s:%s could not be found within the artifact %s. It must be declared within the maven dependencies of the artifact.", groupId, artifactId, applicationFolder.getName()))));
                            }
                        }
                    }
                }
            });
        }
    }
}
Also used : FileJarExplorer(org.mule.runtime.module.artifact.internal.util.FileJarExplorer) LoggerFactory(org.slf4j.LoggerFactory) BundleDescriptor(org.mule.runtime.module.artifact.api.descriptor.BundleDescriptor) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Build(org.apache.maven.model.Build) MULE_MAVEN_PLUGIN_ARTIFACT_ID(org.mule.runtime.module.artifact.api.classloader.MuleMavenPlugin.MULE_MAVEN_PLUGIN_ARTIFACT_ID) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) Map(java.util.Map) Preconditions.checkState(org.mule.runtime.api.util.Preconditions.checkState) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) DOMAIN(org.mule.runtime.core.api.config.bootstrap.ArtifactType.DOMAIN) POLICY(org.mule.runtime.core.api.config.bootstrap.ArtifactType.POLICY) MULE_LOADER_ID(org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.MULE_LOADER_ID) MavenClient(org.mule.maven.client.api.MavenClient) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) INCLUDE_TEST_DEPENDENCIES(org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.INCLUDE_TEST_DEPENDENCIES) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) AbstractMavenClassLoaderModelLoader(org.mule.runtime.module.deployment.impl.internal.maven.AbstractMavenClassLoaderModelLoader) Set(java.util.Set) LocalRepositorySupplierFactory(org.mule.maven.client.api.LocalRepositorySupplierFactory) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) String.format(java.lang.String.format) File(java.io.File) I18nMessageFactory(org.mule.runtime.api.i18n.I18nMessageFactory) ArtifactType(org.mule.runtime.core.api.config.bootstrap.ArtifactType) List(java.util.List) Plugin(org.apache.maven.model.Plugin) APP(org.mule.runtime.core.api.config.bootstrap.ArtifactType.APP) MULE_MAVEN_PLUGIN_GROUP_ID(org.mule.runtime.module.artifact.api.classloader.MuleMavenPlugin.MULE_MAVEN_PLUGIN_GROUP_ID) MavenUtils.getPomModelFolder(org.mule.runtime.module.deployment.impl.internal.maven.MavenUtils.getPomModelFolder) Optional(java.util.Optional) ClassLoaderModelBuilder(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel.ClassLoaderModelBuilder) JarInfo(org.mule.runtime.module.artifact.internal.util.JarInfo) Model(org.apache.maven.model.Model) FileJarExplorer(org.mule.runtime.module.artifact.internal.util.FileJarExplorer) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) JarInfo(org.mule.runtime.module.artifact.internal.util.JarInfo) Build(org.apache.maven.model.Build) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) Model(org.apache.maven.model.Model) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Plugin(org.apache.maven.model.Plugin)

Example 30 with Plugin

use of org.apache.maven.model.Plugin 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)140 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)39 MavenProject (org.apache.maven.project.MavenProject)26 Build (org.apache.maven.model.Build)22 PluginExecution (org.apache.maven.model.PluginExecution)22 ArrayList (java.util.ArrayList)20 Dependency (org.apache.maven.model.Dependency)17 File (java.io.File)15 Model (org.apache.maven.model.Model)15 HashMap (java.util.HashMap)12 PluginDescriptor (org.apache.maven.plugin.descriptor.PluginDescriptor)12 CoreException (org.eclipse.core.runtime.CoreException)11 IOException (java.io.IOException)9 List (java.util.List)8 PluginManagement (org.apache.maven.model.PluginManagement)8 Map (java.util.Map)7 MavenSession (org.apache.maven.execution.MavenSession)7 ReportPlugin (org.apache.maven.model.ReportPlugin)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6