Skip to content

Commit db62c8c

Browse files
Gerd Aschemanngnodet
andcommitted
[#12288] Backport ITs for settings.xml profile -> LRM property propagation
Ports the integration tests added on apache/maven master via #12297 and #12298 to the apache/maven-integration-testing maven-3.10.x branch. Covers three settings.xml-only activation channels: * testActiveByDefaultProfile -- guards <activation><activeByDefault> * testActiveProfilesList -- guards <activeProfiles><activeProfile> (already worked on 3.x, regression guard) * testActiveByDefaultDeactivatedViaCli -- guards that -P !profileId still deactivates an activeByDefault profile Adaptations from master: * java.io.File API instead of java.nio.file.Path * Verifier from org.apache.maven.shared.verifier (3.x package) * ResourceExtractor.simpleExtractResources for fixture extraction * JUnit 4-style assertions inherited from AbstractMavenIntegrationTestCase * Resource directory uses 3.x gh-NNNN convention * Version constraint super("[3.10.0-SNAPSHOT,)") so the IT only runs once the backport (apache/maven PR #12333) lands. Master origin commits: * 7725eaf25ab2715b26848fa56d3f0416862e83cb (initial 2 ITs) * 578523519a33a78a651c472bb07d312e01b1e521 (rename + activeByDefault fix) * 22f9a0ee086a464f2bfa757ecd0a32053f3d1e8d (squashed merge of #12298, adds testActiveByDefaultDeactivatedViaCli) Co-Authored-By: Guillaume Nodet <gnodet@gmail.com>
1 parent e560338 commit db62c8c

4 files changed

Lines changed: 268 additions & 0 deletions

File tree

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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.it;
20+
21+
import java.io.File;
22+
import java.io.IOException;
23+
import java.nio.file.Files;
24+
import java.nio.file.Path;
25+
import java.util.Comparator;
26+
27+
import org.apache.maven.shared.verifier.Verifier;
28+
import org.apache.maven.shared.verifier.util.ResourceExtractor;
29+
import org.junit.jupiter.api.Test;
30+
31+
/**
32+
* Integration tests proving that {@code aether.*} properties declared in the
33+
* {@code <properties>} block of a {@code settings.xml} profile are honored
34+
* by the resolver at local repository manager initialization, regardless of
35+
* which settings.xml-only activation channel was used.
36+
*
37+
* <p>Two activation channels are covered:
38+
* <ul>
39+
* <li>{@code <activation><activeByDefault>true</activeByDefault></activation>}
40+
* on the profile itself;</li>
41+
* <li>{@code <activeProfiles><activeProfile>...</activeProfile></activeProfiles>}
42+
* at the top of {@code settings.xml}.</li>
43+
* </ul>
44+
*
45+
* <p>In both cases the same profile sets:
46+
* <pre>
47+
* aether.enhancedLocalRepository.split = true
48+
* aether.enhancedLocalRepository.localPrefix = it-custom-prefix
49+
* </pre>
50+
* and the test asserts that {@code mvn install} writes the installed pom
51+
* under {@code <localRepo>/it-custom-prefix/&lt;groupId-path&gt;/...} rather
52+
* than the flat or default-split layout.
53+
*
54+
* <p>A third test ({@code testActiveByDefaultDeactivatedViaCli}) guards
55+
* that {@code -P !profileId} still deactivates an {@code <activeByDefault>}
56+
* profile, so its {@code <properties>} are NOT merged into the resolver
57+
* session config.
58+
*
59+
* <p>Backport target: requires the fix from apache/maven PR #12333 to be
60+
* present in the running Maven 3.10.x build.
61+
*/
62+
public class MavenITgh12288SettingsProfileAetherPropertiesTest extends AbstractMavenIntegrationTestCase {
63+
64+
public MavenITgh12288SettingsProfileAetherPropertiesTest() {
65+
super("[3.10.0-SNAPSHOT,)");
66+
}
67+
68+
@Test
69+
public void testActiveByDefaultProfile() throws Exception {
70+
runAndAssertCustomPrefix("settings-active-by-default.xml");
71+
}
72+
73+
@Test
74+
public void testActiveProfilesList() throws Exception {
75+
runAndAssertCustomPrefix("settings-active-profiles-list.xml");
76+
}
77+
78+
@Test
79+
public void testActiveByDefaultDeactivatedViaCli() throws Exception {
80+
File testDir = ResourceExtractor.simpleExtractResources(
81+
getClass(), "/gh-12288-settings-profile-aether-properties");
82+
83+
Verifier verifier = newVerifier(testDir.getAbsolutePath());
84+
verifier.setAutoclean(false);
85+
verifier.setLogFileName("log-deactivation.txt");
86+
verifier.deleteDirectory("target");
87+
verifier.deleteArtifacts("org.apache.maven.its.settings.profile.aether");
88+
89+
File customPrefixSubtree = new File(verifier.getLocalRepository(), "it-custom-prefix");
90+
deleteRecursivelyIfExists(customPrefixSubtree);
91+
92+
verifier.addCliArgument("--settings");
93+
verifier.addCliArgument("settings-active-by-default.xml");
94+
verifier.addCliArgument("-P!aether-split-via-settings");
95+
verifier.addCliArgument("install");
96+
verifier.execute();
97+
verifier.verifyErrorFreeLog();
98+
99+
String localRepo = verifier.getLocalRepository();
100+
String gavRelativePath = "org/apache/maven/its/settings/profile/aether/test-artifact/1.0/test-artifact-1.0.pom";
101+
File flatLayout = new File(localRepo, gavRelativePath);
102+
File customPrefix = new File(localRepo, "it-custom-prefix/" + gavRelativePath);
103+
104+
assertTrue(
105+
"Expected artifact at flat layout (profile deactivated via -P !), but not found at " + flatLayout,
106+
flatLayout.exists());
107+
108+
assertFalse(
109+
"Found artifact at custom prefix " + customPrefix + " - deactivation via -P ! was ignored.",
110+
customPrefix.exists());
111+
}
112+
113+
private void runAndAssertCustomPrefix(String settingsFile) throws Exception {
114+
File testDir = ResourceExtractor.simpleExtractResources(
115+
getClass(), "/gh-12288-settings-profile-aether-properties");
116+
117+
Verifier verifier = newVerifier(testDir.getAbsolutePath());
118+
verifier.setAutoclean(false);
119+
verifier.deleteDirectory("target");
120+
verifier.deleteArtifacts("org.apache.maven.its.settings.profile.aether");
121+
122+
File customPrefixSubtree = new File(verifier.getLocalRepository(), "it-custom-prefix");
123+
deleteRecursivelyIfExists(customPrefixSubtree);
124+
125+
verifier.addCliArgument("--settings");
126+
verifier.addCliArgument(settingsFile);
127+
verifier.addCliArgument("install");
128+
verifier.execute();
129+
verifier.verifyErrorFreeLog();
130+
131+
String localRepo = verifier.getLocalRepository();
132+
String gavRelativePath = "org/apache/maven/its/settings/profile/aether/test-artifact/1.0/test-artifact-1.0.pom";
133+
134+
File expectedAtCustomPrefix = new File(localRepo, "it-custom-prefix/" + gavRelativePath);
135+
File flatLayout = new File(localRepo, gavRelativePath);
136+
File defaultSplitPrefix = new File(localRepo, "installed/" + gavRelativePath);
137+
138+
assertTrue(
139+
"Expected install to use custom localPrefix 'it-custom-prefix' from "
140+
+ settingsFile
141+
+ ", but artifact not found at "
142+
+ expectedAtCustomPrefix,
143+
expectedAtCustomPrefix.exists());
144+
145+
assertFalse(
146+
"Found artifact at flat layout "
147+
+ flatLayout
148+
+ " - indicates the settings.xml profile properties did not reach the resolver"
149+
+ " session config in time for LRM init.",
150+
flatLayout.exists());
151+
152+
assertFalse(
153+
"Found artifact at default split-LRM prefix "
154+
+ defaultSplitPrefix
155+
+ " - indicates split=true was honored but localPrefix was silently dropped.",
156+
defaultSplitPrefix.exists());
157+
}
158+
159+
private static void deleteRecursivelyIfExists(File dir) throws IOException {
160+
if (!dir.exists()) {
161+
return;
162+
}
163+
Path root = dir.toPath();
164+
try (java.util.stream.Stream<Path> walk = Files.walk(root)) {
165+
walk.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
166+
}
167+
}
168+
}
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
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<groupId>org.apache.maven.its.settings.profile.aether</groupId>
24+
<artifactId>test-artifact</artifactId>
25+
<version>1.0</version>
26+
<packaging>pom</packaging>
27+
28+
<name>Maven Integration Test :: Settings Profile Aether Properties</name>
29+
<description>
30+
Minimal project for proving that aether.enhancedLocalRepository.*
31+
properties set in an active-by-default settings.xml profile are honored
32+
by the resolver at local repository manager initialization.
33+
</description>
34+
</project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0">
21+
<profiles>
22+
<profile>
23+
<id>aether-split-via-settings</id>
24+
<activation>
25+
<activeByDefault>true</activeByDefault>
26+
</activation>
27+
<properties>
28+
<aether.enhancedLocalRepository.split>true</aether.enhancedLocalRepository.split>
29+
<aether.enhancedLocalRepository.localPrefix>it-custom-prefix</aether.enhancedLocalRepository.localPrefix>
30+
</properties>
31+
</profile>
32+
</profiles>
33+
</settings>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0">
21+
<activeProfiles>
22+
<activeProfile>aether-split-via-settings</activeProfile>
23+
</activeProfiles>
24+
<profiles>
25+
<profile>
26+
<id>aether-split-via-settings</id>
27+
<properties>
28+
<aether.enhancedLocalRepository.split>true</aether.enhancedLocalRepository.split>
29+
<aether.enhancedLocalRepository.localPrefix>it-custom-prefix</aether.enhancedLocalRepository.localPrefix>
30+
</properties>
31+
</profile>
32+
</profiles>
33+
</settings>

0 commit comments

Comments
 (0)