Example usage for org.apache.maven.project MavenProject getBuildPlugins

List of usage examples for org.apache.maven.project MavenProject getBuildPlugins

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getBuildPlugins.

Prototype

public List<Plugin> getBuildPlugins() 

Source Link

Usage

From source file:org.codehaus.mojo.versions.DisplayPluginUpdatesMojo.java

License:Apache License

/**
 * Gets the all plugins./*  w ww  .jav  a 2 s .c  o  m*/
 *
 * @param project   the project
 * @param lifecycle the lifecycle
 * @return the all plugins
 * @throws PluginNotFoundException     the plugin not found exception
 * @throws LifecycleExecutionException the lifecycle execution exception
 */
private Set<Plugin> getAllPlugins(MavenProject project, Lifecycle lifecycle)
        throws PluginNotFoundException, LifecycleExecutionException

{
    Set<Plugin> plugins = new HashSet<Plugin>();
    // first, bind those associated with the packaging
    Map mappings = findMappingsForLifecycle(project, lifecycle);

    Iterator iter = mappings.entrySet().iterator();
    while (iter.hasNext()) {
        Map.Entry entry = (Map.Entry) iter.next();
        String value = (String) entry.getValue();
        String[] tokens = value.split(":");

        Plugin plugin = new Plugin();
        plugin.setGroupId(tokens[0]);
        plugin.setArtifactId(tokens[1]);
        plugins.add(plugin);
    }

    for (String value : findOptionalMojosForLifecycle(project, lifecycle)) {
        String[] tokens = value.split(":");

        Plugin plugin = new Plugin();
        plugin.setGroupId(tokens[0]);
        plugin.setArtifactId(tokens[1]);
        plugins.add(plugin);
    }

    plugins.addAll((List<Plugin>) project.getBuildPlugins());

    return plugins;
}

From source file:org.codehaus.mojo.versions.DisplayPluginUpdatesMojo.java

License:Apache License

/**
 * Find extension./*from w  w  w  .ja va2s .c om*/
 *
 * @param project         the project
 * @param role            the role
 * @param roleHint        the role hint
 * @param settings        the settings
 * @param localRepository the local repository
 * @return the object
 * @throws LifecycleExecutionException the lifecycle execution exception
 * @throws PluginNotFoundException     the plugin not found exception
 */
private Object findExtension(MavenProject project, String role, String roleHint, Settings settings,
        ArtifactRepository localRepository) throws LifecycleExecutionException, PluginNotFoundException {
    Object pluginComponent = null;

    for (Iterator i = project.getBuildPlugins().iterator(); i.hasNext() && pluginComponent == null;) {
        Plugin plugin = (Plugin) i.next();

        if (plugin.isExtensions()) {
            loadPluginDescriptor(plugin, project, session);

            // TODO: if moved to the plugin manager we
            // already have the descriptor from above
            // and so do can lookup the container
            // directly
            try {
                pluginComponent = pluginManager.getPluginComponent(plugin, role, roleHint);
            } catch (ComponentLookupException e) {
                getLog().debug("Unable to find the lifecycle component in the extension", e);
            } catch (PluginManagerException e) {
                throw new LifecycleExecutionException(
                        "Error getting extensions from the plugin '" + plugin.getKey() + "': " + e.getMessage(),
                        e);
            }
        }
    }
    return pluginComponent;
}

From source file:org.debian.dependency.DefaultDependencyCollection.java

License:Apache License

private void visitPluginDependencies(final DependencyNodeVisitor visitor, final MavenProject project,
        final ArtifactFilter filter, final MavenSession session)
        throws DependencyResolutionException, DependencyGraphBuilderException {
    for (Plugin plugin : project.getBuildPlugins()) {
        if (filter == null || filter.include(repositorySystem.createPluginArtifact(plugin))) {
            DependencyNode pluginDependencies = resolveProjectDependencies(plugin.getGroupId(),
                    plugin.getArtifactId(), plugin.getVersion(), filter, session);
            pluginDependencies.accept(visitor);
        }//  www  .  j  a v a2s  .  c  o m

        for (Dependency dep : plugin.getDependencies()) {
            if (filter != null && !filter.include(repositorySystem.createDependencyArtifact(dep))) {
                continue;
            }

            MavenProject depProject = buildProject(dep.getGroupId(), dep.getArtifactId(), dep.getVersion(),
                    session);
            List<String> exclusions = new ArrayList<String>(dep.getExclusions().size());
            for (Exclusion exclusion : dep.getExclusions()) {
                exclusions.add(exclusion.getGroupId() + ":" + exclusion.getArtifactId());
            }

            AndArtifactFilter depFilter = new AndArtifactFilter();
            depFilter.add(new ExcludesArtifactFilter(exclusions));
            depFilter.add(filter);

            DependencyNode dependencies = dependencyGraphBuilder.buildDependencyGraph(depProject, depFilter);
            dependencies.accept(visitor);
        }
    }
}

From source file:org.ebayopensource.turmeric.eclipse.maven.sconfig.TurmerStandardProjectConfigurator.java

License:Open Source License

private boolean isProjectType(String goalType, ProjectConfigurationRequest projRequest) {
    MavenProject mproj = projRequest.getMavenProject();
    List<Plugin> buildPlugins = mproj.getBuildPlugins();
    for (Plugin mplug : buildPlugins) {
        if (TURMERIC_MAVEN_PLUGIN.equals(mplug.getArtifactId())) {
            List<PluginExecution> exList = mplug.getExecutions();

            for (PluginExecution pexec : exList) {
                List<String> goals = pexec.getGoals();
                for (String goal : goals) {
                    if (goalType.equals(goal)) {
                        return true;
                    }//from  www  .j a v  a 2  s. c o m
                }
            }
        }
    }
    return false;
}

