|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.apache.maven.buildcache.xml; |
| 20 | + |
| 21 | +import org.apache.maven.buildcache.xml.config.TrackedProperty; |
| 22 | +import org.junit.jupiter.api.Test; |
| 23 | + |
| 24 | +import java.util.List; |
| 25 | +import java.util.Set; |
| 26 | +import java.util.stream.Collectors; |
| 27 | + |
| 28 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 29 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 30 | + |
| 31 | +/** |
| 32 | + * Tests that auto-tracking from plugin parameter definitions works correctly. |
| 33 | + * Verifies that ALL functional parameters are automatically tracked, not just a subset. |
| 34 | + */ |
| 35 | +class AutoTrackingFunctionalParametersTest { |
| 36 | + |
| 37 | + @Test |
| 38 | + void testMavenCompilerPluginAutoTracksAllFunctionalParameters() { |
| 39 | + // This test verifies that the auto-generation tracks ALL functional parameters, |
| 40 | + // not just the 3 that were in the old defaults.xml (source, target, release) |
| 41 | + |
| 42 | + PluginParameterLoader loader = new PluginParameterLoader(); |
| 43 | + PluginParameterDefinition def = loader.load("maven-compiler-plugin"); |
| 44 | + |
| 45 | + assertNotNull(def, "Should load maven-compiler-plugin definition"); |
| 46 | + |
| 47 | + PluginParameterDefinition.GoalParameterDefinition compileGoal = def.getGoal("compile"); |
| 48 | + assertNotNull(compileGoal, "compile goal should exist"); |
| 49 | + |
| 50 | + // Get all functional parameter names from the XML definition |
| 51 | + Set<String> functionalParams = compileGoal.getParameters().values().stream() |
| 52 | + .filter(PluginParameterDefinition.ParameterDefinition::isFunctional) |
| 53 | + .map(PluginParameterDefinition.ParameterDefinition::getName) |
| 54 | + .collect(Collectors.toSet()); |
| 55 | + |
| 56 | + // Verify we have more than just the original 3 from defaults.xml |
| 57 | + assertTrue(functionalParams.size() > 3, |
| 58 | + "Should have more than 3 functional parameters (was: " + functionalParams.size() + ")"); |
| 59 | + |
| 60 | + // Verify the original 3 are included |
| 61 | + assertTrue(functionalParams.contains("source"), "Should include 'source' parameter"); |
| 62 | + assertTrue(functionalParams.contains("target"), "Should include 'target' parameter"); |
| 63 | + assertTrue(functionalParams.contains("release"), "Should include 'release' parameter"); |
| 64 | + |
| 65 | + // Verify additional functional parameters are included (these were NOT in defaults.xml) |
| 66 | + assertTrue(functionalParams.contains("encoding"), |
| 67 | + "Should include 'encoding' parameter (auto-tracked, not in old defaults.xml)"); |
| 68 | + assertTrue(functionalParams.contains("debug"), |
| 69 | + "Should include 'debug' parameter (auto-tracked, not in old defaults.xml)"); |
| 70 | + assertTrue(functionalParams.contains("compilerArgs"), |
| 71 | + "Should include 'compilerArgs' parameter (auto-tracked, not in old defaults.xml)"); |
| 72 | + assertTrue(functionalParams.contains("annotationProcessorPaths"), |
| 73 | + "Should include 'annotationProcessorPaths' parameter (auto-tracked, not in old defaults.xml)"); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + void testMavenInstallPluginAutoTracksAllFunctionalParameters() { |
| 78 | + PluginParameterLoader loader = new PluginParameterLoader(); |
| 79 | + PluginParameterDefinition def = loader.load("maven-install-plugin"); |
| 80 | + |
| 81 | + assertNotNull(def, "Should load maven-install-plugin definition"); |
| 82 | + |
| 83 | + PluginParameterDefinition.GoalParameterDefinition installGoal = def.getGoal("install"); |
| 84 | + assertNotNull(installGoal, "install goal should exist"); |
| 85 | + |
| 86 | + // Get all functional parameter names |
| 87 | + Set<String> functionalParams = installGoal.getParameters().values().stream() |
| 88 | + .filter(PluginParameterDefinition.ParameterDefinition::isFunctional) |
| 89 | + .map(PluginParameterDefinition.ParameterDefinition::getName) |
| 90 | + .collect(Collectors.toSet()); |
| 91 | + |
| 92 | + // The old defaults.xml had NO properties listed for maven-install-plugin |
| 93 | + // Now auto-tracking should track all functional parameters |
| 94 | + assertTrue(functionalParams.size() > 0, |
| 95 | + "Should auto-track functional parameters (old defaults.xml had 0)"); |
| 96 | + |
| 97 | + // Verify key functional parameters are tracked |
| 98 | + assertTrue(functionalParams.contains("file"), "Should track 'file' parameter"); |
| 99 | + assertTrue(functionalParams.contains("groupId"), "Should track 'groupId' parameter"); |
| 100 | + assertTrue(functionalParams.contains("artifactId"), "Should track 'artifactId' parameter"); |
| 101 | + assertTrue(functionalParams.contains("version"), "Should track 'version' parameter"); |
| 102 | + } |
| 103 | + |
| 104 | + @Test |
| 105 | + void testBehavioralParametersNotAutoTracked() { |
| 106 | + PluginParameterLoader loader = new PluginParameterLoader(); |
| 107 | + PluginParameterDefinition def = loader.load("maven-compiler-plugin"); |
| 108 | + |
| 109 | + assertNotNull(def); |
| 110 | + |
| 111 | + PluginParameterDefinition.GoalParameterDefinition compileGoal = def.getGoal("compile"); |
| 112 | + assertNotNull(compileGoal); |
| 113 | + |
| 114 | + // Get all behavioral parameter names |
| 115 | + Set<String> behavioralParams = compileGoal.getParameters().values().stream() |
| 116 | + .filter(PluginParameterDefinition.ParameterDefinition::isBehavioral) |
| 117 | + .map(PluginParameterDefinition.ParameterDefinition::getName) |
| 118 | + .collect(Collectors.toSet()); |
| 119 | + |
| 120 | + // Verify behavioral parameters exist in the definition |
| 121 | + assertTrue(behavioralParams.contains("verbose"), "Definition should include 'verbose' as behavioral"); |
| 122 | + assertTrue(behavioralParams.contains("fork"), "Definition should include 'fork' as behavioral"); |
| 123 | + |
| 124 | + // Note: The auto-generation logic in CacheConfigImpl.generateReconciliationFromParameters() |
| 125 | + // filters to only include functional parameters, so behavioral ones won't be tracked |
| 126 | + } |
| 127 | +} |
0 commit comments