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
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@
</properties>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>org.eclipse.transformer</groupId>
<artifactId>org.eclipse.transformer</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
49 changes: 36 additions & 13 deletions src/main/java/org/codehaus/plexus/classworlds/ClassWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.function.Supplier;

import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
import org.codehaus.plexus.classworlds.realm.FilteredClassRealm;
import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
import org.codehaus.plexus.classworlds.realm.TransformerClassRealm;

/**
* A collection of <code>ClassRealm</code>s, indexed by id.
Expand Down Expand Up @@ -75,25 +77,46 @@ public ClassRealm newRealm(String id, ClassLoader classLoader) throws DuplicateR
* @since 2.7.0
* @see FilteredClassRealm
*/
public synchronized ClassRealm newRealm(String id, ClassLoader classLoader, Predicate<String> filter)
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);
}
});
}

if (filter == null) {
realm = new ClassRealm(this, id, classLoader);
} else {
realm = new FilteredClassRealm(filter, this, id, classLoader);
/**
* Adds a class realm using caller supplied factory.
*
* @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
* @see FilteredClassRealm
*/
public synchronized ClassRealm newRealm(Supplier<ClassRealm> factory) throws DuplicateRealmException {
ClassRealm realm = factory.get();
if (realms.containsKey(realm.getId())) {
Exception closeEx = null;
try {
realm.close();
} catch (Exception e) {
closeEx = e;
}
DuplicateRealmException ex = new DuplicateRealmException(this, realm.getId());
if (closeEx != null) {
ex.addSuppressed(closeEx);
}
throw ex;
}
realms.put(id, realm);

realms.put(realm.getId(), realm);
for (ClassWorldListener listener : listeners) {
listener.realmCreated(realm);
}

return realm;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a>
* @author Jason van Zyl
*/
public class ClassRealm extends URLClassLoader {
public abstract class ClassRealm extends URLClassLoader {

private final ClassWorld world;

Expand Down
Loading
Loading