From source file:org.eclipse.m2e.core.internal.project.registry.DefaultMavenDependencyResolver.java

License:Open Source License

@Override
public void resolveProjectDependencies(final IMavenProjectFacade facade, Set<Capability> capabilities,
        Set<RequiredCapability> requirements, final IProgressMonitor monitor) throws CoreException {
    long start = System.currentTimeMillis();
    log.debug("Resolving dependencies for {}", facade.toString()); //$NON-NLS-1$

    markerManager.deleteMarkers(facade.getPom(), IMavenConstants.MARKER_DEPENDENCY_ID);

    ProjectBuildingRequest configuration = getMaven().getExecutionContext().newProjectBuildingRequest();
    configuration.setProject(facade.getMavenProject()); // TODO do we need this?
    configuration.setResolveDependencies(true);
    MavenExecutionResult mavenResult = getMaven().readMavenProject(facade.getPomFile(), configuration);

    markerManager.addMarkers(facade.getPom(), IMavenConstants.MARKER_DEPENDENCY_ID, mavenResult);

    if (!facade.getResolverConfiguration().shouldResolveWorkspaceProjects()) {
        return;/*from  w  w  w  . j a v  a  2  s .  c om*/
    }

    MavenProject mavenProject = facade.getMavenProject();

    // dependencies

    // resolved dependencies
    for (Artifact artifact : mavenProject.getArtifacts()) {
        requirements.add(MavenRequiredCapability.createMavenArtifact(new ArtifactKey(artifact),
                artifact.getScope(), artifact.isOptional()));
    }

    // extension plugins (affect packaging type calculation)
    for (Plugin plugin : mavenProject.getBuildPlugins()) {
        if (plugin.isExtensions()) {
            ArtifactKey artifactKey = new ArtifactKey(plugin.getGroupId(), plugin.getArtifactId(),
                    plugin.getVersion(), null);
            requirements.add(MavenRequiredCapability.createMavenArtifact(artifactKey, "plugin", false)); //$NON-NLS-1$
        }
    }

    // missing dependencies
    DependencyResolutionResult resolutionResult = mavenResult.getDependencyResolutionResult();
    if (resolutionResult != null && resolutionResult.getUnresolvedDependencies() != null) {
        for (Dependency dependency : resolutionResult.getUnresolvedDependencies()) {
            org.sonatype.aether.artifact.Artifact artifact = dependency.getArtifact();
            ArtifactKey dependencyKey = new ArtifactKey(artifact.getGroupId(), artifact.getArtifactId(),
                    artifact.getVersion(), null);
            requirements.add(MavenRequiredCapability.createMavenArtifact(dependencyKey, dependency.getScope(),
                    dependency.isOptional()));
        }
    }

    log.debug("Resolved dependencies for {} in {} ms", facade.toString(), System.currentTimeMillis() - start); //$NON-NLS-1$
}

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;
        }//  ww w.  jav a2s .co  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.facade.P2TargetPlatformResolver.java

License:Open Source License

private static boolean hasSourceBundle(MavenProject project) {
    // TODO this is a fragile way of checking whether we generate a source bundle
    // should we rather use MavenSession to get the actual configured mojo instance?
    for (Plugin plugin : project.getBuildPlugins()) {
        if ("org.eclipse.tycho:tycho-source-plugin".equals(plugin.getKey())) {
            return true;
        }//  w ww  .  j a  v a 2s .c o m
    }
    return false;
}

From source file:org.gephi.maven.MetadataUtils.java

License:Apache License

/**
 * Lookup and return the NBM plugin for this plugin.
 *
 * @param project project/*from  w  ww.  j a va  2  s.  c  om*/
 * @return NBM plugin
 */
protected static Plugin lookupNbmPlugin(MavenProject project) {
    List plugins = project.getBuildPlugins();

    for (Iterator iterator = plugins.iterator(); iterator.hasNext();) {
        Plugin plugin = (Plugin) iterator.next();
        if ("org.codehaus.mojo:nbm-maven-plugin".equalsIgnoreCase(plugin.getKey())) {
            return plugin;
        }
    }
    return null;
}

From source file:org.guvnor.ala.build.maven.executor.MavenProjectConfigExecutor.java

License:Apache License

private Collection<PlugIn> extractPlugins(final MavenProject project) {
    final Collection<PlugIn> result = new ArrayList<>(project.getBuildPlugins().size());
    for (org.apache.maven.model.Plugin plugin : project.getBuildPlugins()) {
        final Map<String, Object> config = extractConfig(plugin.getConfiguration());
        result.add(new PlugIn() {
            @Override//  w  ww . j av  a 2  s .co  m
            public String getId() {
                return plugin.getKey();
            }

            @Override
            public Map<String, ?> getConfiguration() {
                return config;
            }
        });
    }
    return result;
}

From source file:org.jamon.eclipse.maven.configurator.JamonProjectConfigurator.java

License:Mozilla Public License

/**
 * Gets the Jamon plugin from pom.xml. Returns null if it is not found.
 *
 * @param project//from  ww w  .  j a v a2s  .  c  o m
 * @return
 */
private static Plugin getJamonPlugin(MavenProject project) {
    for (Plugin plugin : project.getBuildPlugins()) {
        if (isJamonArtifact(plugin)) {
            return plugin;
        }
    }
    return null;
}