-
Notifications
You must be signed in to change notification settings - Fork 59
Add default executionControl reconciliation for common Maven plugins #389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cowwoc
wants to merge
9
commits into
apache:master
Choose a base branch
from
cowwoc:default-execution-control
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e99c008
Add default executionControl reconciliation for common Maven plugins
cowwoc 4678f01
Add integration tests and fix default reconciliation merging
cowwoc 81856c4
Reclassify skip parameters from behavioral to functional
cowwoc c568eaf
Implement auto-tracking of functional parameters from plugin XML defi…
cowwoc a2c3c4a
Add test to verify all functional parameters are auto-tracked
cowwoc 4b1679f
Apply code formatting and upgrade spotless tooling
cowwoc b61ef66
Address PR review comments
cowwoc 672b997
Fix backward compatibility for auto-generated reconciliation configs
cowwoc af6e629
Revert Spotless Maven Plugin upgrade
cowwoc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
src/main/java/org/apache/maven/buildcache/xml/DefaultReconciliationLoader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.maven.buildcache.xml; | ||
|
|
||
| import javax.xml.parsers.DocumentBuilder; | ||
| import javax.xml.parsers.DocumentBuilderFactory; | ||
|
|
||
| import java.io.InputStream; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import org.apache.maven.buildcache.xml.config.GoalReconciliation; | ||
| import org.apache.maven.buildcache.xml.config.TrackedProperty; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.w3c.dom.Document; | ||
| import org.w3c.dom.Element; | ||
| import org.w3c.dom.NodeList; | ||
|
|
||
| /** | ||
| * Loads default reconciliation configurations from classpath resources. | ||
| * Default configs are stored in src/main/resources/default-reconciliation/defaults.xml | ||
| */ | ||
| public class DefaultReconciliationLoader { | ||
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(DefaultReconciliationLoader.class); | ||
| private static final String DEFAULTS_PATH = "default-reconciliation/defaults.xml"; | ||
|
|
||
| private List<GoalReconciliation> cachedDefaults; | ||
|
|
||
| /** | ||
| * Load default reconciliation configurations from XML | ||
| */ | ||
| public List<GoalReconciliation> loadDefaults() { | ||
| if (cachedDefaults != null) { | ||
| return cachedDefaults; | ||
| } | ||
|
|
||
| InputStream is = getClass().getClassLoader().getResourceAsStream(DEFAULTS_PATH); | ||
|
|
||
| if (is == null) { | ||
| LOGGER.warn("No default reconciliation configuration found at {}", DEFAULTS_PATH); | ||
| cachedDefaults = new ArrayList<>(); | ||
| return cachedDefaults; | ||
| } | ||
|
|
||
| try { | ||
| cachedDefaults = parseDefaults(is); | ||
| LOGGER.info("Loaded {} default reconciliation configurations", cachedDefaults.size()); | ||
| return cachedDefaults; | ||
| } catch (Exception e) { | ||
| LOGGER.warn("Failed to load default reconciliation configurations: {}", e.getMessage(), e); | ||
| cachedDefaults = new ArrayList<>(); | ||
| return cachedDefaults; | ||
| } | ||
| } | ||
|
|
||
| private List<GoalReconciliation> parseDefaults(InputStream is) throws Exception { | ||
| List<GoalReconciliation> defaults = new ArrayList<>(); | ||
|
|
||
| DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | ||
| factory.setNamespaceAware(true); | ||
| DocumentBuilder builder = factory.newDocumentBuilder(); | ||
| Document doc = builder.parse(is); | ||
|
|
||
| Element root = doc.getDocumentElement(); | ||
| NodeList pluginNodes = root.getElementsByTagName("plugin"); | ||
|
|
||
| for (int i = 0; i < pluginNodes.getLength(); i++) { | ||
| Element pluginElement = (Element) pluginNodes.item(i); | ||
| GoalReconciliation config = parsePlugin(pluginElement); | ||
| defaults.add(config); | ||
| } | ||
|
|
||
| return defaults; | ||
| } | ||
|
|
||
| private GoalReconciliation parsePlugin(Element pluginElement) { | ||
| String artifactId = getTextContent(pluginElement, "artifactId"); | ||
| String goal = getTextContent(pluginElement, "goal"); | ||
|
|
||
| GoalReconciliation config = new GoalReconciliation(); | ||
| config.setArtifactId(artifactId); | ||
| config.setGoal(goal); | ||
|
|
||
| // Parse properties if present | ||
| NodeList propertiesNodes = pluginElement.getElementsByTagName("properties"); | ||
| if (propertiesNodes.getLength() > 0) { | ||
| Element propertiesElement = (Element) propertiesNodes.item(0); | ||
| NodeList propertyNodes = propertiesElement.getElementsByTagName("property"); | ||
|
|
||
| for (int i = 0; i < propertyNodes.getLength(); i++) { | ||
| String propertyName = propertyNodes.item(i).getTextContent().trim(); | ||
| TrackedProperty property = new TrackedProperty(); | ||
| property.setPropertyName(propertyName); | ||
| config.addReconcile(property); | ||
| } | ||
| } | ||
|
|
||
| return config; | ||
| } | ||
|
|
||
| private String getTextContent(Element parent, String tagName) { | ||
| NodeList nodes = parent.getElementsByTagName(tagName); | ||
| if (nodes.getLength() > 0) { | ||
| return nodes.item(0).getTextContent().trim(); | ||
| } | ||
| return null; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.