From 910f121247d8dcc7d9dcec1f6ef5e1038e385a33 Mon Sep 17 00:00:00 2001 From: Samuel Cox Date: Mon, 29 Jul 2024 19:59:02 -0500 Subject: [PATCH] [4269] Minimize API change. One method is deprecated. #4269 --- .../org/openrewrite/maven/MavenSettings.java | 14 +++++------ .../java/org/openrewrite/maven/tree/Pom.java | 2 +- .../org/openrewrite/maven/tree/Profile.java | 2 +- .../maven/tree/ProfileActivation.java | 24 ++++++++++++++++++- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/MavenSettings.java b/rewrite-maven/src/main/java/org/openrewrite/maven/MavenSettings.java index 34b04963c647..7a6dd94af352 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/MavenSettings.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/MavenSettings.java @@ -91,7 +91,7 @@ public List activeProfiles(final Iterable userSpecifiedProfiles final List 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 @@ -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, but not solely by activeByDefault. */ - boolean isActivated(Iterable activeProfiles) { + public boolean isActive(Iterable activeProfiles) { if (getId() != null) { for (String activeProfile : activeProfiles) { if (activeProfile.trim().equals(getId())) { @@ -363,6 +358,11 @@ boolean isActivated(Iterable activeProfiles) { } return getActivation() != null && getActivation().isActive(); } + + @SuppressWarnings("unused") + public boolean isActive(String... activeProfiles) { + return isActive(Arrays.asList(activeProfiles)); + } } @FieldDefaults(level = AccessLevel.PRIVATE) diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/tree/Pom.java b/rewrite-maven/src/main/java/org/openrewrite/maven/tree/Pom.java index f27fb1e8fa53..f71458e72770 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/tree/Pom.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/tree/Pom.java @@ -159,7 +159,7 @@ public List getEffectiveRepositories() { public List activeProfiles(final Iterable userSpecifiedProfiles) { final List 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 diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/tree/Profile.java b/rewrite-maven/src/main/java/org/openrewrite/maven/tree/Profile.java index 81ecf066fc97..3b860594dd24 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/tree/Profile.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/tree/Profile.java @@ -48,7 +48,7 @@ public class Profile { * Returns true if this profile was activated either by the supplied active profiles * or by activation property, but not solely by activeByDefault. */ - boolean isActivated(Iterable activeProfiles) { + public boolean isActive(Iterable activeProfiles) { if (getId() != null) { for (String activeProfile : activeProfiles) { if (activeProfile.trim().equals(getId())) { diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/tree/ProfileActivation.java b/rewrite-maven/src/main/java/org/openrewrite/maven/tree/ProfileActivation.java index 9479a300d822..518d828e94a7 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/tree/ProfileActivation.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/tree/ProfileActivation.java @@ -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 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(); }