gnodet-bot commented on code in PR #13277:
URL: https://github.com/apache/maven/pull/13277#discussion_r4115287401
##########
apache-maven/src/assembly/maven/bin/mvn:
##########
@@ -524,13 +526,56 @@ handle_args() {
--up)
MAVEN_MAIN_CLASS="org.apache.maven.cling.MavenUpCling"
;;
+ #
---------------------------------------------------------------------------
+ # CLAPP support: --clapp <toolname> or --clapp=<toolname>
+ # Launches a Maven Command Line App from lib/clapp/<toolname>/.
+ # The tool must advertise its entry-point class in the file
+ # lib/clapp/<toolname>/clapp.properties (key: mainClass)
+ # If that file is absent the class defaults to MavenClappCling which will
+ # emit a helpful error message.
+ #
---------------------------------------------------------------------------
+ --clapp)
+ shift
+ if [ $# -eq 0 ]; then
+ echo "Error: --clapp requires a tool name argument (e.g. --clapp
mvnfoo)" >&2
+ exit 1
+ fi
+ MAVEN_CLAPP_NAME="$1"
+ MAVEN_MAIN_CLASS="org.apache.maven.cling.MavenClappCling"
+ _load_clapp_main_class "$MAVEN_CLAPP_NAME"
+ ;;
+ --clapp=*)
+ MAVEN_CLAPP_NAME="${1#--clapp=}"
+ if [ -z "$MAVEN_CLAPP_NAME" ]; then
+ echo "Error: --clapp= requires a non-empty tool name" >&2
+ exit 1
+ fi
+ MAVEN_MAIN_CLASS="org.apache.maven.cling.MavenClappCling"
+ _load_clapp_main_class "$MAVEN_CLAPP_NAME"
+ ;;
*)
;;
esac
shift
done
Review Comment:
💡 `_skip_next` dead code is now fully removed. Clean.
##########
impl/maven-cli/src/main/java/org/apache/maven/cling/MavenClappCling.java:
##########
@@ -0,0 +1,276 @@
+/*
+ * 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);
+ }
+ }
Review Comment:
Good. `ClappException extends MavenException` is a much better fit than the
previous `IOException` abuse. The split between `ClappException`
(configuration/loading failures), `IllegalArgumentException` (invalid input),
and `IOException` (filesystem issues) correctly models the three distinct error
categories.
--
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]