-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
[MNG-8588] Add activated profiles to Project interface #2132
Open
gnodet
wants to merge
5
commits into
apache:master
Choose a base branch
from
gnodet:add-activated-profiles-to-project-interface
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+339
−40
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5d9eb9c
[MNG-8588] Add activated profiles to Project interface
Giovds 5308f55
[MNG-8588] Add tests for getInjectedProfileIds()
Giovds d7c1fc4
Define getActiveProfiles() instead
gnodet 525c38d
Add getProfiles methods and fix location tracking on settings
gnodet 616b0b4
Update impl/maven-core/src/main/java/org/apache/maven/internal/impl/D…
gnodet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
import org.apache.maven.api.annotations.Nullable; | ||
import org.apache.maven.api.model.DependencyManagement; | ||
import org.apache.maven.api.model.Model; | ||
import org.apache.maven.api.model.Profile; | ||
import org.apache.maven.impl.MappedCollection; | ||
import org.apache.maven.impl.MappedList; | ||
import org.apache.maven.project.MavenProject; | ||
|
@@ -165,6 +166,46 @@ public Optional<Project> getParent() { | |
return Optional.ofNullable(session.getProject(parent)); | ||
} | ||
|
||
@Override | ||
@Nonnull | ||
public List<Profile> getProfiles() { | ||
return getModel().getProfiles(); | ||
} | ||
|
||
@Override | ||
@Nonnull | ||
public List<Profile> getAllProfiles() { | ||
List<org.apache.maven.model.Profile> activeProfiles = new ArrayList<>(); | ||
for (MavenProject project = this.project; project != null; project = project.getParent()) { | ||
activeProfiles.addAll(project.getModel().getProfiles()); | ||
} | ||
return activeProfiles.stream() | ||
.map(org.apache.maven.model.Profile::getDelegate) | ||
.toList(); | ||
} | ||
gnodet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Override | ||
@Nonnull | ||
public List<Profile> getActiveProfiles() { | ||
List<org.apache.maven.model.Profile> activeProfiles = | ||
project.getActiveProfiles() != null ? project.getActiveProfiles() : List.of(); | ||
return activeProfiles.stream() | ||
.map(org.apache.maven.model.Profile::getDelegate) | ||
.toList(); | ||
} | ||
|
||
@Override | ||
@Nonnull | ||
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(); | ||
} | ||
|
||
Comment on lines
+199
to
+208
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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(); |
||
@Nonnull | ||
private DependencyCoordinates toDependency(org.apache.maven.api.model.Dependency dependency) { | ||
return new DependencyCoordinates() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
impl/maven-core/src/test/resources/projects/pom-with-profiles/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="ISO-8859-1"?> | ||
|
||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>maven</groupId> | ||
<artifactId>maven-core</artifactId> | ||
<version>2.0-SNAPSHOT</version> | ||
|
||
<name>Maven</name> | ||
|
||
<profiles> | ||
<profile> | ||
<id>active-by-default</id> | ||
<activation> | ||
<activeByDefault>true</activeByDefault> | ||
</activation> | ||
</profile> | ||
<profile> | ||
<id>profile1</id> | ||
</profile> | ||
<profile> | ||
<id>profile2</id> | ||
</profile> | ||
</profiles> | ||
</project> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to think of a different name for the
getAll(Active)Profiles()
methods, as it might be interpreted the same asgetProfiles()
. I was thinking something alone the lines ofgetAll(Active)ProfilesIncludingInherited()
, or renameget(Active)Profiles()
to something likegetCurrent(Active)Profiles()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about:
getDeclaredProfiles()
/getEffectiveProfiles()
getDeclaredActiveProfiles()
/getEffectiveActiveProfiles()
The
declared
would make reference to only profiles on the current project, whileeffective
would make reference to profiles from the project and it's hierarchy, similar to theeffective
model which is computed with the parents merged into it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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