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
15 changes: 13 additions & 2 deletions apache-maven/src/assembly/component.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,25 @@ under the License.
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>boot</outputDirectory>
<includes>
<include>org.codehaus.plexus:plexus-classworlds</include>
<include>org.apache.maven:maven-api-classworlds</include>
<include>org.apache.maven:maven-classworlds</include>
</includes>
</dependencySet>

<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>lib/modules</outputDirectory>
<includes>
<include>org.jline:*</include>
</includes>
</dependencySet>

<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
<excludes>
<exclude>org.codehaus.plexus:plexus-classworlds</exclude>
<exclude>org.apache.maven:maven-api-classworlds</exclude>
<exclude>org.apache.maven:maven-classworlds</exclude>
</excludes>
Comment on lines 39 to 45
</dependencySet>
</dependencySets>
Expand Down
2 changes: 2 additions & 0 deletions apache-maven/src/assembly/maven/bin/m2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ main is ${maven.mainClass} from plexus.core
set maven.conf default ${maven.home}/conf
set maven.installation.conf default ${maven.conf}

module ${maven.home}/lib/modules/*.jar

[plexus.core]
load ${maven.conf}/logging
optionally ${maven.home}/lib/ext/redisson/*.jar
Expand Down
23 changes: 20 additions & 3 deletions apache-maven/src/assembly/maven/bin/mvn
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,34 @@ fi
if [ -n "$MAVEN_DEBUG_SCRIPT" ]; then
echo "[DEBUG] Final MAVEN_OPTS: $MAVEN_OPTS" >&2
fi
LAUNCHER_JAR=`echo "$MAVEN_HOME"/boot/plexus-classworlds-*.jar`
LAUNCHER_JAR=""
for _jar in "$MAVEN_HOME"/boot/*.jar; do
[ -f "$_jar" ] && LAUNCHER_JAR="${LAUNCHER_JAR:+$LAUNCHER_JAR:}$_jar"
done
LAUNCHER_CLASS=org.codehaus.plexus.classworlds.launcher.Launcher
MODULES_DIR="$MAVEN_HOME/lib/modules"

# Module-path and native access flags require a JDK that can read the module jars.
# The probe includes --module-path so it fails on JDKs that cannot read the module descriptors.
USE_MODULE_PATH=false
if "$JAVACMD" --module-path "$MODULES_DIR" --add-modules ALL-MODULE-PATH --enable-native-access=org.jline.terminal.ffm -version >/dev/null 2>&1; then
USE_MODULE_PATH=true
fi

# For Cygwin and MinGW, switch paths to Windows format before running java(1) command
if $cygwin || $mingw ; then
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --windows "$JAVA_HOME"`
LAUNCHER_JAR=`cygpath --windows "$LAUNCHER_JAR"`
LAUNCHER_JAR=`cygpath --windows --path "$LAUNCHER_JAR"`
CLASSWORLDS_CONF=`cygpath --windows "$CLASSWORLDS_CONF"`
MAVEN_HOME=`cygpath --windows "$MAVEN_HOME"`
MAVEN_PROJECTBASEDIR=`cygpath --windows "$MAVEN_PROJECTBASEDIR"`
MODULES_DIR=`cygpath --windows "$MODULES_DIR"`
fi

MAVEN_MODULE_OPTS=""
if $USE_MODULE_PATH; then
MAVEN_MODULE_OPTS="--module-path \"$MODULES_DIR\" --add-modules ALL-MODULE-PATH --enable-native-access=org.jline.terminal.ffm,org.jline.nativ"
fi

handle_args() {
Expand Down Expand Up @@ -279,7 +296,7 @@ MAVEN_MAIN_CLASS=${MAVEN_MAIN_CLASS:=org.apache.maven.cling.MavenCling}
cmd="\"$JAVACMD\" \
$MAVEN_OPTS \
$MAVEN_DEBUG_OPTS \
--enable-native-access=ALL-UNNAMED \
$MAVEN_MODULE_OPTS \
-classpath \"$LAUNCHER_JAR\" \
\"-Dclassworlds.conf=$CLASSWORLDS_CONF\" \
\"-Dmaven.home=$MAVEN_HOME\" \
Expand Down
15 changes: 12 additions & 3 deletions apache-maven/src/assembly/maven/bin/mvn.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -266,21 +266,30 @@ goto processArgs
:endHandleArgs
call :processArgs %*

for %%i in ("%MAVEN_HOME%"\boot\plexus-classworlds-*) do set LAUNCHER_JAR="%%i"
set LAUNCHER_JAR="%MAVEN_HOME%\boot\*"
set LAUNCHER_CLASS=org.codehaus.plexus.classworlds.launcher.Launcher
set MODULES_DIR="%MAVEN_HOME%\lib\modules"
if "%MAVEN_MAIN_CLASS%"=="" @set MAVEN_MAIN_CLASS=org.apache.maven.cling.MavenCling

@rem Module-path and native access flags require a JDK that can read the module jars.
@rem The probe includes --module-path so it fails on JDKs that cannot read the module descriptors.
set MAVEN_MODULE_OPTS=
"%JAVACMD%" --module-path %MODULES_DIR% --add-modules ALL-MODULE-PATH --enable-native-access=org.jline.terminal.ffm -version >NUL 2>&1
if not ERRORLEVEL 1 (
set MAVEN_MODULE_OPTS=--module-path %MODULES_DIR% --add-modules ALL-MODULE-PATH --enable-native-access=org.jline.terminal.ffm,org.jline.nativ
)

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% %MAVEN_MODULE_OPTS% -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% %*
)

"%JAVACMD%" ^
%INTERNAL_MAVEN_OPTS% ^
%MAVEN_OPTS% ^
%JVM_CONFIG_MAVEN_OPTS% ^
%MAVEN_DEBUG_OPTS% ^
--enable-native-access=ALL-UNNAMED ^
%MAVEN_MODULE_OPTS% ^
-classpath %LAUNCHER_JAR% ^
"-Dclassworlds.conf=%CLASSWORLDS_CONF%" ^
"-Dmaven.home=%MAVEN_HOME%" ^
Expand Down
6 changes: 5 additions & 1 deletion apache-maven/src/main/appended-resources/META-INF/LICENSE.vm
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,13 @@ subject to the terms and conditions of the following licenses:
#* *##end ##
#* *###
#* *### Classworlds is in boot directory, not in lib
#* *##if ( $project.artifact.artifactId == "plexus-classworlds" )
#* *##if ( $project.artifact.artifactId == "maven-classworlds" )
#* *##set ( $directory = 'boot' ) ##
#* *##end ##
#* *### JLine modules are in lib/modules directory
#* *##if ( $groupId == "org.jline" )
#* *##set ( $directory = 'lib/modules' ) ##
#* *##end ##
#* *###
#* *### copy license file to lib/$artifactId.license
#* *##set ( $licFile = $directory + '/' + $project.artifact.artifactId + '.license' ) ##
Expand Down
39 changes: 39 additions & 0 deletions api/maven-api-classworlds/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api</artifactId>
<version>4.1.0-SNAPSHOT</version>
</parent>

<artifactId>maven-api-classworlds</artifactId>
<name>Maven 4 API :: Classworlds</name>
<description>Maven 4 API for class loading realms and isolation.</description>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-annotations</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
/*
* 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.api.classworlds;

import java.io.Closeable;
import java.net.URL;

import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.Nullable;

/**
* A class loading realm that provides isolated class loading with controlled imports and exports.
* <p>
* A ClassRealm represents an isolated class loading environment with its own classpath
* and controlled access to classes from other realms through imports.
* </p>
*
* @since 4.1.0
*/
@Experimental
public interface ClassRealm extends Closeable {

/**
* Returns the unique identifier for this realm.
*
* @return the realm identifier
*/
@Nonnull
String getId();

/**
* Returns the class world that contains this realm.
*
* @return the parent class world
*/
@Nonnull
ClassWorld getWorld();

/**
* Returns the underlying ClassLoader for this realm.
* <p>
* This method allows access to the actual ClassLoader implementation
* while maintaining API abstraction.
* </p>
*
* @return the underlying ClassLoader
*/
@Nonnull
ClassLoader getClassLoader();

/**
* Returns the class loading strategy used by this realm.
*
* @return the strategy
*/
@Nonnull
Strategy getStrategy();

/**
* Adds a URL to this realm's classpath.
*
* @param url the URL to add
*/
void addURL(@Nonnull URL url);

/**
* Returns the URLs in this realm's classpath.
*
* @return array of URLs in the classpath
*/
@Nonnull
URL[] getURLs();

/**
* Imports classes from the specified realm for the given package.
*
* @param realmId the identifier of the realm to import from
* @param packageName the package name to import (supports wildcards)
* @throws NoSuchRealmException if the specified realm doesn't exist
*/
void importFrom(@Nonnull String realmId, @Nonnull String packageName) throws NoSuchRealmException;

/**
* Imports classes from the specified class loader for the given package.
*
* @param classLoader the class loader to import from
* @param packageName the package name to import (supports wildcards)
*/
void importFrom(@Nonnull ClassLoader classLoader, @Nonnull String packageName);

/**
* Returns the class loader that would handle the specified class name through imports.
*
* @param name the class name
* @return the import class loader, or null if no import matches
*/
@Nullable
ClassLoader getImportClassLoader(@Nonnull String name);

// Note: getImportRealms method is not included in the API interface
// to avoid conflicts with the existing implementation signature

/**
* Sets the parent class loader for this realm.
*
* @param parentClassLoader the parent class loader, may be null
*/
void setParentClassLoader(@Nullable ClassLoader parentClassLoader);

/**
* Returns the parent class loader for this realm.
*
* @return the parent class loader, may be null
*/
@Nullable
ClassLoader getParentClassLoader();

// Note: setParentRealm method is not included in the API interface
// to avoid conflicts with the existing implementation signature

// Note: getParentRealm method is not included in the API interface
// to avoid conflicts with the existing implementation signature

// Note: createChildRealm method is not included in the API interface
// to avoid conflicts with the existing implementation signature

/**
* Loads a class from this realm only (not from imports or parent).
*
* @param name the class name
* @return the loaded class, or null if not found
*/
@Nullable
Class<?> loadClassFromSelf(@Nonnull String name);

/**
* Loads a class from imported realms/classloaders.
*
* @param name the class name
* @return the loaded class, or null if not found
*/
@Nullable
Class<?> loadClassFromImport(@Nonnull String name);

/**
* Loads a class from the parent class loader.
*
* @param name the class name
* @return the loaded class, or null if not found
*/
@Nullable
Class<?> loadClassFromParent(@Nonnull String name);

/**
* Loads a resource from this realm only (not from imports or parent).
*
* @param name the resource name
* @return the resource URL, or null if not found
*/
@Nullable
URL loadResourceFromSelf(@Nonnull String name);

/**
* Loads a resource from imported realms/classloaders.
*
* @param name the resource name
* @return the resource URL, or null if not found
*/
@Nullable
URL loadResourceFromImport(@Nonnull String name);

/**
* Loads a resource from the parent class loader.
*
* @param name the resource name
* @return the resource URL, or null if not found
*/
@Nullable
URL loadResourceFromParent(@Nonnull String name);

/**
* Exports a package from a named JPMS module to this realm's unnamed module,
* making the package's public types accessible to classes loaded by this realm.
*
* @param moduleName the source module name
* @param packageName the package to export
*/
default void addExports(@Nonnull String moduleName, @Nonnull String packageName) {}

/**
* Opens a package from a named JPMS module to this realm's unnamed module for deep reflection,
* making the package's types accessible via reflection (including non-public members).
*
* @param moduleName the source module name
* @param packageName the package to open
*/
default void addOpens(@Nonnull String moduleName, @Nonnull String packageName) {}

/**
* Adds a reads edge from a named JPMS module to this realm's unnamed module,
* allowing the named module to access types in this realm.
*
* @param moduleName the source module that should read this realm's unnamed module
*/
default void addReads(@Nonnull String moduleName) {}
}
Loading
Loading