You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by kw...@apache.org on 2020/08/19 07:04:27 UTC

[jackrabbit-filevault-package-maven-plugin] branch master updated: JCRVLT-467 restore correct TCCL in validate-files

This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault-package-maven-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 4fec8fe  JCRVLT-467 restore correct TCCL in validate-files
4fec8fe is described below

commit 4fec8fe8424a9593c46a4b84fdbd66362f972d2e
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Wed Aug 19 09:04:17 2020 +0200

    JCRVLT-467 restore correct TCCL in validate-files
    
    JCRVLT-468 also evaluate forked executions
---
 .../maven/packaging/ValidateFilesMojo.java         | 27 ++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/ValidateFilesMojo.java b/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/ValidateFilesMojo.java
index 1cc429d..af9693c 100644
--- a/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/ValidateFilesMojo.java
+++ b/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/ValidateFilesMojo.java
@@ -273,11 +273,30 @@ public class ValidateFilesMojo extends AbstractValidateMojo {
         if (goals.length == 0) {
             return false;
         }
-        MavenExecutionPlan executionPlan = lifecycleExecutor.calculateExecutionPlan(session, goals);
-        for (MojoExecution mojoExecution : executionPlan.getMojoExecutions()) {
-            if (PLUGIN_KEY.equals(mojoExecution.getPlugin().getKey()) && mojoGoal.equals(mojoExecution.getGoal())) {
-                return true;
+        
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        try {
+            MavenExecutionPlan executionPlan = lifecycleExecutor.calculateExecutionPlan(session, goals);
+            for (MojoExecution mojoExecution : executionPlan.getMojoExecutions()) {
+                if (isMojoGoalExecuted(mojoExecution, mojoGoal)) {
+                    return true;
+                }
+                lifecycleExecutor.calculateForkedExecutions(mojoExecution, session);
+                // also evaluate forked execution goals
+                if (mojoExecution.getForkedExecutions().values().stream().flatMap(Collection::stream).anyMatch( t -> isMojoGoalExecuted(t, mojoGoal))) {
+                    return true;
+                }
             }
+            return false;
+        } finally {
+            // restore old classloader as calculate execution plan modifies it
+            Thread.currentThread().setContextClassLoader(classLoader);
+        }
+    }
+    
+    private static boolean isMojoGoalExecuted(MojoExecution mojoExecution, String mojoGoal) {
+        if (PLUGIN_KEY.equals(mojoExecution.getPlugin().getKey()) && mojoGoal.equals(mojoExecution.getGoal())) {
+            return true;
         }
         return false;
     }