[MNG-8588] Add activated profiles to Project interface#2132
[MNG-8588] Add activated profiles to Project interface#2132gnodet merged 6 commits intoapache:masterfrom
Conversation
|
@Giovds I went ahead and added the |
impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProject.java
Outdated
Show resolved
Hide resolved
| /** | ||
| * Returns all profiles defined in this project. | ||
| * <p> | ||
| * This method returns only the profiles defined directly in the current project's POM | ||
| * and does not include profiles from parent projects. | ||
| * | ||
| * @return a non-null, possibly empty list of profiles defined in this project | ||
| * @see Profile | ||
| * @see #getAllProfiles() | ||
| */ | ||
| @Nonnull | ||
| List<Profile> getProfiles(); | ||
|
|
||
| /** | ||
| * Returns all profiles defined in this project and all of its parent projects. | ||
| * <p> | ||
| * This method traverses the parent hierarchy and includes profiles defined in parent POMs. | ||
| * The returned list contains profiles from the current project and all of its ancestors in | ||
| * the project inheritance chain. | ||
| * | ||
| * @return a non-null, possibly empty list of all profiles from this project and its parents | ||
| * @see Profile | ||
| * @see #getProfiles() | ||
| */ | ||
| @Nonnull | ||
| List<Profile> getAllProfiles(); |
There was a problem hiding this comment.
I'm trying to think of a different name for the getAll(Active)Profiles() methods, as it might be interpreted the same as getProfiles(). I was thinking something alone the lines of getAll(Active)ProfilesIncludingInherited(), or rename get(Active)Profiles() to something like getCurrent(Active)Profiles()
There was a problem hiding this comment.
What about:
getDeclaredProfiles()/getEffectiveProfiles()getDeclaredActiveProfiles()/getEffectiveActiveProfiles()
The declared would make reference to only profiles on the current project, while effective would make reference to profiles from the project and it's hierarchy, similar to the effective model which is computed with the parents merged into it.
There was a problem hiding this comment.
Thats a good one. As it also follows the terminology we use within other parts of the code base and documentation. It does require some knowledge of our domain as consumer of the API but the docs clearly describe the intent
| public List<Profile> getAllActiveProfiles() { | ||
| List<org.apache.maven.model.Profile> activeProfiles = new ArrayList<>(); | ||
| for (MavenProject project = this.project; project != null; project = project.getParent()) { | ||
| activeProfiles.addAll(project.getActiveProfiles()); | ||
| } | ||
| return activeProfiles.stream() | ||
| .map(org.apache.maven.model.Profile::getDelegate) | ||
| .toList(); | ||
| } | ||
|
|
There was a problem hiding this comment.
You could make the methods a one liner, if you'd like with something like this I think:
return Stream.iterate(this.project, Objects::nonNull, MavenProject::getParent)
.flatMap(project -> project.getActiveProfiles().stream())
.map(org.apache.maven.model.Profile::getDelegate)
.toList();…efaultProject.java Co-authored-by: Giovanni van der Schelde <27761321+Giovds@users.noreply.github.com>
|
Resolve #9367 |
Based on #2119