Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import org.apache.maven.api.di.Named;
import org.apache.maven.api.di.Singleton;
import org.apache.maven.api.model.Activation;
import org.apache.maven.api.model.ActivationFile;
import org.apache.maven.api.model.Dependency;
import org.apache.maven.api.model.DependencyManagement;
import org.apache.maven.api.model.Exclusion;
Expand All @@ -71,7 +70,6 @@
import org.apache.maven.api.services.BuilderProblem;
import org.apache.maven.api.services.BuilderProblem.Severity;
import org.apache.maven.api.services.Interpolator;
import org.apache.maven.api.services.InterpolatorException;
import org.apache.maven.api.services.MavenException;
import org.apache.maven.api.services.ModelBuilder;
import org.apache.maven.api.services.ModelBuilderException;
Expand Down Expand Up @@ -111,7 +109,6 @@
import org.apache.maven.api.spi.ModelParserException;
import org.apache.maven.api.spi.ModelTransformer;
import org.apache.maven.impl.util.PhasingExecutor;
import org.apache.maven.model.v4.MavenTransformer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -1174,11 +1171,8 @@ private Model readEffectiveModel() throws ModelBuilderException {
// profile activation
profileActivationContext.setModel(model);

List<Profile> interpolatedProfiles =
interpolateActivations(model.getProfiles(), profileActivationContext, this);

// profile injection
List<Profile> activePomProfiles = getActiveProfiles(interpolatedProfiles, profileActivationContext);
List<Profile> activePomProfiles = getActiveProfiles(model.getProfiles(), profileActivationContext);
model = profileInjector.injectProfiles(model, activePomProfiles, request, this);
model = profileInjector.injectProfiles(model, activeExternalProfiles, request, this);

Expand Down Expand Up @@ -1505,11 +1499,8 @@ protected void mergeModel_Subprojects(
.assembleModelInheritance(raw, parentData, request, this);

// activate profiles
List<Profile> parentInterpolatedProfiles =
interpolateActivations(parent.getProfiles(), profileActivationContext, this);
List<Profile> parentActivePomProfiles = getActiveProfiles(parent.getProfiles(), profileActivationContext);
// profile injection
List<Profile> parentActivePomProfiles =
getActiveProfiles(parentInterpolatedProfiles, profileActivationContext);
Model injectedParentModel = profileInjector
.injectProfiles(parent, parentActivePomProfiles, request, this)
.withProfiles(List.of());
Expand Down Expand Up @@ -1741,79 +1732,6 @@ boolean isBuildRequestWithActivation() {
return request.getRequestType() != ModelBuilderRequest.RequestType.BUILD_CONSUMER;
}

private List<Profile> interpolateActivations(
List<Profile> profiles, DefaultProfileActivationContext context, ModelProblemCollector problems) {
if (profiles.stream()
.map(org.apache.maven.api.model.Profile::getActivation)
.noneMatch(Objects::nonNull)) {
return profiles;
}
Interpolator interpolator = request.getSession().getService(Interpolator.class);

class ProfileInterpolator extends MavenTransformer implements UnaryOperator<Profile> {
ProfileInterpolator() {
super(s -> {
try {
return interpolator.interpolate(
s, Interpolator.chain(context::getUserProperty, context::getSystemProperty));
} catch (InterpolatorException e) {
problems.add(Severity.ERROR, Version.BASE, e.getMessage(), e);
}
return s;
});
}

@Override
public Profile apply(Profile p) {
return Profile.newBuilder(p)
.activation(transformActivation(p.getActivation()))
.build();
}

@Override
protected Activation.Builder transformActivation_Condition(
Supplier<? extends Activation.Builder> creator, Activation.Builder builder, Activation target) {
// do not interpolate the condition activation
return builder;
}

@Override
protected ActivationFile.Builder transformActivationFile_Missing(
Supplier<? extends ActivationFile.Builder> creator,
ActivationFile.Builder builder,
ActivationFile target) {
String path = target.getMissing();
String xformed = transformPath(path, target, "missing");
return xformed != path ? (builder != null ? builder : creator.get()).missing(xformed) : builder;
}

@Override
protected ActivationFile.Builder transformActivationFile_Exists(
Supplier<? extends ActivationFile.Builder> creator,
ActivationFile.Builder builder,
ActivationFile target) {
final String path = target.getExists();
final String xformed = transformPath(path, target, "exists");
return xformed != path ? (builder != null ? builder : creator.get()).exists(xformed) : builder;
}

private String transformPath(String path, ActivationFile target, String locationKey) {
try {
return context.interpolatePath(path);
} catch (InterpolatorException e) {
problems.add(
Severity.ERROR,
Version.BASE,
"Failed to interpolate file location " + path + ": " + e.getMessage(),
target.getLocation(locationKey),
e);
}
return path;
}
}
return profiles.stream().map(new ProfileInterpolator()).toList();
}

record ModelResolverResult(ModelSource source, String resolvedVersion) {}

class CachingModelResolver implements ModelResolver {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.it;

import java.nio.file.Path;

import org.junit.jupiter.api.Test;

/**
* This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-8477">MNG-8477</a>.
*/
class MavenITmng8477MultithreadedFileActivationTest extends AbstractMavenIntegrationTestCase {

MavenITmng8477MultithreadedFileActivationTest() {
super("[4.0.0-rc-3-SNAPSHOT,)");
}

/**
* Verify project is buildable.
*/
@Test
void testIt() throws Exception {
Path basedir = extractResources("/mng-8477").getAbsoluteFile().toPath();

Verifier verifier = newVerifier(basedir.toString());
verifier.addCliArguments("help:active-profiles", "-Dmaven.modelBuilder.parallelism=1");
verifier.execute();
verifier.verifyErrorFreeLog();

verifier.verifyTextInLog("- xxx (source: test:m2:jar:1)");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public TestSuiteOrdering() {
* the tests are to finishing. Newer tests are also more likely to fail, so this is
* a fail fast technique as well.
*/
suite.addTestSuite(MavenITmng8477MultithreadedFileActivationTest.class);
suite.addTestSuite(MavenITmng8469InterpolationPrecendenceTest.class);
suite.addTestSuite(MavenITmng8461SpySettingsEventTest.class);
suite.addTestSuite(MavenITmng8414ConsumerPomWithNewFeaturesTest.class);
Expand Down
11 changes: 11 additions & 0 deletions its/core-it-suite/src/test/resources/mng-8477/m1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>test</groupId>
<artifactId>project</artifactId>
<version>1</version>
</parent>
<groupId>test</groupId>
<artifactId>m1</artifactId>
</project>
11 changes: 11 additions & 0 deletions its/core-it-suite/src/test/resources/mng-8477/m2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>test</groupId>
<artifactId>project</artifactId>
<version>1</version>
</parent>
<groupId>test</groupId>
<artifactId>m2</artifactId>
</project>
Empty file.
29 changes: 29 additions & 0 deletions its/core-it-suite/src/test/resources/mng-8477/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>project</artifactId>
<version>1</version>
<packaging>pom</packaging>
<modules>
<module>m1</module>
<module>m2</module>
</modules>
<profiles>
<profile>
<id>xxx</id>
<activation>
<file>
<exists>src/io.properties</exists>
</file>
</activation>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.0</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Loading