Search in sources :

Example 21 with PluginExecution

use of org.apache.maven.model.PluginExecution 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
 * instance.
 */
private List<SkipReference> findSkipRefs(final Plugin plugin, final Project project) throws ManipulationException {
    if (plugin == null) {
        return Collections.emptyList();
    }
    final Map<ConfigurationContainer, String> configs = new LinkedHashMap<>();
    Object configuration = plugin.getConfiguration();
    if (configuration != null) {
        configs.put(plugin, configuration.toString());
    }
    final List<PluginExecution> executions = plugin.getExecutions();
    if (executions != null) {
        for (final PluginExecution execution : executions) {
            configuration = execution.getConfiguration();
            if (configuration != null) {
                configs.put(execution, configuration.toString());
            }
        }
    }
    final List<SkipReference> result = new ArrayList<>();
    for (final Map.Entry<ConfigurationContainer, String> entry : configs.entrySet()) {
        try {
            final Document doc = galleyWrapper.parseXml(entry.getValue());
            final NodeList children = doc.getDocumentElement().getChildNodes();
            if (children != null) {
                for (int i = 0; i < children.getLength(); i++) {
                    final Node n = children.item(i);
                    if (n.getNodeName().equals(SKIP_NODE)) {
                        result.add(new SkipReference(entry.getKey(), n));
                    }
                }
            }
        } catch (final GalleyMavenXMLException e) {
            throw new ManipulationException("Unable to parse config for plugin: %s in: %s", e, plugin.getId(), project.getId());
        }
    }
    return result;
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) GalleyMavenXMLException(org.commonjava.maven.galley.maven.parse.GalleyMavenXMLException) Document(org.w3c.dom.Document) LinkedHashMap(java.util.LinkedHashMap) ConfigurationContainer(org.apache.maven.model.ConfigurationContainer) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 22 with PluginExecution

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

the class DistributionEnforcingManipulator method enforceSkipFlag.

/**
 * For every mention of a <code>skip</code> parameter in either the install or deploy plugins, enforce a particular value that's passed in. If the
 * passed-in value is <code>null</code> AND the detectFlagValue parameter is true, then look for an install-plugin configuration (in either the
 * plugin-wide config or that of the default-install execution ONLY) that contains the <code>skip</code> flag, and use that as the enforced value.
 *
 * If detection is enabled and no install-plugin is found, set the value to false (don't skip install or deploy).
 *
 * @return the detected value, if detection is enabled.
 */
private Boolean enforceSkipFlag(final ModelBase base, Boolean baseSkipSetting, final Project project, final Set<Project> changed, final boolean detectFlagValue) throws ManipulationException {
    // search for install/skip config option, use the first one found...
    Boolean skipSetting = baseSkipSetting;
    List<SkipReference> skipRefs = findSkipRefs(base, MAVEN_INSTALL_ARTIFACTID, project);
    if (!skipRefs.isEmpty()) {
        if (detectFlagValue && skipSetting == null) {
            // we need to set the local value AND the global value.
            final SkipReference ref = skipRefs.get(0);
            final ConfigurationContainer container = ref.getContainer();
            if (!(container instanceof PluginExecution) || ((PluginExecution) container).getId().equals(DEFAULT_INSTALL_EXEC)) {
                String textVal = ref.getNode().getTextContent();
                if (isNotEmpty(textVal)) {
                    textVal = textVal.trim();
                    skipSetting = Boolean.parseBoolean(textVal);
                }
            }
        }
    } else if (detectFlagValue && skipSetting == null) {
        skipSetting = false;
    }
    if (skipSetting == null) {
        logger.warn("No setting to enforce for skip-flag! Aborting enforcement...");
        return null;
    }
    if (!skipRefs.isEmpty()) {
        for (final SkipReference ref : skipRefs) {
            setFlag(ref, skipSetting, project, changed);
        }
    }
    skipRefs = findSkipRefs(base, MAVEN_DEPLOY_ARTIFACTID, project);
    if (!skipRefs.isEmpty()) {
        for (final SkipReference ref : skipRefs) {
            setFlag(ref, skipSetting, project, changed);
        }
    }
    return skipSetting;
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) ConfigurationContainer(org.apache.maven.model.ConfigurationContainer)

