Giovds commented on code in PR #2132:
URL: https://github.com/apache/maven/pull/2132#discussion_r1972492500


##########
impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProject.java:
##########
@@ -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();
+    }
+
+    @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();
+    }
+

Review Comment:
   You could make the methods a one liner, if you'd like with something like 
this I think:
   
   ```java
       return Stream.iterate(this.project, Objects::nonNull, 
MavenProject::getParent)
                    .flatMap(project -> project.getActiveProfiles().stream())
                    .map(org.apache.maven.model.Profile::getDelegate)
                    .toList();
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to