com.atlassian.confluence.util
Class ClasspathUtils

java.lang.Object
  extended by com.atlassian.confluence.util.ClasspathUtils

public class ClasspathUtils
extends java.lang.Object

Classpath discovery utilities


Constructor Summary
ClasspathUtils()
           
 
Method Summary
static java.util.List<java.lang.String> getClassesFromJar(java.net.URL jarUrl)
          Get a list of class files in the JAR specified by a URL.
static ClasspathClasses getClassesInClasspathJars()
          Gets a list of JARs from the thread context classloader, and returns a ClasspathClasses object with the class file names and the JARs which they appear in.
static java.util.List<java.net.URL> getClassLoaderClasspath(java.lang.ClassLoader classloader)
          Get the classpath searched for by a particular classloader (only supports URLClassLoaders presently)
static ClasspathClasses getFilesInClasspathJars()
          Gets a list of JARs from the thread context classloader, and returns a ClasspathClasses object with the class file names and the JARs which they appear in.
static java.net.URL[] getSystemClasspath()
          This method will return an array of URLs used by the system classloader.
static java.util.List<java.lang.ClassLoader> getThreadContentClassLoaderHierarchy()
          Get a list of classloaders in the thread context classloader hierarchy
static java.net.URL[] getThreadContextClasspath()
          This method will return an array of URLs used by the thread context classloader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClasspathUtils

public ClasspathUtils()
Method Detail

getSystemClasspath

public static java.net.URL[] getSystemClasspath()
This method will return an array of URLs used by the system classloader. If the system classloader is not an instance of URLClassLoader, this method will return null

Returns:
Array of URLs in classpath lookup order or null if system classloader does not support classpath discovery

getThreadContextClasspath

public static java.net.URL[] getThreadContextClasspath()
This method will return an array of URLs used by the thread context classloader. This method will search the classloader hierarchy for all classloaders of class URLClassLoader and return all URLs searched by these classloaders in order of discovery. If no such classloaders are found this method will return null

Returns:
Array of URLs in classpath as reported by all URLClassLoaders in the classloader hierarchy, null if no such classloaders exist.

getThreadContentClassLoaderHierarchy

public static java.util.List<java.lang.ClassLoader> getThreadContentClassLoaderHierarchy()
Get a list of classloaders in the thread context classloader hierarchy

Returns:
list of classloaders in order of delegation

getClassLoaderClasspath

public static java.util.List<java.net.URL> getClassLoaderClasspath(java.lang.ClassLoader classloader)
Get the classpath searched for by a particular classloader (only supports URLClassLoaders presently)

Parameters:
classloader - to examine
Returns:
List of paths searched on by the classloader, or null if the classloader does not support path discovery

getClassesFromJar

public static java.util.List<java.lang.String> getClassesFromJar(java.net.URL jarUrl)
Get a list of class files in the JAR specified by a URL.

Parameters:
jarUrl - the URL of a JAR on the classpath, such as one of the items in the list returned by getClassLoaderClasspath(ClassLoader)
Returns:
a List of Strings which are the class files in the JAR, an empty list if the JAR contains no class files or null if the JAR cannot be opened.

getClassesInClasspathJars

public static ClasspathClasses getClassesInClasspathJars()
Gets a list of JARs from the thread context classloader, and returns a ClasspathClasses object with the class file names and the JARs which they appear in. Useful for finding duplicate classes in the classpath.

Returns:
a ClasspathClasses object contains classes found in JARs on the classpath. If the thread context classloader is not a URLClassLoader, returns null.
See Also:
getThreadContextClasspath()

getFilesInClasspathJars

public static ClasspathClasses getFilesInClasspathJars()
Gets a list of JARs from the thread context classloader, and returns a ClasspathClasses object with the class file names and the JARs which they appear in. Useful for finding duplicate classes in the classpath.

Returns:
a ClasspathClasses object contains classes found in JARs on the classpath. If the thread context classloader is not a URLClassLoader, returns null.
See Also:
getThreadContextClasspath()


Copyright © 2003-2014 Atlassian. All Rights Reserved.