You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2021/02/13 19:25:54 UTC

[GitHub] [maven] michael-o commented on a change in pull request #446: [MNG-6511] - Optional project selection

michael-o commented on a change in pull request #446:
URL: https://github.com/apache/maven/pull/446#discussion_r575700502



##########
File path: maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java
##########
@@ -278,55 +290,61 @@
     MavenExecutionRequest setProfiles( List<Profile> profiles );
 
     /**
-     * @deprecated Use {@link #getProfileActivation()}.
+     * @deprecated Since Maven 4: use {@link #getProfileActivation()}.
      */
     @Deprecated
     MavenExecutionRequest addActiveProfile( String profile );
 
     /**
-     * @deprecated Use {@link #getProfileActivation()}.
+     * @deprecated Since Maven 4: use {@link #getProfileActivation()}.
      */
     @Deprecated
     MavenExecutionRequest addActiveProfiles( List<String> profiles );
 
     /**
-     * @deprecated Use {@link #getProfileActivation()}.
+     * @deprecated Since Maven 4: use {@link #getProfileActivation()}.

Review comment:
       I think these profile-related changes should be a separate PR.

##########
File path: maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java
##########
@@ -242,21 +274,17 @@ public DefaultGraphBuilder( BuildResumptionDataRepository buildResumptionDataRep
     {
         List<MavenProject> result = projects;
 
-        if ( !request.getExcludedProjects().isEmpty() )
+        ProjectActivation projectActivation = request.getProjectActivation();
+        Set<String> requiredSelectors = projectActivation.getRequiredInactiveProjectSelectors();
+        Set<String> optionalSelectors = projectActivation.getOptionalInactiveProjectSelectors();
+        if ( !requiredSelectors.isEmpty() || !optionalSelectors.isEmpty() )
         {
-            File reactorDirectory = getReactorDirectory( request );
+            Set<MavenProject> excludedProjects = new HashSet<>( requiredSelectors.size() + optionalSelectors.size() );
+            excludedProjects.addAll( getProjectsBySelectors( request, projects, requiredSelectors, true ) );
+            excludedProjects.addAll( getProjectsBySelectors( request, projects, optionalSelectors, false ) );

Review comment:
       Call me blind, but this just looks like [here](https://github.com/apache/maven/pull/446/files#diff-5a5fe4cfc363538b43d7a3e89cc8b12b64d7ae0f4159caa45740405a299b6e3eR180-R187), but method names are opposite. Can you explain please?

##########
File path: maven-core/src/main/java/org/apache/maven/execution/ActivationSettings.java
##########
@@ -0,0 +1,58 @@
+package org.apache.maven.execution;
+
+/*
+ * 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.
+ */
+
+/**
+ * Describes whether something (a profile or a project) should be activated or not, and if that is required or optional.

Review comment:
       This is now completely decoupled from profiles or projects, I think the docs on the parens are superfluous.

##########
File path: maven-core/src/main/java/org/apache/maven/execution/ProfileActivation.java
##########
@@ -74,7 +44,7 @@ static ActivationSettings of( final boolean active, final boolean optional )
     @Deprecated
     public List<String> getActiveProfiles()
     {
-        return new ArrayList<>( getProfileIds( pa -> pa.active ) );
+        return Collections.unmodifiableList( new ArrayList<>( getProfileIds( pa -> pa.active ) ) );

Review comment:
       This is likely nitpicking, but the previous impl did not return an immutable collection. I think since this deprecated anyway, it should not change its behavior.

##########
File path: maven-core/src/main/java/org/apache/maven/execution/ProjectActivation.java
##########
@@ -0,0 +1,173 @@
+package org.apache.maven.execution;
+
+/*
+ * 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.
+ */
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Predicate;
+
+import static java.util.stream.Collectors.toSet;
+
+/**
+ * Container for storing the request from the user to activate or de-activate certain projects and optionally fail the
+ * build if those projects do not exist.
+ */
+public class ProjectActivation
+{
+    private final Map<String, ActivationSettings> activations = new HashMap<>();
+
+    /**
+     * Adds a project activation to the request.
+     * @param selector The selector of the project.
+     * @param active Should the project be activated?
+     * @param optional Can the build continue if the project does not exist?
+     */
+    public void addProjectActivation( String selector, boolean active, boolean optional )
+    {
+        final ActivationSettings settings = ActivationSettings.of( active, optional );
+        this.activations.put( selector, settings );
+    }
+
+    private Set<String> getProjectSelectors( final Predicate<ActivationSettings> predicate )
+    {
+        return this.activations.entrySet().stream()
+                .filter( e -> predicate.test( e.getValue() ) )
+                .map( e -> e.getKey() )
+                .collect( toSet() );
+    }
+
+    /**
+     * @return Required active project selectors, never {@code null}.
+     */
+    public Set<String> getRequiredActiveProjectSelectors()
+    {
+        return getProjectSelectors( pa -> !pa.optional && pa.active );
+    }
+
+    /**
+     * @return Optional active project selectors, never {@code null}.
+     */
+    public Set<String> getOptionalActiveProjectSelectors()
+    {
+        return getProjectSelectors( pa -> pa.optional && pa.active );
+    }
+
+    /**
+     * @return Required inactive project selectors, never {@code null}.
+     */
+    public Set<String> getRequiredInactiveProjectSelectors()
+    {
+        return getProjectSelectors( pa -> !pa.optional && !pa.active );
+    }
+
+    /**
+     * @return Optional inactive project selectors, never {@code null}.
+     */
+    public Set<String> getOptionalInactiveProjectSelectors()
+    {
+        return getProjectSelectors( pa -> pa.optional && !pa.active );
+    }
+
+    /**
+     * Mimics the pre-Maven 4 "selected projects" list.
+     * @deprecated Use {@link #getRequiredActiveProjectSelectors()} and {@link #getOptionalActiveProjectSelectors()}
+     * instead.
+     */
+    @Deprecated
+    public List<String> getSelectedProjects()
+    {
+        return Collections.unmodifiableList( new ArrayList<>( getProjectSelectors( pa -> pa.active ) ) );

Review comment:
       Same as above

##########
File path: maven-core/src/main/java/org/apache/maven/execution/ActivationSettings.java
##########
@@ -0,0 +1,58 @@
+package org.apache.maven.execution;
+
+/*
+ * 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.
+ */
+
+/**
+ * Describes whether something (a profile or a project) should be activated or not, and if that is required or optional.

Review comment:
       Since you use the term 'target' later it should say: Describes whether a target...

##########
File path: maven-core/src/main/java/org/apache/maven/execution/ProjectActivation.java
##########
@@ -0,0 +1,173 @@
+package org.apache.maven.execution;
+
+/*
+ * 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.
+ */
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Predicate;
+
+import static java.util.stream.Collectors.toSet;
+
+/**
+ * Container for storing the request from the user to activate or de-activate certain projects and optionally fail the
+ * build if those projects do not exist.
+ */
+public class ProjectActivation
+{
+    private final Map<String, ActivationSettings> activations = new HashMap<>();
+
+    /**
+     * Adds a project activation to the request.
+     * @param selector The selector of the project.

Review comment:
       You probably should describe at least at class level what a selector is . It took me a while that it is either a `module`, `:artifactId` or `groupId:artifactId`.




----------------------------------------------------------------
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.

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