Search in sources :

Example 91 with Plugin

use of org.apache.maven.model.Plugin in project pom-manipulation-ext by release-engineering.

the class Project method getResolvedProfileManagedPlugins.

/**
 * This method will scan the plugins in the pluginManagement section in the potentially active Profiles
 * in this project and return a fully resolved list. Note that while updating the {@link Plugin}
 * reference returned will be reflected in the Model as it is the same object, if you wish to remove
 * or add items to the Model then you must use {@link #getModel()}
 *
 * @param session MavenSessionHandler, used by {@link PropertyResolver}
 * @return a list of fully resolved {@link ProjectVersionRef} to the original {@link Plugin}
 * @throws ManipulationException if an error occurs
 */
public HashMap<Profile, HashMap<ProjectVersionRef, Plugin>> getResolvedProfileManagedPlugins(MavenSessionHandler session) throws ManipulationException {
    if (resolvedProfileManagedPlugins == null) {
        resolvedProfileManagedPlugins = new HashMap<>();
        for (final Profile profile : ProfileUtils.getProfiles(session, model)) {
            HashMap<ProjectVersionRef, Plugin> profileDeps = new HashMap<>();
            if (profile.getBuild() != null) {
                final PluginManagement pm = profile.getBuild().getPluginManagement();
                if (!(pm == null || pm.getPlugins() == null)) {
                    resolvePlugins(session, pm.getPlugins(), profileDeps);
                }
            }
            resolvedProfileManagedPlugins.put(profile, profileDeps);
        }
    }
    return resolvedProfileManagedPlugins;
}
Also used : PluginManagement(org.apache.maven.model.PluginManagement) HashMap(java.util.HashMap) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Profile(org.apache.maven.model.Profile) Plugin(org.apache.maven.model.Plugin)

Example 92 with Plugin

use of org.apache.maven.model.Plugin in project pom-manipulation-ext by release-engineering.

the class DistributionEnforcingManipulator method getPluginMap.

private Map<String, Plugin> getPluginMap(final ModelBase base) {
    final BuildBase build;
    if (base instanceof Model) {
        build = ((Model) base).getBuild();
    } else {
        build = ((Profile) base).getBuild();
    }
    if (build == null) {
        return Collections.emptyMap();
    }
    final Map<String, Plugin> result = build.getPluginsAsMap();
    if (result == null) {
        return Collections.emptyMap();
    }
    return result;
}
Also used : BuildBase(org.apache.maven.model.BuildBase) Model(org.apache.maven.model.Model) Plugin(org.apache.maven.model.Plugin)

Example 93 with Plugin

use of org.apache.maven.model.Plugin in project pom-manipulation-ext by release-engineering.

the class DistributionEnforcingManipulator method findSkipRefs.

/**
 * Go through the plugin / plugin-execution configurations and find references to the <code>skip</code> parameter for the given Maven plugin
 * (specified by artifactId), both in managed and concrete plugin declarations (where available).
 */
private List<SkipReference> findSkipRefs(final ModelBase base, final String pluginArtifactId, final Project project) throws ManipulationException {
    final String key = ga(MAVEN_PLUGIN_GROUPID, pluginArtifactId);
    final List<SkipReference> result = new ArrayList<>();
    Map<String, Plugin> pluginMap = getManagedPluginMap(base);
    Plugin plugin = pluginMap.get(key);
    result.addAll(findSkipRefs(plugin, project));
    pluginMap = getPluginMap(base);
    plugin = pluginMap.get(key);
    result.addAll(findSkipRefs(plugin, project));
    return result;
}
Also used : ArrayList(java.util.ArrayList) Plugin(org.apache.maven.model.Plugin)

Example 94 with Plugin

use of org.apache.maven.model.Plugin in project pom-manipulation-ext by release-engineering.

the class PluginRemovalManipulator method scanPlugins.

private boolean scanPlugins(List<ProjectRef> pluginsToRemove, List<Plugin> plugins) {
    boolean result = false;
    if (plugins != null) {
        Iterator<Plugin> it = plugins.iterator();
        while (it.hasNext()) {
            Plugin p = it.next();
            if (pluginsToRemove.contains(SimpleProjectRef.parse(p.getKey()))) {
                logger.debug("Removing {} ", p.toString());
                it.remove();
                result = true;
            }
        }
    }
    return result;
}
Also used : Plugin(org.apache.maven.model.Plugin)

Example 95 with Plugin

use of org.apache.maven.model.Plugin in project pom-manipulation-ext by release-engineering.

the class BOMBuilderManipulator method applyChanges.

/**
 * If enabled, grab the execution root pom (which will be the topmost POM in terms of directory structure). Within that
 * handle the manipulation of the bom injection.
 */
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
    final BOMInjectingState state = session.getState(BOMInjectingState.class);
    if (!session.isEnabled() || !state.isEnabled()) {
        logger.debug(getClass().getSimpleName() + ": Nothing to do!");
        return Collections.emptySet();
    }
    List<Dependency> projectArtifacts = getArtifacts(projects);
    for (final Project project : projects) {
        if (project.isExecutionRoot()) {
            logger.info("Examining {} to add BOM generation.", project);
            final Model model = project.getModel();
            Build build = model.getBuild();
            if (build == null) {
                build = new Build();
                model.setBuild(build);
            }
            Model bomModel = createModel(project, IDBOM);
            bomModel.setDescription("PME Generated BOM for other projects to use to align to.");
            DependencyManagement dm = new DependencyManagement();
            dm.setDependencies(projectArtifacts);
            bomModel.setDependencyManagement(dm);
            // Write new bom back out.
            File pmebom = new File(session.getTargetDir(), IDBOM + ".xml");
            session.getTargetDir().mkdir();
            pomIO.writeModel(bomModel, pmebom);
            final Map<String, Plugin> pluginMap = build.getPluginsAsMap();
            if (!pluginMap.containsKey(POM_DEPLOYER_COORD)) {
                final PluginExecution execution = new PluginExecution();
                execution.setId(IDBOM);
                execution.setPhase("install");
                execution.setGoals(Collections.singletonList("add-pom"));
                final Plugin plugin = new Plugin();
                plugin.setGroupId(POM_DEPLOYER_GID);
                plugin.setArtifactId(POM_DEPLOYER_AID);
                plugin.setVersion(POM_DEPLOYER_VID);
                plugin.addExecution(execution);
                plugin.setInherited(false);
                build.addPlugin(plugin);
                final Xpp3Dom xml = new Xpp3Dom("configuration");
                final Map<String, Object> config = new HashMap<>();
                config.put("pomName", "target" + File.separatorChar + pmebom.getName());
                config.put("errorOnMissing", false);
                config.put("artifactId", bomModel.getArtifactId());
                config.put("groupId", bomModel.getGroupId());
                for (final Map.Entry<String, Object> entry : config.entrySet()) {
                    final Xpp3Dom child = new Xpp3Dom(entry.getKey());
                    if (entry.getValue() != null) {
                        child.setValue(entry.getValue().toString());
                    }
                    xml.addChild(child);
                }
                execution.setConfiguration(xml);
            }
            return Collections.singleton(project);
        }
    }
    return Collections.emptySet();
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) HashMap(java.util.HashMap) Dependency(org.apache.maven.model.Dependency) Project(org.commonjava.maven.ext.common.model.Project) Build(org.apache.maven.model.Build) Model(org.apache.maven.model.Model) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) BOMInjectingState(org.commonjava.maven.ext.core.state.BOMInjectingState) DependencyManagement(org.apache.maven.model.DependencyManagement) 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