Skip to content

Commit b4e8e1b

Browse files
committed
Implement JPMS module support for --enable-native-access
This implementation addresses issue #11028 by enhancing Maven's launcher to support JPMS modules with proper native access control. Key changes: 1. Added module-info.java to maven-classworlds, making it a proper JPMS module 2. Created modules/ directory in distribution for JLine JARs that need module path 3. Updated launcher scripts to use --module-path and specific --enable-native-access 4. Modified assembly configuration to separate JLine modules from regular dependencies 5. Updated classworlds configuration to load from both lib/ and modules/ directories The implementation moves away from --enable-native-access=ALL-UNNAMED to using specific module names (org.jline.terminal.ffm) for better security and proper JPMS compliance. JLine modules are placed on both module path and classpath to ensure compatibility with existing classloader-based code while enabling proper module system integration. Benefits: - Enhanced security through targeted native access permissions - Proper JPMS module isolation for JLine components - Maintains backward compatibility with existing Maven functionality - Prepares foundation for future full JPMS migration
1 parent 4894a84 commit b4e8e1b

File tree

5 files changed

+72
-4
lines changed

5 files changed

+72
-4
lines changed

apache-maven/src/assembly/component.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,37 @@ under the License.
2626
<include>org.apache.maven:maven-classworlds</include>
2727
</includes>
2828
</dependencySet>
29+
<dependencySet>
30+
<useProjectArtifact>false</useProjectArtifact>
31+
<outputDirectory>modules</outputDirectory>
32+
<includes>
33+
<!-- JLine modules that need native access -->
34+
<include>org.jline:jline-terminal-ffm</include>
35+
<include>org.jline:jline-terminal-jni</include>
36+
<include>org.jline:jline-terminal</include>
37+
<include>org.jline:jline-reader</include>
38+
<include>org.jline:jline-style</include>
39+
<include>org.jline:jline-builtins</include>
40+
<include>org.jline:jline-console</include>
41+
<include>org.jline:jline-console-ui</include>
42+
<include>org.jline:jansi-core</include>
43+
</includes>
44+
</dependencySet>
2945
<dependencySet>
3046
<useProjectArtifact>false</useProjectArtifact>
3147
<outputDirectory>lib</outputDirectory>
3248
<excludes>
3349
<exclude>org.apache.maven:maven-classworlds</exclude>
50+
<!-- Exclude JLine modules that go to modules/ directory -->
51+
<exclude>org.jline:jline-terminal-ffm</exclude>
52+
<exclude>org.jline:jline-terminal-jni</exclude>
53+
<exclude>org.jline:jline-terminal</exclude>
54+
<exclude>org.jline:jline-reader</exclude>
55+
<exclude>org.jline:jline-style</exclude>
56+
<exclude>org.jline:jline-builtins</exclude>
57+
<exclude>org.jline:jline-console</exclude>
58+
<exclude>org.jline:jline-console-ui</exclude>
59+
<exclude>org.jline:jansi-core</exclude>
3460
</excludes>
3561
</dependencySet>
3662
</dependencySets>

