Search in sources :

Example 1 with ConfigurationContainer

use of org.apache.maven.model.ConfigurationContainer 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 2 with ConfigurationContainer

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

Aggregations

ConfigurationContainer (org.apache.maven.model.ConfigurationContainer)2 PluginExecution (org.apache.maven.model.PluginExecution)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ManipulationException (org.commonjava.maven.ext.common.ManipulationException)1 GalleyMavenXMLException (org.commonjava.maven.galley.maven.parse.GalleyMavenXMLException)1 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1