24
24
import java .util .List ;
25
25
import java .util .Map ;
26
26
import java .util .Set ;
27
+ import java .util .function .Predicate ;
27
28
28
29
import org .codehaus .plexus .classworlds .realm .ClassRealm ;
29
30
import org .codehaus .plexus .classworlds .realm .DuplicateRealmException ;
@@ -69,22 +70,22 @@ public ClassRealm newRealm( String id )
69
70
public ClassRealm newRealm ( String id , ClassLoader classLoader )
70
71
throws DuplicateRealmException
71
72
{
72
- return newRealm ( id , classLoader , Collections . emptySet () );
73
+ return newRealm ( id , classLoader , null );
73
74
}
74
75
75
76
/**
76
77
* Shortcut for {@link #newRealm(String, ClassLoader, Set)} with the class loader of the current class.
77
78
* @param id The identifier for this realm, must not be <code>null</code>.
78
- * @param allowedResourceNamePrefixes the prefixes of resource names which should be exposed. Separator '/' is used here (even for classes).
79
+ * @param filter a predicate to apply to each resource name to determine if it should be loaded through this class loader
79
80
* @return the created class realm
80
81
* @throws DuplicateRealmException in case a realm with the given id does already exist
81
82
* @since 2.7.0
82
83
* @see FilteredClassRealm
83
84
*/
84
- public synchronized ClassRealm newRealm ( String id , Set <String > allowedResourceNamePrefixes )
85
+ public synchronized ClassRealm newRealm ( String id , Predicate <String > filter )
85
86
throws DuplicateRealmException
86
87
{
87
- return newRealm ( id , getClass ().getClassLoader (), allowedResourceNamePrefixes );
88
+ return newRealm ( id , getClass ().getClassLoader (), filter );
88
89
}
89
90
90
91
/**
@@ -93,13 +94,13 @@ public synchronized ClassRealm newRealm( String id, Set<String> allowedResourceN
93
94
* @param id The identifier for this realm, must not be <code>null</code>.
94
95
* @param classLoader The base class loader for this realm, may be <code>null</code> to use the bootstrap class
95
96
* loader.
96
- * @param allowedResourceNamePrefixes the prefixes of resource names which should be exposed. Separator '/' is used here (even for classes).
97
+ * @param filter a predicate to apply to each resource name to determine if it should be loaded through this class loader
97
98
* @return the created class realm
98
99
* @throws DuplicateRealmException in case a realm with the given id does already exist
99
100
* @since 2.7.0
100
101
* @see FilteredClassRealm
101
102
*/
102
- public synchronized ClassRealm newRealm ( String id , ClassLoader classLoader , Set <String > allowedResourceNamePrefixes )
103
+ public synchronized ClassRealm newRealm ( String id , ClassLoader classLoader , Predicate <String > filter )
103
104
throws DuplicateRealmException
104
105
{
105
106
if ( realms .containsKey ( id ) )
@@ -109,13 +110,13 @@ public synchronized ClassRealm newRealm( String id, ClassLoader classLoader, Set
109
110
110
111
ClassRealm realm ;
111
112
112
- if ( allowedResourceNamePrefixes . isEmpty () )
113
+ if ( filter == null )
113
114
{
114
115
realm = new ClassRealm ( this , id , classLoader );
115
116
}
116
117
else
117
118
{
118
- realm = new FilteredClassRealm ( allowedResourceNamePrefixes , this , id , classLoader );
119
+ realm = new FilteredClassRealm ( filter , this , id , classLoader );
119
120
}
120
121
realms .put ( id , realm );
121
122
0 commit comments