gnodet-bot commented on code in PR #13392:
URL: https://github.com/apache/maven/pull/13392#discussion_r4231536413


##########
impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java:
##########
@@ -162,20 +165,43 @@ public void execute(final MavenSession session, final 
List<MojoExecution> mojoEx
 
         final PhaseRecorder phaseRecorder = new 
PhaseRecorder(session.getCurrentProject());
 
+        // Resolve the mojo execution filter once per project execution.
+        final List<FilterPredicate> filterPredicates = 
resolveFilterPredicates(session);
+
         mojosExecutionStrategy.get().execute(mojoExecutions, session, new 
MojoExecutionRunner() {
             @Override
             public void run(MojoExecution mojoExecution) throws 
LifecycleExecutionException {
-                MojoExecutor.this.execute(session, mojoExecution, 
dependencyContext, phaseRecorder);
+                MojoExecutor.this.execute(session, mojoExecution, 
dependencyContext, phaseRecorder, filterPredicates);
             }
         });
     }
 
+    /**
+     * Resolves the mojo execution filter predicates for this build.
+     * Uses {@code -Dmaven.lifecycle.filter} user property; returns an empty 
list if absent.
+     */
+    private List<FilterPredicate> resolveFilterPredicates(MavenSession 
session) throws LifecycleExecutionException {
+        Properties userProps = session.getUserProperties();
+        String filterExpression = userProps != null ? 
userProps.getProperty(MojoExecutionFilter.PROPERTY_NAME) : null;
+        try {
+            return MojoExecutionFilter.parse(filterExpression);
+        } catch (IllegalArgumentException e) {
+            throw new LifecycleExecutionException(
+                    "Invalid value for '" + MojoExecutionFilter.PROPERTY_NAME 
+ "': " + e.getMessage(), e);
+        }
+    }
+
     private void execute(
             MavenSession session,
             MojoExecution mojoExecution,
             DependencyContext dependencyContext,
-            PhaseRecorder phaseRecorder)
+            PhaseRecorder phaseRecorder,
+            List<FilterPredicate> filterPredicates)
             throws LifecycleExecutionException {
+        if (MojoExecutionFilter.matches(mojoExecution, filterPredicates)) {
+            LOGGER.info("Skipping {} (filtered by {})", 
mojoExecution.getGoal(), MojoExecutionFilter.PROPERTY_NAME);

Review Comment:
   💡 `getGoal()` returns only the bare goal name (e.g. `"test"`), which is 
ambiguous when multiple plugins bind the same goal (e.g. surefire:test vs 
failsafe:test). Since this is a user-facing INFO message, consider using 
`mojoExecution` directly (its `toString()` returns 
`groupId:artifactId:version:goal {execution: id}`) or at minimum the plugin 
prefix + goal:
   
   ```suggestion
               LOGGER.info("Skipping {} (filtered by {})", mojoExecution, 
MojoExecutionFilter.PROPERTY_NAME);
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to