Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apache-maven/src/assembly/component.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ under the License.
<includes>
<include>mvn</include>
<include>mvnenc</include>
<include>mvnlog</include>
<include>mvnsh</include>
<include>mvnup</include>
<include>mvnDebug</include>
Expand Down
18 changes: 18 additions & 0 deletions apache-maven/src/assembly/maven/bin/mvn
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ handle_args() {
--up)
MAVEN_MAIN_CLASS="org.apache.maven.cling.MavenUpCling"
;;
--log)
MAVEN_MAIN_CLASS="org.apache.maven.cling.MavenLogCling"
;;
*)
;;
esac
Expand All @@ -311,6 +314,21 @@ handle_args() {
}

handle_args "$@"

# Strip routing flags (--debug, --yjp, --enc, --shell, --up, --log) from $@
# so they are not passed to the Java process where they may collide with
# Commons CLI option-prefix matching (e.g. --log matches --log-file).
_argc=$#
_i=0
while [ $_i -lt $_argc ]; do
_arg="$1"
shift
case $_arg in
--debug|--yjp|--enc|--shell|--up|--log) ;;
*) set -- "$@" "$_arg" ;;
esac
_i=$((_i + 1))
done
MAVEN_MAIN_CLASS=${MAVEN_MAIN_CLASS:=org.apache.maven.cling.MavenCling}

# Build base command string for eval (only contains Maven-controlled values)
Expand Down
115 changes: 71 additions & 44 deletions apache-maven/src/assembly/maven/bin/mvn.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,77 @@ set "WDIR=%EXEC_DIR%"
@REM POM location, if supplied.

set FILE_ARG=
set "FILTERED_ARGS="
if "%MAVEN_DEBUG_ADDRESS%"=="" set MAVEN_DEBUG_ADDRESS=localhost:8000

@REM Single pass through all arguments at the top level.
@REM At top level, %%1 preserves '=' signs (unlike 'call :label %%*' which
@REM re-tokenizes and splits on '=', breaking -Dkey=value and --flag=value).
:arg_loop
if "%~1" == "" goto argLoopDone

@REM --- Flags consumed by the script (NOT passed to Java) ---
if "%~1" == "--debug" (
if "%MAVEN_DEBUG_OPTS%" == "" (
set "MAVEN_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=%MAVEN_DEBUG_ADDRESS%"
)
shift
goto arg_loop
)
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 "INTERNAL_MAVEN_OPTS=-agentpath:%YJPLIB%=onexit=snapshot,onexit=memory,tracing,onlylocal %INTERNAL_MAVEN_OPTS%"
shift
goto arg_loop
)
if "%~1" == "--enc" (
set "MAVEN_MAIN_CLASS=org.apache.maven.cling.MavenEncCling"
shift
goto arg_loop
)
if "%~1" == "--shell" (
set "MAVEN_MAIN_CLASS=org.apache.maven.cling.MavenShellCling"
shift
goto arg_loop
)
if "%~1" == "--up" (
set "MAVEN_MAIN_CLASS=org.apache.maven.cling.MavenUpCling"
shift
goto arg_loop
)
if "%~1" == "--log" (
set "MAVEN_MAIN_CLASS=org.apache.maven.cling.MavenLogCling"
shift
goto arg_loop
)

@REM --- Extract -f/--file for basedir detection (still passed through to Java) ---
if "%~1" == "-f" (
set "FILE_ARG=%~2"
shift
goto process_file_arg
set "FILE_ARG=%~2"
set "FILTERED_ARGS=%FILTERED_ARGS% %1 %2"
shift
shift
goto arg_loop
)
if "%~1" == "--file" (
set "FILE_ARG=%~2"
shift
goto process_file_arg
set "FILE_ARG=%~2"
set "FILTERED_ARGS=%FILTERED_ARGS% %1 %2"
shift
shift
goto arg_loop
)
@REM If none of the above, skip the argument

@REM --- All other arguments pass through to Java ---
set "FILTERED_ARGS=%FILTERED_ARGS% %1"
shift
if not "%~1" == "" (
goto arg_loop
) else (
goto findBaseDir
)
goto arg_loop

:argLoopDone
if not "%FILE_ARG%" == "" goto process_file_arg
goto findBaseDir

