Skip to content

Commit 7da52c3

Browse files
oldhenGlenn
andauthored
Fixes condition-activated profiles not considered in effective model (#481)
* Fixes condition-activated profiles not considered in effective model Fixes #91, #244, #316 Signed-off-by: Glenn <[email protected]> Co-authored-by: Glenn <[email protected]>
1 parent 7680ed4 commit 7da52c3

File tree

3 files changed

+76
-3
lines changed

3 files changed

+76
-3
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>org.codehaus.mojo.flatten.its</groupId>
6+
<artifactId>profile-with-conditional-depMgmt</artifactId>
7+
<version>0.1-SNAPSHOT</version>
8+
9+
<dependencies>
10+
<dependency>
11+
<groupId>jakarta.json</groupId>
12+
<artifactId>jakarta.json-api</artifactId>
13+
</dependency>
14+
</dependencies>
15+
16+
<profiles>
17+
<profile>
18+
<activation>
19+
<file>
20+
<missing>file-does-not-exist</missing>
21+
</file>
22+
</activation>
23+
<dependencyManagement>
24+
<dependencies>
25+
<dependency>
26+
<groupId>jakarta.json</groupId>
27+
<artifactId>jakarta.json-api</artifactId>
28+
<version>2.1.3</version>
29+
</dependency>
30+
</dependencies>
31+
</dependencyManagement>
32+
</profile>
33+
</profiles>
34+
</project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
import groovy.xml.XmlSlurper
20+
21+
File originalPom = new File( basedir, 'pom.xml' )
22+
assert originalPom.exists()
23+
24+
def originalProject = new XmlSlurper().parse( originalPom )
25+
assert 1 == originalProject.dependencies.size()
26+
assert 1 == originalProject.dependencies[0].dependency.size()
27+
assert originalProject.dependencies[0].dependency[0].version.empty
28+
29+
File flattendPom = new File( basedir, '.flattened-pom.xml' )
30+
assert flattendPom.exists()
31+
32+
def flattendProject = new XmlSlurper().parse( flattendPom )
33+
assert 1 == flattendProject.dependencies.size()
34+
assert 1 == flattendProject.dependencies[0].dependency.size()
35+
assert 1 == flattendProject.dependencies[0].dependency[0].version.size()
36+
assert '2.1.3' == flattendProject.dependencies[0].dependency[0].version[0].text()
37+

src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
import org.apache.maven.model.interpolation.ModelInterpolator;
6767
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
6868
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
69-
import org.apache.maven.model.profile.DefaultProfileSelector;
7069
import org.apache.maven.model.profile.ProfileInjector;
70+
import org.apache.maven.model.profile.ProfileSelector;
7171
import org.apache.maven.plugin.MojoExecution;
7272
import org.apache.maven.plugin.MojoExecutionException;
7373
import org.apache.maven.plugin.MojoFailureException;
@@ -416,6 +416,9 @@ public class FlattenMojo extends AbstractFlattenMojo {
416416
@Inject
417417
private RepositorySystem repositorySystem;
418418

419+
@Inject
420+
private ProfileSelector profileSelector;
421+
419422
/**
420423
* The constructor.
421424
*/
@@ -963,8 +966,7 @@ protected Model createEffectivePomImpl(ModelBuildingRequest buildingRequest) thr
963966
}
964967
};
965968

966-
buildingResult = modelBuilderThreadSafetyWorkaround.build(
967-
buildingRequest, customInjector, new DefaultProfileSelector());
969+
buildingResult = modelBuilderThreadSafetyWorkaround.build(buildingRequest, customInjector, profileSelector);
968970
} catch (ModelBuildingException e) {
969971
throw new MojoExecutionException(e.getMessage(), e);
970972
}

0 commit comments

Comments
 (0)