Skip to content

Commit 0136c97

Browse files
committed
Add integration tests and fix default reconciliation merging
Addresses reviewer feedback on PR apache#389: 1. Add integration tests for default reconciliation behavior: - Test with no executionControl configuration (uses defaults) - Test with executionControl for different plugin (verifies merging) 2. Fix reconciliation config resolution to merge defaults with explicit config: - Explicit configs take precedence when present - Default reconciliation configs apply when no explicit config exists - Ensures compiler defaults work even when other plugins are configured 3. Add null safety checks to prevent NPE in unit tests: - Check for null mojoExecution before accessing - Check for null plugin before matching Integration tests verify that: - Changing maven.compiler.release invalidates cache as expected - Changing maven.compiler.source/target invalidates cache - Default reconciliation still applies when executionControl configures other plugins
1 parent e99c008 commit 0136c97

File tree

10 files changed

+374
-11
lines changed

10 files changed

+374
-11
lines changed

src/main/java/org/apache/maven/buildcache/xml/CacheConfigImpl.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,23 +248,36 @@ public boolean isLogAllProperties(MojoExecution mojoExecution) {
248248
}
249249

250250
private GoalReconciliation findReconciliationConfig(MojoExecution mojoExecution) {
251-
List<GoalReconciliation> reconciliation;
251+
if (mojoExecution == null) {
252+
return null;
253+
}
252254

253-
if (cacheConfig.getExecutionControl() == null || cacheConfig.getExecutionControl().getReconcile() == null) {
254-
// Use default reconciliation configs for common plugins
255-
reconciliation = getDefaultReconciliationConfigs();
256-
} else {
257-
reconciliation = cacheConfig.getExecutionControl().getReconcile().getPlugins();
255+
final String goal = mojoExecution.getGoal();
256+
final Plugin plugin = mojoExecution.getPlugin();
257+
258+
if (plugin == null) {
259+
return null;
258260
}
259261

260-
for (GoalReconciliation goalReconciliationConfig : reconciliation) {
261-
final String goal = mojoExecution.getGoal();
262+
// First check explicit configuration
263+
if (cacheConfig.getExecutionControl() != null && cacheConfig.getExecutionControl().getReconcile() != null) {
264+
List<GoalReconciliation> explicitConfigs =
265+
cacheConfig.getExecutionControl().getReconcile().getPlugins();
266+
for (GoalReconciliation config : explicitConfigs) {
267+
if (isPluginMatch(plugin, config) && Strings.CS.equals(goal, config.getGoal())) {
268+
return config;
269+
}
270+
}
271+
}
262272

263-
if (isPluginMatch(mojoExecution.getPlugin(), goalReconciliationConfig)
264-
&& Strings.CS.equals(goal, goalReconciliationConfig.getGoal())) {
265-
return goalReconciliationConfig;
273+
// Fall back to defaults if no explicit configuration found
274+
List<GoalReconciliation> defaults = getDefaultReconciliationConfigs();
275+
for (GoalReconciliation config : defaults) {
276+
if (isPluginMatch(plugin, config) && Strings.CS.equals(goal, config.getGoal())) {
277+
return config;
266278
}
267279
}
280+
268281
return null;
269282
}
270283

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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.its;
20+
21+
import java.io.IOException;
22+
import java.util.Arrays;
23+
24+
import org.apache.maven.buildcache.its.junit.IntegrationTest;
25+
import org.apache.maven.it.VerificationException;
26+
import org.apache.maven.it.Verifier;
27+
import org.junit.jupiter.api.Test;
28+
29+
/**
30+
* Test that default reconciliation configs are applied when no executionControl is configured.
31+
* Verifies that compiler properties (source, target, release) are tracked by default.
32+
*/
33+
@IntegrationTest("src/test/projects/default-reconciliation")
34+
class DefaultReconciliationTest {
35+
36+
@Test
37+
void testDefaultReconciliationWithNoConfig(Verifier verifier) throws VerificationException, IOException {
38+
verifier.setAutoclean(false);
39+
40+
// First build with release=17
41+
verifier.setLogFileName("../log-build1.txt");
42+
verifier.setSystemProperty("maven.compiler.release", "17");
43+
verifier.executeGoal("verify");
44+
verifier.verifyErrorFreeLog();
45+
verifier.verifyTextInLog("Saved Build to local file");
46+
47+
// Second build with same release=17 should hit cache
48+
verifier.setLogFileName("../log-build2.txt");
49+
verifier.setSystemProperty("maven.compiler.release", "17");
50+
verifier.executeGoals(Arrays.asList("clean", "verify"));
51+
verifier.verifyErrorFreeLog();
52+
verifier.verifyTextInLog("Found cached build");
53+
54+
// Third build with different release=21 should NOT hit cache (invalidated by default reconciliation)
55+
verifier.setLogFileName("../log-build3.txt");
56+
verifier.setSystemProperty("maven.compiler.release", "21");
57+
verifier.executeGoals(Arrays.asList("clean", "verify"));
58+
verifier.verifyErrorFreeLog();
59+
verifier.verifyTextInLog("Local build was not found");
60+
}
61+
62+
@Test
63+
void testDefaultReconciliationWithSourceTarget(Verifier verifier) throws VerificationException, IOException {
64+
verifier.setAutoclean(false);
65+
66+
// First build with source=11, target=11
67+
verifier.setLogFileName("../log-source1.txt");
68+
verifier.setSystemProperty("maven.compiler.source", "11");
69+
verifier.setSystemProperty("maven.compiler.target", "11");
70+
verifier.executeGoal("verify");
71+
verifier.verifyErrorFreeLog();
72+
verifier.verifyTextInLog("Saved Build to local file");
73+
74+
// Second build with different target=17 should NOT hit cache
75+
verifier.setLogFileName("../log-source2.txt");
76+
verifier.setSystemProperty("maven.compiler.source", "11");
77+
verifier.setSystemProperty("maven.compiler.target", "17");
78+
verifier.executeGoals(Arrays.asList("clean", "verify"));
79+
verifier.verifyErrorFreeLog();
80+
verifier.verifyTextInLog("Local build was not found");
81+
}
82+
}
83+
84+
/**
85+
* Test that default reconciliation configs are still applied when executionControl exists
86+
* but configures a different plugin. Ensures defaults and explicit configs are merged.
87+
*/
88+
@IntegrationTest("src/test/projects/default-reconciliation-with-other-plugin")
89+
class DefaultReconciliationWithOtherPluginTest {
90+
91+
@Test
92+
void testDefaultReconciliationMergesWithExplicitConfig(Verifier verifier)
93+
throws VerificationException, IOException {
94+
verifier.setAutoclean(false);
95+
96+
// First build with release=17
97+
verifier.setLogFileName("../log-merge1.txt");
98+
verifier.setSystemProperty("maven.compiler.release", "17");
99+
verifier.executeGoal("verify");
100+
verifier.verifyErrorFreeLog();
101+
verifier.verifyTextInLog("Saved Build to local file");
102+
103+
// Second build with release=21 should NOT hit cache
104+
// (defaults should still apply even though executionControl configures surefire)
105+
verifier.setLogFileName("../log-merge2.txt");
106+
verifier.setSystemProperty("maven.compiler.release", "21");
107+
verifier.executeGoals(Arrays.asList("clean", "verify"));
108+
verifier.verifyErrorFreeLog();
109+
verifier.verifyTextInLog("Local build was not found");
110+
}
111+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
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, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<extensions>
19+
<extension>
20+
<groupId>org.apache.maven.extensions</groupId>
21+
<artifactId>maven-build-cache-extension</artifactId>
22+
<version>@project.version@</version>
23+
</extension>
24+
</extensions>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
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, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<cache xmlns="http://maven.apache.org/BUILD-CACHE-CONFIG/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/BUILD-CACHE-CONFIG/1.0.0 https://maven.apache.org/xsd/build-cache-config-1.0.0.xsd">
20+
<configuration>
21+
<!-- Has executionControl but only for surefire plugin, not compiler - defaults should still apply -->
22+
<executionControl>
23+
<reconcile>
24+
<plugins>
25+
<plugin artifactId="maven-surefire-plugin">
26+
<reconciles>
27+
<reconcile propertyName="forkCount"/>
28+
</reconciles>
29+
</plugin>
30+
</plugins>
31+
</reconcile>
32+
</executionControl>
33+
</configuration>
34+
</cache>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
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, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<groupId>org.apache.maven.caching.test</groupId>
24+
<artifactId>default-reconciliation</artifactId>
25+
<version>1.0-SNAPSHOT</version>
26+
27+
<properties>
28+
<maven.compiler.source>8</maven.compiler.source>
29+
<maven.compiler.target>8</maven.compiler.target>
30+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
31+
</properties>
32+
33+
<build>
34+
<plugins>
35+
<plugin>
36+
<groupId>org.apache.maven.plugins</groupId>
37+
<artifactId>maven-compiler-plugin</artifactId>
38+
<version>3.11.0</version>
39+
</plugin>
40+
</plugins>
41+
</build>
42+
</project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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;
20+
21+
public class Test {
22+
public static void main(String[] args) {
23+
System.out.println("Default reconciliation test");
24+
}
25+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
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, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<extensions>
19+
<extension>
20+
<groupId>org.apache.maven.extensions</groupId>
21+
<artifactId>maven-build-cache-extension</artifactId>
22+
<version>@project.version@</version>
23+
</extension>
24+
</extensions>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
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, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<cache xmlns="http://maven.apache.org/BUILD-CACHE-CONFIG/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/BUILD-CACHE-CONFIG/1.0.0 https://maven.apache.org/xsd/build-cache-config-1.0.0.xsd">
20+
<configuration>
21+
<!-- No executionControl configuration - should use defaults -->
22+
</configuration>
23+
</cache>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
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, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<groupId>org.apache.maven.caching.test</groupId>
24+
<artifactId>default-reconciliation</artifactId>
25+
<version>1.0-SNAPSHOT</version>
26+
27+
<properties>
28+
<maven.compiler.source>8</maven.compiler.source>
29+
<maven.compiler.target>8</maven.compiler.target>
30+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
31+
</properties>
32+
33+
<build>
34+
<plugins>
35+
<plugin>
36+
<groupId>org.apache.maven.plugins</groupId>
37+
<artifactId>maven-compiler-plugin</artifactId>
38+
<version>3.11.0</version>
39+
</plugin>
40+
</plugins>
41+
</build>
42+
</project>

0 commit comments

Comments
 (0)