Skip to content

Commit

Permalink
[4269] Minimize API change.
Browse files Browse the repository at this point in the history
One method is deprecated.

 #4269
  • Loading branch information
Samuel Cox committed Jul 30, 2024
1 parent c72cc87 commit 910f121
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public List<Profile> activeProfiles(final Iterable<String> userSpecifiedProfiles

final List<Profile> explicitActiveProfiles =
profiles.getProfiles().stream()
.filter(p -> p.isActivated(userSpecifiedProfiles))
.filter(p -> p.isActive(userSpecifiedProfiles))
.collect(Collectors.toList());

// activeByDefault profiles should be active even if they don't exist
Expand Down Expand Up @@ -344,16 +344,11 @@ public static class Profile {
@Nullable
RawRepositories repositories;

@SuppressWarnings("unused")
public boolean isActivated(String... activeProfiles) {
return isActivated(Arrays.asList(activeProfiles));
}

/**
* Returns true if this profile was activated either by the supplied active profiles
* or by activation property, <i>but not solely by activeByDefault</i>.
*/
boolean isActivated(Iterable<String> activeProfiles) {
public boolean isActive(Iterable<String> activeProfiles) {
if (getId() != null) {
for (String activeProfile : activeProfiles) {
if (activeProfile.trim().equals(getId())) {
Expand All @@ -363,6 +358,11 @@ boolean isActivated(Iterable<String> activeProfiles) {
}
return getActivation() != null && getActivation().isActive();
}

@SuppressWarnings("unused")
public boolean isActive(String... activeProfiles) {
return isActive(Arrays.asList(activeProfiles));
}
}

@FieldDefaults(level = AccessLevel.PRIVATE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public List<MavenRepository> getEffectiveRepositories() {
public List<Profile> activeProfiles(final Iterable<String> userSpecifiedProfiles) {
final List<Profile> explicitActiveProfiles =
getProfiles().stream()
.filter(p -> p.isActivated(userSpecifiedProfiles))
.filter(p -> p.isActive(userSpecifiedProfiles))
.collect(Collectors.toList());

// activeByDefault profiles should be active even if they don't exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class Profile {
* Returns true if this profile was activated either by the supplied active profiles
* or by activation property, <i>but not solely by activeByDefault</i>.
*/
boolean isActivated(Iterable<String> activeProfiles) {
public boolean isActive(Iterable<String> activeProfiles) {
if (getId() != null) {
for (String activeProfile : activeProfiles) {
if (activeProfile.trim().equals(getId())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,29 @@ public class ProfileActivation {
@Nullable
Property property;

// TODO rename these as well?
/**
* Determines the supplied profile `id` should be considered active
* given the other parameters.
*
* @deprecated use {@link Profile#isActive(Iterable)}
*/
@Deprecated
public static boolean isActive(@Nullable String id, Iterable<String> activeProfiles,
@Nullable ProfileActivation activation) {
if (id != null) {
for (String activeProfile : activeProfiles) {
if (activeProfile.trim().equals(id)) {
return true;
}
}
}
return activation != null &&
(activation.isActive() ||
// Active by default is *only* enabled when no other profile is marked active by any other mechanism
// So even this check for any other explicit activation is overly broad
(Boolean.TRUE.equals(activation.getActiveByDefault()) && !activeProfiles.iterator().hasNext()));
}

public boolean isActive() {
return isActiveByJdk() || isActiveByProperty();
}
Expand Down

0 comments on commit 910f121

Please sign in to comment.