Example 23 with PluginExecution

use of org.apache.maven.model.PluginExecution 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)

Example 24 with PluginExecution

use of org.apache.maven.model.PluginExecution in project meghanada-server by mopemope.

the class POMParser method parsePlugins.

private void parsePlugins(POMInfo pomInfo, Build build) {
    for (Plugin plugin : build.getPlugins()) {
        if (plugin.getArtifactId().equals("build-helper-maven-plugin")) {
            for (PluginExecution pluginExecution : plugin.getExecutions()) {
                Object conf = pluginExecution.getConfiguration();
                if (nonNull(conf) && conf instanceof Xpp3Dom) {
                    Xpp3Dom confDom = (Xpp3Dom) conf;
                    Xpp3Dom sources = confDom.getChild("sources");
                    if (nonNull(sources)) {
                        Xpp3Dom[] children = sources.getChildren();
                        if (nonNull(children)) {
                            for (Xpp3Dom s : sources.getChildren()) {
                                String value = s.getValue();
                                if (!Strings.isNullOrEmpty(value)) {
                                    pomInfo.sourceDirectory.add(normalize(pomInfo, value));
                                }
                            }
                        }
                    }
                }
            }
        }
        if (plugin.getArtifactId().equals("maven-compiler-plugin")) {
            Object conf = plugin.getConfiguration();
            if (nonNull(conf) && conf instanceof Xpp3Dom) {
                Xpp3Dom confDom = (Xpp3Dom) conf;
                Xpp3Dom source = confDom.getChild("source");
                if (nonNull(source)) {
                    pomInfo.compileSource = source.getValue();
                }
                Xpp3Dom target = confDom.getChild("target");
                if (nonNull(target)) {
                    pomInfo.compileTarget = target.getValue();
                }
            }
        }
    }
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Plugin(org.apache.maven.model.Plugin)

Example 25 with PluginExecution

use of org.apache.maven.model.PluginExecution in project maven-git-versioning-extension by qoomon.

the class VersioningModelProcessor method addBuildPlugin.

private void addBuildPlugin(Model model) {
    GAV projectGav = GAV.of(model);
    logger.debug(projectGav + " temporary add build plugin");
    if (model.getBuild() == null) {
        model.setBuild(new Build());
    }
    Plugin projectPlugin = VersioningPomReplacementMojo.asPlugin();
    PluginExecution execution = new PluginExecution();
    execution.setId(VersioningPomReplacementMojo.GOAL);
    execution.getGoals().add(VersioningPomReplacementMojo.GOAL);
    projectPlugin.getExecutions().add(execution);
    model.getBuild().getPlugins().add(projectPlugin);
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) Build(org.apache.maven.model.Build) GAV(com.qoomon.maven.GAV) Plugin(org.apache.maven.model.Plugin)

Aggregations

PluginExecution (org.apache.maven.model.PluginExecution)32 Plugin (org.apache.maven.model.Plugin)22 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)18 ArrayList (java.util.ArrayList)8 Build (org.apache.maven.model.Build)6 Dependency (org.apache.maven.model.Dependency)6 Model (org.apache.maven.model.Model)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 Element (org.jdom.Element)4 Iterator (java.util.Iterator)3 MavenProject (org.apache.maven.project.MavenProject)3 ManipulationException (org.commonjava.maven.ext.common.ManipulationException)3 File (java.io.File)2 ConfigurationContainer (org.apache.maven.model.ConfigurationContainer)2 Repository (org.apache.maven.model.Repository)2 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)2 Project (org.commonjava.maven.ext.common.model.Project)2 CorePlugin (org.talend.core.CorePlugin)2