- 
                Notifications
    You must be signed in to change notification settings 
- Fork 55
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
  6
  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 5 commits
      Commits
    
    
            Show all changes
          
          
            6 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 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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -118,6 +118,7 @@ public class CacheConfigImpl implements org.apache.maven.buildcache.xml.CacheCon | |
| private final XmlService xmlService; | ||
| private final Provider<MavenSession> providerSession; | ||
| private final RuntimeInformation rtInfo; | ||
| private final PluginParameterLoader parameterLoader; | ||
|  | ||
| private volatile CacheState state; | ||
| private CacheConfig cacheConfig; | ||
|  | @@ -129,6 +130,7 @@ public CacheConfigImpl(XmlService xmlService, Provider<MavenSession> providerSes | |
| this.xmlService = xmlService; | ||
| this.providerSession = providerSession; | ||
| this.rtInfo = rtInfo; | ||
| this.parameterLoader = new PluginParameterLoader(); | ||
| } | ||
|  | ||
| @Nonnull | ||
|  | @@ -248,27 +250,163 @@ public boolean isLogAllProperties(MojoExecution mojoExecution) { | |
| } | ||
|  | ||
| private GoalReconciliation findReconciliationConfig(MojoExecution mojoExecution) { | ||
| if (cacheConfig.getExecutionControl() == null) { | ||
| if (mojoExecution == null) { | ||
| return null; | ||
| } | ||
|  | ||
| final ExecutionControl executionControl = cacheConfig.getExecutionControl(); | ||
| if (executionControl.getReconcile() == null) { | ||
| final String goal = mojoExecution.getGoal(); | ||
| final Plugin plugin = mojoExecution.getPlugin(); | ||
|  | ||
| if (plugin == null) { | ||
| return null; | ||
| } | ||
|  | ||
| final List<GoalReconciliation> reconciliation = | ||
| executionControl.getReconcile().getPlugins(); | ||
| // First check explicit configuration | ||
| if (cacheConfig.getExecutionControl() != null && cacheConfig.getExecutionControl().getReconcile() != null) { | ||
| List<GoalReconciliation> explicitConfigs = | ||
| cacheConfig.getExecutionControl().getReconcile().getPlugins(); | ||
| for (GoalReconciliation config : explicitConfigs) { | ||
| if (isPluginMatch(plugin, config) && Strings.CS.equals(goal, config.getGoal())) { | ||
| // Validate explicit config against parameter definitions (with version) | ||
| validateReconciliationConfig(config, plugin); | ||
| return config; | ||
| } | ||
| } | ||
| } | ||
|  | ||
| // Auto-generate from parameter definitions (track all functional parameters) | ||
| GoalReconciliation autoGenerated = generateReconciliationFromParameters(plugin, goal); | ||
| if (autoGenerated != null) { | ||
| LOGGER.debug( | ||
| "Auto-generated reconciliation config for {}:{} with {} functional parameters", | ||
| plugin.getArtifactId(), | ||
| goal, | ||
| autoGenerated.getReconciles() != null ? autoGenerated.getReconciles().size() : 0); | ||
| } | ||
| return autoGenerated; | ||
| } | ||
|  | ||
| /** | ||
| * Validates a single reconciliation config against plugin parameter definitions. | ||
| * Uses plugin version to load the appropriate parameter definition. | ||
| */ | ||
| private void validateReconciliationConfig(GoalReconciliation config, Plugin plugin) { | ||
| String artifactId = config.getArtifactId(); | ||
| String goal = config.getGoal(); | ||
| String pluginVersion = plugin.getVersion(); | ||
|  | ||
| // Load parameter definition for this plugin with version | ||
| PluginParameterDefinition pluginDef = parameterLoader.load(artifactId, pluginVersion); | ||
|  | ||
| if (pluginDef == null) { | ||
| LOGGER.warn( | ||
| "No parameter definition found for plugin {}:{} version {}. " | ||
| + "Cannot validate reconciliation configuration. " | ||
| + "Consider adding a parameter definition file to plugin-parameters/{}.xml", | ||
| artifactId, | ||
| goal, | ||
| pluginVersion != null ? pluginVersion : "unknown", | ||
| artifactId); | ||
| return; | ||
| } | ||
|  | ||
| // Get goal definition | ||
| PluginParameterDefinition.GoalParameterDefinition goalDef = pluginDef.getGoal(goal); | ||
| if (goalDef == null) { | ||
| LOGGER.warn( | ||
| "Goal '{}' not found in parameter definition for plugin {} version {}. " | ||
| + "Cannot validate reconciliation configuration.", | ||
| goal, | ||
| artifactId, | ||
| pluginVersion != null ? pluginVersion : "unknown"); | ||
| return; | ||
| } | ||
|  | ||
| for (GoalReconciliation goalReconciliationConfig : reconciliation) { | ||
| final String goal = mojoExecution.getGoal(); | ||
| // Validate each tracked property | ||
| List<TrackedProperty> properties = config.getReconciles(); | ||
| if (properties == null) { | ||
| return; | ||
| } | ||
|  | ||
| if (isPluginMatch(mojoExecution.getPlugin(), goalReconciliationConfig) | ||
| && Strings.CS.equals(goal, goalReconciliationConfig.getGoal())) { | ||
| return goalReconciliationConfig; | ||
| for (TrackedProperty property : properties) { | ||
| String propertyName = property.getPropertyName(); | ||
|  | ||
| if (!goalDef.hasParameter(propertyName)) { | ||
| LOGGER.error( | ||
| "Unknown parameter '{}' in reconciliation config for {}:{} version {}. " | ||
| + "This may indicate a plugin version mismatch or renamed parameter. " | ||
| + "Consider updating parameter definition or removing from reconciliation.", | ||
| propertyName, | ||
| artifactId, | ||
| goal, | ||
| pluginVersion != null ? pluginVersion : "unknown"); | ||
| } else { | ||
| PluginParameterDefinition.ParameterDefinition paramDef = goalDef.getParameter(propertyName); | ||
| if (paramDef.isBehavioral()) { | ||
| LOGGER.warn( | ||
| "Parameter '{}' in reconciliation config for {}:{} is categorized as BEHAVIORAL. " | ||
| + "Behavioral parameters affect how the build runs but not the output. " | ||
| + "Consider removing if it doesn't actually affect build artifacts.", | ||
| propertyName, | ||
| artifactId, | ||
| goal); | ||
| } | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|  | ||
| /** | ||
| * Auto-generates a reconciliation config by tracking all functional parameters | ||
| * from the plugin parameter definition. | ||
| * This provides automatic default tracking for any plugin with parameter definitions. | ||
| * | ||
| * @param plugin The plugin to generate config for | ||
| * @param goal The goal name | ||
| * @return Auto-generated config tracking all functional parameters, or null if no parameter definition exists | ||
| */ | ||
| private GoalReconciliation generateReconciliationFromParameters(Plugin plugin, String goal) { | ||
| String artifactId = plugin.getArtifactId(); | ||
| String pluginVersion = plugin.getVersion(); | ||
|  | ||
| // Load parameter definition for this plugin | ||
| PluginParameterDefinition pluginDef = parameterLoader.load(artifactId, pluginVersion); | ||
| if (pluginDef == null) { | ||
| return null; | ||
| } | ||
|  | ||
| // Get goal definition | ||
| PluginParameterDefinition.GoalParameterDefinition goalDef = pluginDef.getGoal(goal); | ||
| if (goalDef == null) { | ||
| return null; | ||
| } | ||
|  | ||
| // Collect all functional parameters | ||
| List<TrackedProperty> functionalProperties = new ArrayList<>(); | ||
| for (PluginParameterDefinition.ParameterDefinition param : goalDef.getParameters().values()) { | ||
| if (param.isFunctional()) { | ||
| TrackedProperty property = new TrackedProperty(); | ||
| property.setPropertyName(param.getName()); | ||
| functionalProperties.add(property); | ||
| } | ||
| } | ||
|  | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a debug statement here please?  Something like:  | ||
| // Only create config if there are functional parameters to track | ||
| if (functionalProperties.isEmpty()) { | ||
| return null; | ||
| } | ||
|  | ||
| // Create auto-generated reconciliation config | ||
| GoalReconciliation config = new GoalReconciliation(); | ||
| config.setArtifactId(artifactId); | ||
| if (plugin.getGroupId() != null) { | ||
| config.setGroupId(plugin.getGroupId()); | ||
| } | ||
| config.setGoal(goal); | ||
| for (TrackedProperty property : functionalProperties) { | ||
| config.addReconcile(property); | ||
| } | ||
|  | ||
| return config; | ||
| } | ||
|  | ||
| @Nonnull | ||
|  | ||
        
          
          
            148 changes: 148 additions & 0 deletions
          
          148 
        
  src/main/java/org/apache/maven/buildcache/xml/PluginParameterDefinition.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,148 @@ | ||
| /* | ||
| * 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 java.util.HashMap; | ||
| import java.util.Map; | ||
|  | ||
| /** | ||
| * Represents the complete parameter definition for a Maven plugin loaded from XML. | ||
| * Contains all goals and their parameters with categorization (functional vs behavioral). | ||
| */ | ||
| public class PluginParameterDefinition { | ||
|  | ||
| private final String groupId; | ||
| private final String artifactId; | ||
| private final String minVersion; | ||
| private final Map<String, GoalParameterDefinition> goals; | ||
|  | ||
| public PluginParameterDefinition(String groupId, String artifactId, String minVersion) { | ||
| this.groupId = groupId; | ||
| this.artifactId = artifactId; | ||
| this.minVersion = minVersion; | ||
| this.goals = new HashMap<>(); | ||
| } | ||
|  | ||
| public String getGroupId() { | ||
| return groupId; | ||
| } | ||
|  | ||
| public String getArtifactId() { | ||
| return artifactId; | ||
| } | ||
|  | ||
| public String getMinVersion() { | ||
| return minVersion; | ||
| } | ||
|  | ||
| public void addGoal(String goalName, GoalParameterDefinition goal) { | ||
| goals.put(goalName, goal); | ||
| } | ||
|  | ||
| public GoalParameterDefinition getGoal(String goalName) { | ||
| return goals.get(goalName); | ||
| } | ||
|  | ||
| public Map<String, GoalParameterDefinition> getGoals() { | ||
| return goals; | ||
| } | ||
|  | ||
| /** | ||
| * Represents parameters for a single goal | ||
| */ | ||
| public static class GoalParameterDefinition { | ||
| private final String name; | ||
| private final Map<String, ParameterDefinition> parameters; | ||
|  | ||
| public GoalParameterDefinition(String name) { | ||
| this.name = name; | ||
| this.parameters = new HashMap<>(); | ||
| } | ||
|  | ||
| public String getName() { | ||
| return name; | ||
| } | ||
|  | ||
| public void addParameter(ParameterDefinition parameter) { | ||
| parameters.put(parameter.getName(), parameter); | ||
| } | ||
|  | ||
| public ParameterDefinition getParameter(String paramName) { | ||
| return parameters.get(paramName); | ||
| } | ||
|  | ||
| public Map<String, ParameterDefinition> getParameters() { | ||
| return parameters; | ||
| } | ||
|  | ||
| public boolean hasParameter(String paramName) { | ||
| return parameters.containsKey(paramName); | ||
| } | ||
| } | ||
|  | ||
| /** | ||
| * Represents a single parameter definition | ||
| */ | ||
| public static class ParameterDefinition { | ||
| private final String name; | ||
| private final ParameterType type; | ||
| private final String description; | ||
|  | ||
| public ParameterDefinition(String name, ParameterType type, String description) { | ||
| this.name = name; | ||
| this.type = type; | ||
| this.description = description; | ||
| } | ||
|  | ||
| public String getName() { | ||
| return name; | ||
| } | ||
|  | ||
| public ParameterType getType() { | ||
| return type; | ||
| } | ||
|  | ||
| public String getDescription() { | ||
| return description; | ||
| } | ||
|  | ||
| public boolean isFunctional() { | ||
| return type == ParameterType.FUNCTIONAL; | ||
| } | ||
|  | ||
| public boolean isBehavioral() { | ||
| return type == ParameterType.BEHAVIORAL; | ||
| } | ||
| } | ||
|  | ||
| /** | ||
| * Parameter type categorization | ||
| */ | ||
| public enum ParameterType { | ||
| /** | ||
| * Functional parameters affect the compiled output or artifacts | ||
| */ | ||
| FUNCTIONAL, | ||
|  | ||
| /** | ||
| * Behavioral parameters affect how the build runs but not the output | ||
| */ | ||
| BEHAVIORAL | ||
| } | ||
| } | 
      
      Oops, something went wrong.
        
    
  
      
      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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like a warn as well. there might be an outdated config bundled in the extension which was manually corrected by user using config. might be an error, might be not.