Class ClassLoaders
- java.lang.Object
-
- org.codehaus.commons.compiler.jdk.util.ClassLoaders
-
public final class ClassLoaders extends java.lang.Object
Utility methods around theClassLoader
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static interface
ClassLoaders.SubresourceGetter
-
Field Summary
Fields Modifier and Type Field Description private static ClassLoaders.SubresourceGetter
BOOTCLASSPATH_SUBRESOURCES_OF
-
Constructor Summary
Constructors Modifier Constructor Description private
ClassLoaders()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.net.URL
fileUrl(java.io.File file)
private static java.util.Map<? extends java.lang.String,? extends java.net.URL>
getBootclasspathSubresourcesOf(java.lang.String name, boolean includeDirectories, boolean recurse)
Finds subresources on the JVM's bootstrap classpath.private static java.util.Map<java.lang.String,java.net.URL>
getFileResources(java.net.URL fileUrl, java.lang.String namePrefix, boolean includeDirectories, boolean recurse)
static java.util.Map<java.lang.String,java.net.URL>
getSubresources(java.lang.ClassLoader classLoader, java.lang.String name, boolean includeDirectories)
Equivalent withgetSubresources(ClassLoader, String, boolean, boolean)
with the recurse parameter set totrue
.static java.util.Map<java.lang.String,java.net.URL>
getSubresources(java.lang.ClassLoader classLoader, java.lang.String name, boolean includeDirectories, boolean recurse)
Returns a name-to-URL mapping of all resources "under" a given directory name.private static java.util.Map<java.lang.String,java.net.URL>
getSubresources(java.net.URL jarFileUrl, java.util.jar.JarFile jarFile, java.lang.String namePrefix, boolean includeDirectories, boolean recurse)
static java.util.Map<java.lang.String,java.net.URL>
getSubresourcesOf(java.net.URL root, java.lang.String rootName, boolean includeDirectories)
Equivalent withgetSubresourcesOf(URL, String, boolean, boolean)
with the recurse parameter set totrue
.static java.util.Map<java.lang.String,java.net.URL>
getSubresourcesOf(java.net.URL root, java.lang.String rootName, boolean includeDirectories, boolean recurse)
Returns a name-to-URL mapping of all resources "under" a given root resource.
-
-
-
Field Detail
-
BOOTCLASSPATH_SUBRESOURCES_OF
private static final ClassLoaders.SubresourceGetter BOOTCLASSPATH_SUBRESOURCES_OF
-
-
Method Detail
-
getSubresources
public static java.util.Map<java.lang.String,java.net.URL> getSubresources(@Nullable java.lang.ClassLoader classLoader, java.lang.String name, boolean includeDirectories) throws java.io.IOException
Equivalent withgetSubresources(ClassLoader, String, boolean, boolean)
with the recurse parameter set totrue
.- Throws:
java.io.IOException
-
getSubresources
public static java.util.Map<java.lang.String,java.net.URL> getSubresources(@Nullable java.lang.ClassLoader classLoader, java.lang.String name, boolean includeDirectories, boolean recurse) throws java.io.IOException
Returns a name-to-URL mapping of all resources "under" a given directory name.Iff the name does not end with a slash, then calling this method is equivalent with calling
ClassLoader.getResource(String)
.Otherwise, if the name does end with a slash, then this method returns a name-to-URL mapping of all content resources who's names begin with the given name. Iff recurse is
false
, then only immediate subresources are included. Iff includeDirectories istrue
, then also directory resources are included in the result set; their names all ending with a slash.If multiple resources have the name, then the resources are retrieved from the first occurrence.
- Parameters:
classLoader
- The class loader to use;null
means use the system class loadername
- No leading slash- Returns:
- Keys ending with a slash map to "directory resources", the other keys map to "content resources"
- Throws:
java.io.IOException
-
getBootclasspathSubresourcesOf
private static java.util.Map<? extends java.lang.String,? extends java.net.URL> getBootclasspathSubresourcesOf(java.lang.String name, boolean includeDirectories, boolean recurse) throws java.io.IOException
Finds subresources on the JVM's bootstrap classpath. This is kind of tricky because the .jar files on the BOOTCLASSPATH don't contain "directory entries".- Throws:
java.io.IOException
-
getSubresourcesOf
public static java.util.Map<java.lang.String,java.net.URL> getSubresourcesOf(java.net.URL root, java.lang.String rootName, boolean includeDirectories) throws java.io.IOException
Equivalent withgetSubresourcesOf(URL, String, boolean, boolean)
with the recurse parameter set totrue
.- Throws:
java.io.IOException
-
getSubresourcesOf
public static java.util.Map<java.lang.String,java.net.URL> getSubresourcesOf(java.net.URL root, java.lang.String rootName, boolean includeDirectories, boolean recurse) throws java.io.IOException
Returns a name-to-URL mapping of all resources "under" a given root resource.If the root designates a "content resource" (as opposed to a "directory resource"), then the method returns
Collections.singletonMap(name, rootName)
.Otherwise, if the root designates a "directory resource", then this method returns a name-to-URL mapping of all content resources that are located "under" the root resource. Iff recurse is
false
, then only immediate subresources are included. Iff includeDirectories istrue
, then directory resources are also included in the result set; their names all ending with a slash.- Returns:
- Keys ending with a slash map to "directory resources", the other keys map to "content resources"
- Throws:
java.io.IOException
-
getSubresources
private static java.util.Map<java.lang.String,java.net.URL> getSubresources(java.net.URL jarFileUrl, java.util.jar.JarFile jarFile, java.lang.String namePrefix, boolean includeDirectories, boolean recurse)
-
getFileResources
private static java.util.Map<java.lang.String,java.net.URL> getFileResources(java.net.URL fileUrl, java.lang.String namePrefix, boolean includeDirectories, boolean recurse)
-
fileUrl
private static java.net.URL fileUrl(java.io.File file)
-
-