public class ClassPathUtils
extends java.lang.Object
ClassLoader
Constructor and Description |
---|
ClassPathUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
classNameToResourceName(java.lang.String className)
Get the resource name for the class file for the given class name
|
static java.lang.String |
classToResourceName(java.lang.Class<?> clazz)
Get the resource name for the class file for the given class
|
static java.nio.file.Path |
findRootPathForClass(java.lang.Class<?> clazz)
Find the root path for the given class.
|
static java.nio.file.Path |
findRootPathForResource(java.lang.String resourceName,
java.lang.ClassLoader classLoader)
Find the root path for the given resource.
|
static java.util.Set<java.nio.file.Path> |
getDirectoriesFromJar(java.nio.file.Path pathToJarFile)
Get all of the directory paths in a zip/jar file
|
static java.nio.file.Path |
getJarPathFromUrl(java.net.URL jarUrl)
Find the jar containing the given resource.
|
static java.util.Set<java.lang.String> |
getJdkPaths()
Get a list of JDK packages in the classpath, by scanning the bootstrap classpath.
|
static java.util.Set<java.lang.String> |
scanClassPath(java.lang.String classPath,
java.util.Set<java.lang.String> excludeJarSet)
Scan the classpath string provided, and collect a set of package paths found in jars and classes on the path.
|
static java.util.Set<java.lang.String> |
scanClassPath(java.lang.String classPath,
java.util.Set<java.lang.String> excludeJarSet,
java.util.Set<java.lang.String> excludePrefixes,
java.util.Set<java.lang.String> includePrefixes)
Scan the classpath string provided, and collect a set of package paths found in jars and classes on the path.
|
static java.util.Set<java.lang.String> |
scanClassPathWithExcludes(java.lang.String classPath,
java.util.Set<java.lang.String> excludeJarSet,
java.util.Set<java.lang.String> excludePrefixes)
Scan the classpath string provided, and collect a set of package paths found in jars and classes on the path,
excluding any that match a set of exclude prefixes.
|
static java.util.Set<java.lang.String> |
scanClassPathWithIncludes(java.lang.String classPath,
java.util.Set<java.lang.String> excludeJarSet,
java.util.Set<java.lang.String> includePrefixes)
Scan the classpath string provided, and collect a set of package paths found in jars and classes on the path,
including only those that match a set of include prefixes.
|
public static java.util.Set<java.lang.String> getJdkPaths()
@Nullable public static java.nio.file.Path findRootPathForResource(java.lang.String resourceName, java.lang.ClassLoader classLoader)
resourceName
- relative path of the resource to search for. E.G. "scripts/myscript.groovy"classLoader
- the ClassLoader
to search@Nullable public static java.nio.file.Path findRootPathForClass(java.lang.Class<?> clazz)
clazz
- class to search forpublic static java.nio.file.Path getJarPathFromUrl(java.net.URL jarUrl)
jarUrl
- URL that came from a jar that needs to be parsedPath
to the Jar containing the resource.public static java.util.Set<java.nio.file.Path> getDirectoriesFromJar(java.nio.file.Path pathToJarFile) throws java.io.IOException
pathToJarFile
- location of the jarfile. can also be a zipfilejava.io.IOException
public static java.lang.String classToResourceName(java.lang.Class<?> clazz)
clazz
- the class to convertClassLoader.getResource(String)
public static java.lang.String classNameToResourceName(java.lang.String className)
className
- fully qualified classname to convertClassLoader.getResource(String)
public static java.util.Set<java.lang.String> scanClassPath(java.lang.String classPath, java.util.Set<java.lang.String> excludeJarSet)
classPath
- the classpath stringexcludeJarSet
- a set of jars to exclude from scanningpublic static java.util.Set<java.lang.String> scanClassPath(java.lang.String classPath, java.util.Set<java.lang.String> excludeJarSet, java.util.Set<java.lang.String> excludePrefixes, java.util.Set<java.lang.String> includePrefixes)
classPath
- the classpath stringexcludeJarSet
- a set of jars to exclude from scanningexcludePrefixes
- a set of path prefixes that determine what is excludedincludePrefixes
- a set of path prefixes that determine what is includedpublic static java.util.Set<java.lang.String> scanClassPathWithExcludes(java.lang.String classPath, java.util.Set<java.lang.String> excludeJarSet, java.util.Set<java.lang.String> excludePrefixes)
classPath
- the classpath stringexcludeJarSet
- a set of jars to exclude from scanningexcludePrefixes
- a set of path prefixes that determine what is excludedpublic static java.util.Set<java.lang.String> scanClassPathWithIncludes(java.lang.String classPath, java.util.Set<java.lang.String> excludeJarSet, java.util.Set<java.lang.String> includePrefixes)
classPath
- the classpath stringexcludeJarSet
- a set of jars to exclude from scanningincludePrefixes
- a set of path prefixes that determine what is included