Skip to content

HACK TransformerClassRealm#144

Draft
cstamas wants to merge 1 commit intomasterfrom
transformer-classrealm
Draft

HACK TransformerClassRealm#144
cstamas wants to merge 1 commit intomasterfrom
transformer-classrealm

Conversation

@cstamas
Copy link
Copy Markdown
Member

@cstamas cstamas commented Apr 15, 2026

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)

private final ClassActionImpl classAction;
private final ServiceLoaderConfigActionImpl serviceConfigAction;

public static TransformerClassRealm newJakartaTransformerClassRealm(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this really be part of Classworlds? Although a common example the actual rules are usually defined by consumer...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 TransformerClassRealm to 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 {
Comment on lines +80 to +89
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);
}
});
Comment on lines +101 to +104
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
Comment on lines +197 to +203
@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);
Comment thread pom.xml
Comment on lines +64 to +68
<dependency>
<groupId>org.eclipse.transformer</groupId>
<artifactId>org.eclipse.transformer</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>
Comment on lines 41 to 46
@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);
Comment on lines +51 to +52
*
* @since TBD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants