Skip to content

Commit 8bec93c

Browse files
authored
Merge pull request wildfly#6730 from darranl/WFCORE-7569
[WFCORE-7569] Skip additional activation types when parsing the profiles.
2 parents 957cae1 + fe583cd commit 8bec93c

3 files changed

Lines changed: 186 additions & 0 deletions

File tree

model-test/src/main/java/org/jboss/as/model/test/MavenSettings.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ private static void parseProfile(final XMLStreamReader reader, MavenSettings mav
243243
activeByDefault = Boolean.parseBoolean(reader.getElementText());
244244
break;
245245
}
246+
default: {
247+
skip(reader);
248+
}
246249
}
247250
} else {
248251
break;

model-test/src/test/java/org/jboss/as/model/test/MavenSettingsTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,33 @@ public void testServersConfig() throws Exception {
113113
Assert.assertFalse(settings.getServers().containsKey("non-authenticated-repo"));
114114
}
115115

116+
@Test
117+
public void testActivationTypes() throws Exception {
118+
MavenSettings settings = new MavenSettings();
119+
MavenSettings.parseSettingsXml(Paths.get(MavenSettingsTest.class.getResource("settings-with-various-activations.xml").toURI()), settings);
120+
settings.resolveActiveSettings();
121+
122+
List<String> repoIds = settings.getRemoteRepositories().stream()
123+
.map(MavenSettings.Repository::getId)
124+
.toList();
125+
126+
// Only profiles with activeByDefault=true should be activated
127+
Assert.assertTrue("active-repo should be present (activeByDefault=true)", repoIds.contains("active-repo"));
128+
Assert.assertTrue("mixed-repo should be present (activeByDefault=true)", repoIds.contains("mixed-repo"));
129+
130+
// Profiles with other activation types should NOT be activated
131+
Assert.assertFalse("property-repo should not be present (property activation)", repoIds.contains("property-repo"));
132+
Assert.assertFalse("jdk-repo should not be present (jdk activation)", repoIds.contains("jdk-repo"));
133+
Assert.assertFalse("os-repo should not be present (os activation)", repoIds.contains("os-repo"));
134+
Assert.assertFalse("file-repo should not be present (file activation)", repoIds.contains("file-repo"));
135+
Assert.assertFalse("not-active-repo should not be present (activeByDefault=false)", repoIds.contains("not-active-repo"));
136+
Assert.assertFalse("property-name-repo should not be present (property name only)", repoIds.contains("property-name-repo"));
137+
Assert.assertFalse("file-missing-repo should not be present (file missing activation)", repoIds.contains("file-missing-repo"));
138+
139+
// central should always be present (default)
140+
Assert.assertTrue("central should always be present", repoIds.contains("central"));
141+
}
142+
116143
/**
117144
* testing is snapshot resolving works properly, as in case of snapshot version, we need to use different path than exact version.
118145
* @throws Exception
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright The WildFly Authors
4+
~ SPDX-License-Identifier: Apache-2.0
5+
-->
6+
7+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
8+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
10+
11+
<profiles>
12+
<!-- Profile with property activation - should NOT activate -->
13+
<profile>
14+
<id>property-activated</id>
15+
<activation>
16+
<property>
17+
<name>quickstart</name>
18+
<value>true</value>
19+
</property>
20+
</activation>
21+
<repositories>
22+
<repository>
23+
<id>property-repo</id>
24+
<url>https://example.org/property-repo/</url>
25+
</repository>
26+
</repositories>
27+
</profile>
28+
29+
<!-- Profile with jdk activation - should NOT activate -->
30+
<profile>
31+
<id>jdk-activated</id>
32+
<activation>
33+
<jdk>11</jdk>
34+
</activation>
35+
<repositories>
36+
<repository>
37+
<id>jdk-repo</id>
38+
<url>https://example.org/jdk-repo/</url>
39+
</repository>
40+
</repositories>
41+
</profile>
42+
43+
<!-- Profile with os activation - should NOT activate -->
44+
<profile>
45+
<id>os-activated</id>
46+
<activation>
47+
<os>
48+
<name>Linux</name>
49+
<family>unix</family>
50+
<arch>amd64</arch>
51+
<version>5.0</version>
52+
</os>
53+
</activation>
54+
<repositories>
55+
<repository>
56+
<id>os-repo</id>
57+
<url>https://example.org/os-repo/</url>
58+
</repository>
59+
</repositories>
60+
</profile>
61+
62+
<!-- Profile with file activation - should NOT activate -->
63+
<profile>
64+
<id>file-activated</id>
65+
<activation>
66+
<file>
67+
<exists>${basedir}/pom.xml</exists>
68+
</file>
69+
</activation>
70+
<repositories>
71+
<repository>
72+
<id>file-repo</id>
73+
<url>https://example.org/file-repo/</url>
74+
</repository>
75+
</repositories>
76+
</profile>
77+
78+
<!-- Profile with activeByDefault=true - SHOULD activate -->
79+
<profile>
80+
<id>active-by-default</id>
81+
<activation>
82+
<activeByDefault>true</activeByDefault>
83+
</activation>
84+
<repositories>
85+
<repository>
86+
<id>active-repo</id>
87+
<url>https://example.org/active-repo/</url>
88+
</repository>
89+
</repositories>
90+
</profile>
91+
92+
<!-- Profile with activeByDefault=false - should NOT activate -->
93+
<profile>
94+
<id>not-active-by-default</id>
95+
<activation>
96+
<activeByDefault>false</activeByDefault>
97+
</activation>
98+
<repositories>
99+
<repository>
100+
<id>not-active-repo</id>
101+
<url>https://example.org/not-active-repo/</url>
102+
</repository>
103+
</repositories>
104+
</profile>
105+
106+
<!-- Profile with mixed activation (property + activeByDefault) - SHOULD activate -->
107+
<profile>
108+
<id>mixed-activation</id>
109+
<activation>
110+
<activeByDefault>true</activeByDefault>
111+
<property>
112+
<name>env</name>
113+
<value>dev</value>
114+
</property>
115+
</activation>
116+
<repositories>
117+
<repository>
118+
<id>mixed-repo</id>
119+
<url>https://example.org/mixed-repo/</url>
120+
</repository>
121+
</repositories>
122+
</profile>
123+
124+
<!-- Profile with property activation (name only) - should NOT activate -->
125+
<profile>
126+
<id>property-name-only</id>
127+
<activation>
128+
<property>
129+
<name>someProperty</name>
130+
</property>
131+
</activation>
132+
<repositories>
133+
<repository>
134+
<id>property-name-repo</id>
135+
<url>https://example.org/property-name-repo/</url>
136+
</repository>
137+
</repositories>
138+
</profile>
139+
140+
<!-- Profile with file missing activation - should NOT activate -->
141+
<profile>
142+
<id>file-missing-activated</id>
143+
<activation>
144+
<file>
145+
<missing>${basedir}/non-existent-file.txt</missing>
146+
</file>
147+
</activation>
148+
<repositories>
149+
<repository>
150+
<id>file-missing-repo</id>
151+
<url>https://example.org/file-missing-repo/</url>
152+
</repository>
153+
</repositories>
154+
</profile>
155+
</profiles>
156+
</settings>

0 commit comments

Comments
 (0)