:process_file_arg
if "%FILE_ARG%" == "" (
Expand Down Expand Up @@ -255,37 +308,11 @@ if defined MAVEN_DEBUG_SCRIPT (
@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 "INTERNAL_MAVEN_OPTS=-agentpath:%YJPLIB%=onexit=snapshot,onexit=memory,tracing,onlylocal %INTERNAL_MAVEN_OPTS%"
) else if "%~1"=="--enc" (
set "MAVEN_MAIN_CLASS=org.apache.maven.cling.MavenEncCling"
) else if "%~1"=="--shell" (
set "MAVEN_MAIN_CLASS=org.apache.maven.cling.MavenShellCling"
) else if "%~1"=="--up" (
set "MAVEN_MAIN_CLASS=org.apache.maven.cling.MavenUpCling"
)
exit /b 0

:processArgs
if "%~1"=="" exit /b 0
call :handleArgs %1
shift
goto processArgs

@REM All arg processing (--debug, --yjp, --enc, --shell, --up, --log, -f/--file)
@REM and FILTERED_ARGS building was done in the arg_loop above.
@REM This avoids 'call :subroutine %%*' which re-tokenizes and splits on '=',
@REM breaking -Dkey=value arguments on Windows.
: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
Expand All @@ -297,7 +324,7 @@ if not "%MAVEN_MAIN_CLASS%"=="org.apache.maven.cling.MavenCling" set "MAVEN_ARGS

if defined MAVEN_DEBUG_SCRIPT (
echo [DEBUG] Launching JVM with command:
echo [DEBUG] "%JAVACMD%" %INTERNAL_MAVEN_OPTS% %MAVEN_OPTS% %JVM_CONFIG_MAVEN_OPTS% %MAVEN_DEBUG_OPTS% --enable-native-access=ALL-UNNAMED -classpath %LAUNCHER_JAR% "-Dclassworlds.conf=%CLASSWORLDS_CONF%" "-Dmaven.home=%MAVEN_HOME%" "-Dmaven.mainClass=%MAVEN_MAIN_CLASS%" "-Dlibrary.jline.path=%MAVEN_HOME%\lib\jline-native" "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %LAUNCHER_CLASS% %MAVEN_ARGS% %*
echo [DEBUG] "%JAVACMD%" %INTERNAL_MAVEN_OPTS% %MAVEN_OPTS% %JVM_CONFIG_MAVEN_OPTS% %MAVEN_DEBUG_OPTS% --enable-native-access=ALL-UNNAMED -classpath %LAUNCHER_JAR% "-Dclassworlds.conf=%CLASSWORLDS_CONF%" "-Dmaven.home=%MAVEN_HOME%" "-Dmaven.mainClass=%MAVEN_MAIN_CLASS%" "-Dlibrary.jline.path=%MAVEN_HOME%\lib\jline-native" "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %LAUNCHER_CLASS% %MAVEN_ARGS% %FILTERED_ARGS%
)

"%JAVACMD%" ^
Expand All @@ -314,7 +341,7 @@ if defined MAVEN_DEBUG_SCRIPT (
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
%LAUNCHER_CLASS% ^
%MAVEN_ARGS% ^
%*
%FILTERED_ARGS%
if ERRORLEVEL 1 goto error
goto end

Expand Down
30 changes: 30 additions & 0 deletions apache-maven/src/assembly/maven/bin/mvnlog
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/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 Build Log Viewer 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.
# -----------------------------------------------------------------------------

"`dirname "$0"`/mvn" --log "$@"
39 changes: 39 additions & 0 deletions apache-maven/src/assembly/maven/bin/mvnlog.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@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 Build Log Viewer 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 -----------------------------------------------------------------------------

@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

@call "%~dp0"mvn.cmd --log %*
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,43 @@ public interface Options {
@Nonnull
Optional<String> color();

/**
* Returns the console output mode.
* <p>
* Supported modes:
* <ul>
* <li>{@code "auto"} — selects {@code "plain"} in CI, {@code "rich"} on interactive TTYs,
* {@code "verbose"} otherwise</li>
* <li>{@code "plain"} — compact one-line-per-module output with structured summary</li>
* <li>{@code "rich"} — JLine status bar with live reactor progress (requires TTY)</li>
* <li>{@code "verbose"} — full mojo-level output (Maven 4.0 default behavior)</li>
* <li>{@code "machine"} — JSON lines: one typed JSON object per lifecycle event,
* designed for piping to external tools, CI systems, and LLM agents</li>
* </ul>
*
* @return an {@link Optional} containing the console mode, or empty if not set
* @since 4.1.0
*/
@Nonnull
Optional<String> console();

/**
* Returns the warning display mode.
* <p>
* Controls how build warnings (diagnostics) are displayed:
* <ul>
* <li>{@code "summary"} (default) — collect warnings, show deduplicated summary at end of build</li>
* <li>{@code "all"} — show warnings inline as they occur AND show summary at end</li>
* <li>{@code "none"} — suppress the diagnostic summary entirely</li>
* <li>{@code "fail"} — show summary AND fail the build if any warnings exist</li>
* </ul>
*
* @return an {@link Optional} containing the warning mode, or empty if not set
* @since 4.1.0
*/
@Nonnull
Optional<String> warningMode();

/**
* Indicates whether Maven should operate in offline mode.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,30 @@ static Builder mvnup(@Nonnull List<String> args, @Nonnull MessageBuilderFactory
return builder(Tools.MVNUP_CMD, Tools.MVNUP_NAME, args, messageBuilderFactory);
}

/**
* Creates a new Builder instance for constructing a Maven Build Log Viewer ParserRequest.
*
* @param args the command-line arguments
* @param messageBuilderFactory the factory for creating message builders
* @return a new Builder instance
*/
@Nonnull
static Builder mvnlog(@Nonnull String[] args, @Nonnull MessageBuilderFactory messageBuilderFactory) {
return mvnlog(Arrays.asList(args), messageBuilderFactory);
}

/**
* Creates a new Builder instance for constructing a Maven Build Log Viewer ParserRequest.
*
* @param args the command-line arguments
* @param messageBuilderFactory the factory for creating message builders
* @return a new Builder instance
*/
@Nonnull
static Builder mvnlog(@Nonnull List<String> args, @Nonnull MessageBuilderFactory messageBuilderFactory) {
return builder(Tools.MVNLOG_CMD, Tools.MVNLOG_NAME, args, messageBuilderFactory);
}

/**
* Creates a new Builder instance for constructing a ParserRequest.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ private Tools() {}

public static final String MVNUP_CMD = "mvnup";
public static final String MVNUP_NAME = "Maven Upgrade Tool";

public static final String MVNLOG_CMD = "mvnlog";
public static final String MVNLOG_NAME = "Maven Build Log Viewer";
}
Loading
Loading