Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ under the License.
<minimalMavenBuildVersion>3.9.0</minimalMavenBuildVersion>
<minimalJavaBuildVersion>11</minimalJavaBuildVersion>
<classWorldsVersion>2.6.0</classWorldsVersion>
<version.spotless-maven-plugin>3.0.0</version.spotless-maven-plugin>

<!-- default maven version, will be overridden by maven3 profile -->
<mavenVersion>4.0.0-alpha-8</mavenVersion>
Expand Down Expand Up @@ -427,6 +428,17 @@ under the License.
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<configuration>
<java>
<palantirJavaFormat>
<version>2.81.0</version>
</palantirJavaFormat>
</java>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
165 changes: 153 additions & 12 deletions src/main/java/org/apache/maven/buildcache/xml/CacheConfigImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.apache.maven.buildcache.xml.config.Exclude;
import org.apache.maven.buildcache.xml.config.Executables;
import org.apache.maven.buildcache.xml.config.ExecutionConfigurationScan;
import org.apache.maven.buildcache.xml.config.ExecutionControl;
import org.apache.maven.buildcache.xml.config.ExecutionIdsList;
import org.apache.maven.buildcache.xml.config.GoalReconciliation;
import org.apache.maven.buildcache.xml.config.GoalsList;
Expand Down Expand Up @@ -118,6 +117,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;
Expand All @@ -129,6 +129,7 @@ public CacheConfigImpl(XmlService xmlService, Provider<MavenSession> providerSes
this.xmlService = xmlService;
this.providerSession = providerSession;
this.rtInfo = rtInfo;
this.parameterLoader = new PluginParameterLoader();
}

@Nonnull
Expand Down Expand Up @@ -248,27 +249,167 @@ 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);
}
}

// 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
Expand Down
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
}
}
Loading