Skip to content
Open
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 @@ -237,10 +237,7 @@ DefaultProfileActivationContext start() {
}

Record stop() {
// only keep keys for which the value is `true`
Objects.requireNonNull(record, "start() must be called before stop()");
record.usedActiveProfiles.values().removeIf(value -> !value);
record.usedInactiveProfiles.values().removeIf(value -> !value);
return new Record(record); // Return immutable copy for thread-safe caching
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -61,6 +62,34 @@ void setup() {
assertNotNull(builder);
}

@Test
public void testParentProfileCacheDistinguishesActiveProfileContexts() {
DefaultProfileActivationContext.Record withoutRelease = recordActiveProfile(List.of(), "release");
DefaultProfileActivationContext.Record withRelease = recordActiveProfile(List.of("release"), "release");

assertFalse(
withoutRelease.matches(newProfileActivationContext(List.of("release"), List.of())),
"a parent assembled without -Prelease must not be reused for a module built with -Prelease");
assertFalse(
withRelease.matches(newProfileActivationContext(List.of(), List.of())),
"a parent assembled with -Prelease must not be reused for a module built without it");
assertTrue(withoutRelease.matches(newProfileActivationContext(List.of(), List.of())));
assertTrue(withRelease.matches(newProfileActivationContext(List.of("release"), List.of())));
}

@Test
public void testParentProfileCacheDistinguishesInactiveProfileContexts() {
DefaultProfileActivationContext recording =
newProfileActivationContext(List.of(), List.of()).start();
recording.isProfileInactive("release");
DefaultProfileActivationContext.Record withoutSuppression = recording.stop();

assertFalse(
withoutSuppression.matches(newProfileActivationContext(List.of(), List.of("release"))),
"a parent assembled without -!release must not be reused for a module built with -!release");
assertTrue(withoutSuppression.matches(newProfileActivationContext(List.of(), List.of())));
}

@Test
public void testPropertiesAndProfiles() {
ModelBuilderRequest request = ModelBuilderRequest.builder()
Expand Down Expand Up @@ -518,6 +547,20 @@ public void testBomDependencyManagementVersionInference() {
"1.0-SNAPSHOT", managedDep.getVersion(), "Version should be inferred from the reactor sibling module");
}

private static DefaultProfileActivationContext.Record recordActiveProfile(
List<String> activeIds, String profileId) {
DefaultProfileActivationContext recording =
newProfileActivationContext(activeIds, List.of()).start();
recording.isProfileActive(profileId);
return recording.stop();
}

private static DefaultProfileActivationContext newProfileActivationContext(
List<String> activeIds, List<String> inactiveIds) {
return new DefaultProfileActivationContext(
null, null, null, activeIds, inactiveIds, Map.of(), Map.of(), Model.newInstance());
}

private Path getPom(String name) {
return Paths.get("src/test/resources/poms/factory/" + name + ".xml").toAbsolutePath();
}
Expand Down