Conversation
experimenting with https://github.com/eclipse-transformer/transformer
| private final ClassActionImpl classAction; | ||
| private final ServiceLoaderConfigActionImpl serviceConfigAction; | ||
|
|
||
| public static TransformerClassRealm newJakartaTransformerClassRealm( |
There was a problem hiding this comment.
Should this really be part of Classworlds? Although a common example the actual rules are usually defined by consumer...
There was a problem hiding this comment.
Exactly, in this case maven is consumer... but again, this is hack, this realm could be hidden in maven own impl package... (but rest of changes are needed here, to allow classworld to create 'custom type' realm)
There was a problem hiding this comment.
Pull request overview
This PR experiments with integrating the Eclipse Transformer into Plexus Classworlds by introducing a transformer-backed ClassRealm implementation and routing ClassWorld’s default realm creation through it (along with related test updates and new dependencies).
Changes:
- Introduces
TransformerClassRealmto transform loaded classes/resources (e.g.,javax.*→jakarta.*) at classloading time. - Refactors
ClassWorld.newRealm(...)to support a supplier-based realm factory and switches the default realm implementation when no filter is provided. - Updates tests to create realms through
ClassWorld.newRealm(...)and adds new Maven dependencies (SLF4J + Eclipse Transformer).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| src/test/java/org/codehaus/plexus/classworlds/realm/DefaultClassRealmTest.java | Updates realm creation to go through ClassWorld.newRealm(...) (now coupled to default realm type). |
| src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmImplTest.java | Updates realm construction to use ClassWorld.newRealm(...) and propagates DuplicateRealmException. |
| src/main/java/org/codehaus/plexus/classworlds/realm/TransformerClassRealm.java | Adds a new transformer-backed ClassRealm that wraps resources/classes via URL handlers and overrides class/resource finding. |
| src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java | Makes ClassRealm abstract, preventing direct instantiation. |
| src/main/java/org/codehaus/plexus/classworlds/ClassWorld.java | Adds supplier-based realm creation and changes default realm creation to use TransformerClassRealm. |
| pom.xml | Adds dependencies on slf4j-api and a SNAPSHOT org.eclipse.transformer artifact. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * @author Jason van Zyl | ||
| */ | ||
| public class ClassRealm extends URLClassLoader { | ||
| public abstract class ClassRealm extends URLClassLoader { |
| public ClassRealm newRealm(String id, ClassLoader classLoader, Predicate<String> filter) | ||
| throws DuplicateRealmException { | ||
| if (realms.containsKey(id)) { | ||
| throw new DuplicateRealmException(this, id); | ||
| } | ||
|
|
||
| ClassRealm realm; | ||
| return newRealm(() -> { | ||
| if (filter == null) { | ||
| // return new ClassRealm(this, id, classLoader); | ||
| return TransformerClassRealm.newJakartaTransformerClassRealm(this, id, classLoader); | ||
| } else { | ||
| return new FilteredClassRealm(filter, this, id, classLoader); | ||
| } | ||
| }); |
| public synchronized ClassRealm newRealm(Supplier<ClassRealm> factory) throws DuplicateRealmException { | ||
| ClassRealm realm = factory.get(); | ||
| if (realms.containsKey(realm.getId())) { | ||
| Exception closeEx = null; |
| * @param factory The factory to create realm instance. | ||
| * @return the created class realm | ||
| * @throws DuplicateRealmException in case a realm with the given id does already exist | ||
| * @since TBD |
| @Override | ||
| public InputStream getInputStream() throws IOException { | ||
| URLConnection useBaseConnection = getBaseConnection(); | ||
| String baseName = useBaseConnection.getURL().toString(); | ||
| InputStream baseStream = useBaseConnection.getInputStream(); | ||
| return applyClass(baseName, baseStream); | ||
| } |
| } | ||
| URL res = loadResourceFromSelf(resourceName); | ||
| if (res == null) { | ||
| throw new ClassNotFoundException(resourceName); |
| <dependency> | ||
| <groupId>org.eclipse.transformer</groupId> | ||
| <artifactId>org.eclipse.transformer</artifactId> | ||
| <version>1.1.0-SNAPSHOT</version> | ||
| </dependency> |
| @Test | ||
| void loadClassFromRealm() throws Exception { | ||
| ClassRealm mainRealm = new ClassRealm(new ClassWorld(), "main", null); | ||
| ClassRealm mainRealm = new ClassWorld().newRealm("main", null); | ||
|
|
||
| mainRealm.addURL(getJarUrl("component0-1.0.jar")); | ||
|
|
| void locateSourceRealmNoImports() { | ||
| ClassRealm realm = new ClassRealm(this.world, "foo", null); | ||
| void locateSourceRealmNoImports() throws DuplicateRealmException { | ||
| ClassRealm realm = world.newRealm("foo", null); |
| * | ||
| * @since TBD |
Experimenting with https://github.com/eclipse-transformer/transformer
NO MERGE! This is A HACK yet.
To build:
mvn -Denforcer.skip(as Eclipse Transformer is Java 17)