Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow recursive profile group references #24327

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -117,7 +117,9 @@ private List<String> expandProfiles(List<String> profiles) {
while (!stack.isEmpty()) {
String current = stack.pop();
expandedProfiles.add(current);
asReversedList(this.groups.get(current)).forEach(stack::push);
List<String> groupProfiles = asReversedList(this.groups.get(current));
groupProfiles.remove(current);
groupProfiles.forEach(stack::push);
}
return asUniqueItemList(StringUtils.toStringArray(expandedProfiles));
}
Expand All @@ -128,7 +130,7 @@ private List<String> asReversedList(List<String> list) {
}
List<String> reversed = new ArrayList<>(list);
Collections.reverse(reversed);
return Collections.unmodifiableList(reversed);
return reversed;
Copy link
Contributor Author

@dreis2211 dreis2211 Dec 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, we could do a stream/filter approach, but the unmodifiable list seemed not needed as the result is only used above and cannot be modified from the outside.

}

private List<String> asUniqueItemList(String[] array) {
Expand Down
Expand Up @@ -359,4 +359,15 @@ void isAcceptedWhenNoActiveAndDefaultWithGroupsContainsProfileReturnsTrue() {
assertThat(profiles.isAccepted("x")).isTrue();
}

@Test
void recursiveReferenceInProfileGroupIsIgnored() {
MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.profiles.active", "a,b,c");
environment.setProperty("spring.profiles.group.a", "a,e,f");
environment.setProperty("spring.profiles.group.e", "x,y");
Binder binder = Binder.get(environment);
Profiles profiles = new Profiles(environment, binder, null);
assertThat(profiles).containsExactly("a", "e", "x", "y", "f", "b", "c");
}

}