Tarun4201 commented on code in PR #13277:
URL: https://github.com/apache/maven/pull/13277#discussion_r4123598594


##########
impl/maven-cli/src/main/java/org/apache/maven/cling/MavenClappCling.java:
##########
@@ -0,0 +1,302 @@
+/*
+ * 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.
+ */
+package org.apache.maven.cling;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.api.annotations.Nullable;
+import org.apache.maven.api.cli.Invoker;
+import org.apache.maven.api.cli.Parser;
+import org.apache.maven.api.cli.ParserRequest;
+import org.apache.maven.cling.invoker.ProtoLookup;
+import org.apache.maven.cling.invoker.mvn.MavenInvoker;
+import org.apache.maven.cling.invoker.mvn.MavenParser;
+import org.apache.maven.api.services.MavenException;
+import org.codehaus.plexus.classworlds.ClassWorld;
+
+/**
+ * Maven CLAPP (Command Line App) entry point.
+ * <p>
+ * This class acts as the launcher for external Maven CLI tools ("CLAPPs") 
that ship their
+ * own dependencies in {@code ${maven.home}/lib/clapp/<toolName>/} instead of 
requiring
+ * those jars to be in the shared {@code ${maven.home}/lib/} directory.
+ * <p>
+ * The {@code maven.clapp.name} system property identifies which CLAPP to 
launch.
+ * The CLAPP's jar directory is {@code ${maven.home}/lib/clapp/<toolName>/}.
+ * That directory is scanned for {@code *.jar} files which are added to a child
+ * {@link URLClassLoader} that delegates to the core Maven class-loader.
+ * The CLAPP's main entry point class is then looked up via the
+ * {@code maven.clapp.mainClass} system property and invoked.
+ * <p>
+ * This mechanism allows future {@code mvnXxx} tools to package tool-specific
+ * dependencies in isolation without bloating the core Maven classpath.
+ *
+ * @since 4.1.0
+ */
+public class MavenClappCling extends ClingSupport {
+
+    /**
+     * System property that specifies the CLAPP tool name (e.g., {@code 
"mvnenc"}).
+     * Used to locate {@code ${maven.home}/lib/clapp/<toolName>/}.
+     */
+    public static final String MAVEN_CLAPP_NAME_PROPERTY = "maven.clapp.name";
+
+    /**
+     * System property that specifies the fully-qualified main class name of 
the CLAPP tool.
+     * That class must expose a {@code public static int main(String[], 
ClassWorld)} method.
+     */
+    public static final String MAVEN_CLAPP_MAIN_CLASS_PROPERTY = 
"maven.clapp.mainClass";
+
+    /**
+     * Exception thrown when a CLAPP tool cannot be loaded, configured, or 
launched.
+     *
+     * @since 4.1.0
+     */
+    public static class ClappException extends MavenException {
+        public ClappException(String message) {
+            super(message);
+        }
+
+        public ClappException(String message, Throwable cause) {
+            super(message, cause);
+        }
+    }
+
+    /**
+     * Relative path under {@code ${maven.home}} where per-CLAPP jar 
directories live.
+     */
+    static final String CLAPP_LIB_RELATIVE_PATH = "lib/clapp";
+
+    /**
+     * "Normal" Java entry point. Note: Maven uses ClassWorld Launcher and 
this entry point is NOT
+     * used under normal circumstances.
+     */
+    public static void main(String[] args) throws IOException {
+        int exitCode = new MavenClappCling().run(args, null, null, null, 
false);
+        System.exit(exitCode);
+    }
+
+    /**
+     * ClassWorld Launcher "enhanced" entry point: returning exitCode and 
accepts ClassWorld.
+     * <p>
+     * When {@code maven.clapp.name} and {@code maven.clapp.mainClass} system 
properties are set,
+     * this method builds a per-CLAPP child classloader and delegates to the 
CLAPP's main class.
+     * Otherwise, it falls back to the standard {@link MavenCling} behaviour.
+     */
+    public static int main(String[] args, ClassWorld world) throws IOException 
{
+        String clappName = System.getProperty(MAVEN_CLAPP_NAME_PROPERTY);
+        String clappMainClass = 
System.getProperty(MAVEN_CLAPP_MAIN_CLASS_PROPERTY);
+
+        if (clappName != null && !clappName.isBlank() && clappMainClass != 
null && !clappMainClass.isBlank()) {
+            return launchClapp(clappName.trim(), clappMainClass.trim(), args, 
world);
+        }
+
+        // Fallback: behave as MavenCling when no CLAPP is configured
+        return MavenCling.main(args, world);

Review Comment:
   Fixed in commit ca84dc3d: `MavenClappCling.main()` now explicitly validates 
`mainClass` when a CLAPP is specified and fails fast with `ClappException` if 
missing. Furthermore, the fallback to standard Maven run now directly calls 
`new MavenCling(world).run(args, null, null, null, false)` rather than 
delegating through `MavenCling.main()`, completely preventing recursive 
launcher re-entry.



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