This is an automated email from the ASF dual-hosted git repository. cstamas pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push: new 35a7b31dc4 [MNG-8310] Use --debug option instead of a specific mvnDebug script (#1812) 35a7b31dc4 is described below commit 35a7b31dc48c69cd2e94f6d2f628ba963270ff0b Author: Guillaume Nodet <gno...@gmail.com> AuthorDate: Fri Oct 18 13:01:21 2024 +0200 [MNG-8310] Use --debug option instead of a specific mvnDebug script (#1812) Use --debug option instead of a specific mvnDebug script. Deprecate existing mvnDebug script, drop newly added mvnencDebug (as it was not released). --- apache-maven/src/assembly/maven/bin/mvn | 41 +++++++++++++++++--- apache-maven/src/assembly/maven/bin/mvn.cmd | 28 ++++++++++++++ apache-maven/src/assembly/maven/bin/mvnDebug | 7 +--- apache-maven/src/assembly/maven/bin/mvnDebug.cmd | 7 +--- apache-maven/src/assembly/maven/bin/mvnenc | 2 +- apache-maven/src/assembly/maven/bin/mvnenc.cmd | 4 +- apache-maven/src/assembly/maven/bin/mvnencDebug | 35 ----------------- .../src/assembly/maven/bin/mvnencDebug.cmd | 44 ---------------------- apache-maven/src/assembly/maven/bin/mvnyjp | 8 +--- .../main/java/org/apache/maven/cli/CLIManager.java | 28 ++++++++------ .../java/org/apache/maven/cli/CleanArgument.java | 15 +++++++- .../org/apache/maven/cli/CleanArgumentTest.java | 9 +++++ 12 files changed, 111 insertions(+), 117 deletions(-) diff --git a/apache-maven/src/assembly/maven/bin/mvn b/apache-maven/src/assembly/maven/bin/mvn old mode 100644 new mode 100755 index 08e699dab5..a942b12a57 --- a/apache-maven/src/assembly/maven/bin/mvn +++ b/apache-maven/src/assembly/maven/bin/mvn @@ -22,10 +22,12 @@ # # Environment Variable Prerequisites # -# JAVA_HOME (Optional) Points to a Java installation. -# MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments. -# MAVEN_OPTS (Optional) Java runtime options used when Maven is executed. -# MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files. +# JAVA_HOME (Optional) Points to a Java installation. +# MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments. +# MAVEN_OPTS (Optional) Java runtime options used when Maven is executed. +# MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files. +# MAVEN_DEBUG_OPTS (Optional) Specify the debug options to use. Default value is "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=${MAVEN_DEBUG_ADDRESS}" when --debug is used +# MAVEN_DEBUG_ADDRESS (Optional) Set the debug address. Default value is "localhost:8000" # ----------------------------------------------------------------------------- if [ -z "$MAVEN_SKIP_RC" ] ; then @@ -167,7 +169,6 @@ MAVEN_PROJECTBASEDIR="`find_maven_basedir "$@"`" MAVEN_OPTS="$MAVEN_OPTS `concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config"`" LAUNCHER_JAR=`echo "$MAVEN_HOME"/boot/plexus-classworlds-*.jar` LAUNCHER_CLASS=org.codehaus.plexus.classworlds.launcher.Launcher -MAVEN_MAIN_CLASS=${MAVEN_MAIN_CLASS:=org.apache.maven.cling.MavenCling} # For Cygwin and MinGW, switch paths to Windows format before running java(1) command if $cygwin || $mingw ; then @@ -179,6 +180,36 @@ if $cygwin || $mingw ; then MAVEN_PROJECTBASEDIR=`cygpath --windows "$MAVEN_PROJECTBASEDIR"` fi +handle_args() { + while [ $# -gt 0 ]; do + case $1 in + --debug) + if [ -z "$MAVEN_DEBUG_OPTS" ] ; then + MAVEN_DEBUG_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=${MAVEN_DEBUG_ADDRESS:-localhost:8000}" + else + echo "Ignoring --debug option as MAVEN_DEBUG_OPTS is already set" + fi + ;; + --yjp) + if [ ! -f "$YJPLIB" ]; then + echo "Error: Unable to autodetect the YJP library location. Please set YJPLIB variable" >&2 + exit 1 + fi + MAVEN_OPTS="-agentpath:$YJPLIB=onexit=snapshot,onexit=memory,tracing,onlylocal $MAVEN_OPTS" + ;; + --enc) + MAVEN_MAIN_CLASS="org.apache.maven.cling.MavenEncCling" + ;; + *) + ;; + esac + shift + done +} + +handle_args "$@" +MAVEN_MAIN_CLASS=${MAVEN_MAIN_CLASS:=org.apache.maven.cling.MavenCling} + exec "$JAVACMD" \ $MAVEN_OPTS \ $MAVEN_DEBUG_OPTS \ diff --git a/apache-maven/src/assembly/maven/bin/mvn.cmd b/apache-maven/src/assembly/maven/bin/mvn.cmd index e51267e4d7..965f9bc0fa 100644 --- a/apache-maven/src/assembly/maven/bin/mvn.cmd +++ b/apache-maven/src/assembly/maven/bin/mvn.cmd @@ -174,6 +174,34 @@ for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do s @REM do not let MAVEN_PROJECTBASEDIR end with a single backslash which would escape the double quote. This happens when .mvn at drive root. if "_%MAVEN_PROJECTBASEDIR:~-1%"=="_\" set "MAVEN_PROJECTBASEDIR=%MAVEN_PROJECTBASEDIR%\" +if "%MAVEN_DEBUG_ADDRESS%"=="" set MAVEN_DEBUG_ADDRESS=localhost:8000 + +goto endHandleArgs +:handleArgs +if "%~1"=="--debug" ( + if "%MAVEN_DEBUG_OPTS%"=="" ( + set "MAVEN_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=%MAVEN_DEBUG_ADDRESS%" + ) +) else if "%~1"=="--yjp" ( + if not exist "%YJPLIB%" ( + echo Error: Unable to autodetect the YJP library location. Please set YJPLIB variable >&2 + exit /b 1 + ) + set "MAVEN_OPTS=-agentpath:%YJPLIB%=onexit=snapshot,onexit=memory,tracing,onlylocal %MAVEN_OPTS%" +) else if "%~1"=="--enc" ( + set "MAVEN_MAIN_CLASS=org.apache.maven.cling.MavenEncCling" +) +exit /b 0 + +:processArgs +if "%~1"=="" exit /b 0 +call :handleArgs %1 +shift +goto processArgs + +:endHandleArgs +call :processArgs %* + for %%i in ("%MAVEN_HOME%"\boot\plexus-classworlds-*) do set LAUNCHER_JAR="%%i" set LAUNCHER_CLASS=org.codehaus.plexus.classworlds.launcher.Launcher if "%MAVEN_MAIN_CLASS%"=="" @set MAVEN_MAIN_CLASS=org.apache.maven.cling.MavenCling diff --git a/apache-maven/src/assembly/maven/bin/mvnDebug b/apache-maven/src/assembly/maven/bin/mvnDebug index 7c8d327eb6..1b4bd5a97e 100644 --- a/apache-maven/src/assembly/maven/bin/mvnDebug +++ b/apache-maven/src/assembly/maven/bin/mvnDebug @@ -28,8 +28,5 @@ # MAVEN_DEBUG_ADDRESS (Optional) Set the debug address. Default value is localhost:8000 # ----------------------------------------------------------------------------- -MAVEN_DEBUG_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=${MAVEN_DEBUG_ADDRESS:-localhost:8000}" - -echo Preparing to execute Maven in debug mode - -env MAVEN_OPTS="$MAVEN_OPTS" MAVEN_DEBUG_OPTS="$MAVEN_DEBUG_OPTS" "`dirname "$0"`/mvn" "$@" +echo "This script is deprecated for removal, please use 'mvn --debug' instead" +"`dirname "$0"`/mvn" --debug "$@" diff --git a/apache-maven/src/assembly/maven/bin/mvnDebug.cmd b/apache-maven/src/assembly/maven/bin/mvnDebug.cmd index f02e89c84d..52439c366a 100644 --- a/apache-maven/src/assembly/maven/bin/mvnDebug.cmd +++ b/apache-maven/src/assembly/maven/bin/mvnDebug.cmd @@ -37,8 +37,5 @@ title %0 @setlocal -if "%MAVEN_DEBUG_ADDRESS%"=="" @set MAVEN_DEBUG_ADDRESS=localhost:8000 - -@set MAVEN_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=%MAVEN_DEBUG_ADDRESS% - -@call "%~dp0"mvn.cmd %* +echo "This script is deprecated for removal, please use 'mvn --debug' instead" +@call "%~dp0"mvn.cmd --debug %* diff --git a/apache-maven/src/assembly/maven/bin/mvnenc b/apache-maven/src/assembly/maven/bin/mvnenc index 852b2a84e8..c6067dda62 100644 --- a/apache-maven/src/assembly/maven/bin/mvnenc +++ b/apache-maven/src/assembly/maven/bin/mvnenc @@ -27,4 +27,4 @@ # MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files. # ----------------------------------------------------------------------------- -env MAVEN_MAIN_CLASS="org.apache.maven.cling.MavenEncCling" "`dirname "$0"`/mvn" "$@" +"`dirname "$0"`/mvn" --enc "$@" diff --git a/apache-maven/src/assembly/maven/bin/mvnenc.cmd b/apache-maven/src/assembly/maven/bin/mvnenc.cmd index fd9a106f6d..f8b0fb9bdb 100644 --- a/apache-maven/src/assembly/maven/bin/mvnenc.cmd +++ b/apache-maven/src/assembly/maven/bin/mvnenc.cmd @@ -36,6 +36,4 @@ title %0 @setlocal -@set MAVEN_MAIN_CLASS=org.apache.maven.cling.MavenEncCling - -@call "%~dp0"mvn.cmd %* +@call "%~dp0"mvn.cmd --enc %* diff --git a/apache-maven/src/assembly/maven/bin/mvnencDebug b/apache-maven/src/assembly/maven/bin/mvnencDebug deleted file mode 100644 index 50b3e67492..0000000000 --- a/apache-maven/src/assembly/maven/bin/mvnencDebug +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh - -# 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. - -# ----------------------------------------------------------------------------- -# Apache Maven Debug Script -# -# Environment Variable Prerequisites -# -# JAVA_HOME (Optional) Points to a Java installation. -# MAVEN_OPTS (Optional) Java runtime options used when Maven is executed. -# MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files. -# MAVEN_DEBUG_ADDRESS (Optional) Set the debug address. Default value is localhost:8000 -# ----------------------------------------------------------------------------- - -MAVEN_DEBUG_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=${MAVEN_DEBUG_ADDRESS:-localhost:8000}" - -echo Preparing to execute Maven in debug mode - -env MAVEN_OPTS="$MAVEN_OPTS" MAVEN_DEBUG_OPTS="$MAVEN_DEBUG_OPTS" "`dirname "$0"`/mvnenc" "$@" diff --git a/apache-maven/src/assembly/maven/bin/mvnencDebug.cmd b/apache-maven/src/assembly/maven/bin/mvnencDebug.cmd deleted file mode 100644 index 22a869cd5b..0000000000 --- a/apache-maven/src/assembly/maven/bin/mvnencDebug.cmd +++ /dev/null @@ -1,44 +0,0 @@ -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. - -@REM ----------------------------------------------------------------------------- -@REM Apache Maven Debug Script -@REM -@REM Environment Variable Prerequisites -@REM -@REM JAVA_HOME (Optional) Points to a Java installation. -@REM MAVEN_BATCH_ECHO (Optional) Set to 'on' to enable the echoing of the batch commands. -@REM MAVEN_BATCH_PAUSE (Optional) set to 'on' to wait for a key stroke before ending. -@REM MAVEN_OPTS (Optional) Java runtime options used when Maven is executed. -@REM MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files. -@REM MAVEN_DEBUG_ADDRESS (Optional) Set the debug address. Default value is localhost:8000 -@REM ----------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%"=="on" echo %MAVEN_BATCH_ECHO% - -@setlocal - -if "%MAVEN_DEBUG_ADDRESS%"=="" @set MAVEN_DEBUG_ADDRESS=localhost:8000 - -@set MAVEN_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=%MAVEN_DEBUG_ADDRESS% - -@call "%~dp0"mvnenc.cmd %* diff --git a/apache-maven/src/assembly/maven/bin/mvnyjp b/apache-maven/src/assembly/maven/bin/mvnyjp index a35eabf1f6..5e76db1c8c 100644 --- a/apache-maven/src/assembly/maven/bin/mvnyjp +++ b/apache-maven/src/assembly/maven/bin/mvnyjp @@ -27,9 +27,5 @@ # MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files. # ----------------------------------------------------------------------------- -if [ ! -f "$YJPLIB" ]; then - echo "Error: Unable to autodetect the YJP library location. Please set YJPLIB variable" >&2 - exit 1 -fi - -env MAVEN_OPTS="-agentpath:$YJPLIB=onexit=snapshot,onexit=memory,tracing,onlylocal $MAVEN_OPTS" "`dirname "$0"`/mvn" "$@" +echo "This script is deprecated for removal, please use 'mvn --yjp' instead" +"`dirname "$0"`/mvn" --yjp "$@" diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java index 93d7c15251..8312f3bd87 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java @@ -131,10 +131,9 @@ public class CLIManager { public static final String IGNORE_TRANSITIVE_REPOSITORIES = "itr"; - /** This option is deprecated and may be repurposed as Java debug in a future version. - * Use {@code -X,--verbose} instead. */ - @Deprecated public static final String DEBUG = "debug"; + public static final String ENC = "enc"; + public static final String YJP = "yjp"; protected Options options; protected final Set<Option> usedDeprecatedOptions = new LinkedHashSet<>(); @@ -339,6 +338,20 @@ public class CLIManager { .desc("If set, Maven will ignore remote repositories introduced by transitive dependencies.") .build()); + // Parameters handled by script + options.addOption(Option.builder() + .longOpt(DEBUG) + .desc("Launch the JVM in debug mode (script option).") + .build()); + options.addOption(Option.builder() + .longOpt(ENC) + .desc("Launch the Maven Encryption tool (script option).") + .build()); + options.addOption(Option.builder() + .longOpt(YJP) + .desc("Launch the JVM with Yourkit profiler (script option).") + .build()); + // Adding this back to make Maven fail if used options.addOption(Option.builder("llr") .longOpt("legacy-local-repository") @@ -350,15 +363,6 @@ public class CLIManager { .build()); // Deprecated - options.addOption(Option.builder() - .longOpt(DEBUG) - .desc("<deprecated> Produce execution verbose output.") - .deprecated(DeprecatedAttributes.builder() - .setForRemoval(true) - .setSince("4.0.0") - .setDescription("Use -X,--verbose instead.") - .get()) - .build()); options.addOption(Option.builder(ALTERNATE_GLOBAL_SETTINGS) .longOpt("global-settings") .desc("<deprecated> Alternate path for the global settings file.") diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CleanArgument.java b/maven-embedder/src/main/java/org/apache/maven/cli/CleanArgument.java index ad4566dd47..4bd7f6aacb 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CleanArgument.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CleanArgument.java @@ -26,6 +26,17 @@ import java.util.List; */ public class CleanArgument { public static String[] cleanArgs(String[] args) { + try { + return doCleanArgs(args); + } catch (RuntimeException e) { + for (String a : args) { + System.out.println("Arg: '" + a + "'"); + } + throw e; + } + } + + private static String[] doCleanArgs(String[] args) { List<String> cleaned = new ArrayList<>(); StringBuilder currentArg = null; @@ -49,7 +60,9 @@ public class CleanArgument { if (addedToBuffer && arg.endsWith("\"")) { // if we're building an argument, keep doing so. // if this is the case of "-Dfoo=bar", then we need to adjust the buffer. - currentArg.setLength(currentArg.length() - 1); + if (!currentArg.isEmpty()) { + currentArg.setLength(currentArg.length() - 1); + } cleaned.add(currentArg.toString()); diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/CleanArgumentTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/CleanArgumentTest.java index fb4bcd221f..9dfea2ec3b 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/CleanArgumentTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/CleanArgumentTest.java @@ -25,6 +25,15 @@ import static org.junit.jupiter.api.Assertions.assertEquals; /** */ class CleanArgumentTest { + + @Test + void cleanArgs() { + String[] args = { + "\"", + }; + CleanArgument.cleanArgs(args); + } + @Test void cleanArgsShouldRemoveWrongSurroundingQuotes() { String[] args = {"\"-Dfoo=bar", "\"-Dfoo2=bar two\""};