apache-maven/src/assembly/maven/bin/m2.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ optionally ${user.home}/.m2/ext/*.jar
3131
optionally ${maven.home}/lib/ext/*.jar
3232
load ${maven.home}/lib/maven-*.jar
3333
load ${maven.home}/lib/*.jar
34+
load ${maven.home}/modules/*.jar

apache-maven/src/assembly/maven/bin/mvn

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ else
107107
fi
108108
fi
109109

110-
if ! "$JAVACMD" --enable-native-access=ALL-UNNAMED -version >/dev/null 2>&1; then
110+
if ! "$JAVACMD" --enable-native-access=org.jline.terminal.ffm -version >/dev/null 2>&1; then
111111
echo "Error: Apache Maven 4.x requires Java 17 or newer to run." >&2
112112
"$JAVACMD" -version >&2
113113
echo "Please upgrade your Java installation or set JAVA_HOME to point to a compatible JDK." >&2
@@ -192,6 +192,7 @@ MAVEN_PROJECTBASEDIR="`find_maven_basedir "$@"`"
192192
MAVEN_OPTS="$MAVEN_OPTS `concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config"`"
193193
LAUNCHER_JAR=`echo "$MAVEN_HOME"/boot/maven-classworlds-*.jar`
194194
LAUNCHER_CLASS=org.codehaus.plexus.classworlds.launcher.Launcher
195+
MODULE_PATH="$MAVEN_HOME/modules"
195196

196197
# For Cygwin and MinGW, switch paths to Windows format before running java(1) command
197198
if $cygwin || $mingw ; then
@@ -242,7 +243,8 @@ MAVEN_MAIN_CLASS=${MAVEN_MAIN_CLASS:=org.apache.maven.cling.MavenCling}
242243
cmd="\"$JAVACMD\" \
243244
$MAVEN_OPTS \
244245
$MAVEN_DEBUG_OPTS \
245-
--enable-native-access=ALL-UNNAMED \
246+
--module-path \"$MODULE_PATH\" \
247+
--enable-native-access=org.jline.terminal.ffm \
246248
-classpath \"$LAUNCHER_JAR\" \
247249
\"-Dclassworlds.conf=$CLASSWORLDS_CONF\" \
248250
\"-Dmaven.home=$MAVEN_HOME\" \

apache-maven/src/assembly/maven/bin/mvn.cmd

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ if not exist "%JAVACMD%" (
7575
)
7676

7777
@REM Check Java version by testing the Java 17+ flag
78-
"%JAVACMD%" --enable-native-access=ALL-UNNAMED -version >nul 2>&1
78+
"%JAVACMD%" --enable-native-access=org.jline.terminal.ffm -version >nul 2>&1
7979
if ERRORLEVEL 1 (
8080
echo Error: Apache Maven 4.x requires Java 17 or newer to run. >&2
8181
"%JAVACMD%" -version >&2
@@ -249,14 +249,16 @@ call :processArgs %*
249249

250250
for %%i in ("%MAVEN_HOME%"\boot\maven-classworlds-*) do set LAUNCHER_JAR="%%i"
251251
set LAUNCHER_CLASS=org.codehaus.plexus.classworlds.launcher.Launcher
252+
set MODULE_PATH="%MAVEN_HOME%\modules"
252253
if "%MAVEN_MAIN_CLASS%"=="" @set MAVEN_MAIN_CLASS=org.apache.maven.cling.MavenCling
253254

254255
"%JAVACMD%" ^
255256
%INTERNAL_MAVEN_OPTS% ^
256257
%MAVEN_OPTS% ^
257258
%JVM_CONFIG_MAVEN_OPTS% ^
258259
%MAVEN_DEBUG_OPTS% ^
259-
--enable-native-access=ALL-UNNAMED ^
260+
--module-path %MODULE_PATH% ^
261+
--enable-native-access=org.jline.terminal.ffm ^
260262
-classpath %LAUNCHER_JAR% ^
261263
"-Dclassworlds.conf=%CLASSWORLDS_CONF%" ^
262264
"-Dmaven.home=%MAVEN_HOME%" ^
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
/**
21+
* Maven Classworlds module for class loading isolation and realm management.
22+
* <p>
23+
* This module provides the core class loading framework used by Maven to create
24+
* isolated class loading environments (realms) with controlled imports and exports.
25+
* </p>
26+
*/
27+
module org.apache.maven.classworlds {
28+
// Required dependencies (automatic modules)
29+
requires maven.api.annotations;
30+
31+
// Export public API packages
32+
exports org.apache.maven.api.classworlds;
33+
exports org.codehaus.plexus.classworlds;
34+
exports org.codehaus.plexus.classworlds.launcher;
35+
exports org.codehaus.plexus.classworlds.realm;
36+
exports org.codehaus.plexus.classworlds.strategy;
37+
}

0 commit comments

Comments
 (0)