Class Locations

java.lang.Object
com.tngtech.archunit.core.importer.Locations

public final class Locations
extends java.lang.Object
Represents a set of locations of Java class files. Also offers methods to derive concrete locations (i.e. URIs) from higher level concepts like packages or the classpath.
  • Method Summary

    Modifier and Type Method Description
    static java.util.Set<Location> inClassPath()  
    static java.util.Set<Location> of​(java.lang.Iterable<java.net.URL> urls)
    Directly converts the passed URLs to locations.
    static java.util.Set<Location> ofClass​(java.lang.Class<?> clazz)
    Set of locations where the class file of the supplied class can be found.
    Note that this is really a set, since the same (or in bad cases a different version of the same) class might be found within the classpath several times.
    static java.util.Set<Location> ofPackage​(java.lang.String pkg)
    All locations in the classpath that match the supplied package.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • of

      @PublicAPI(usage=ACCESS) public static java.util.Set<Location> of​(java.lang.Iterable<java.net.URL> urls)
      Directly converts the passed URLs to locations. URLs can be of class files as well as directories. They can also be JAR URLs of class files (e.g. jar:file:///some.jar!/some/Example.class) or folders within JAR files.
      Parameters:
      urls - URLs to directly convert to locations
      Returns:
      Locations representing the passed URLs
    • ofPackage

      @PublicAPI(usage=ACCESS) public static java.util.Set<Location> ofPackage​(java.lang.String pkg)
      All locations in the classpath that match the supplied package.
      Parameters:
      pkg - the package to look for within the classpath
      Returns:
      Locations of all paths that match the supplied package
    • ofClass

      @PublicAPI(usage=ACCESS) public static java.util.Set<Location> ofClass​(java.lang.Class<?> clazz)
      Set of locations where the class file of the supplied class can be found.
      Note that this is really a set, since the same (or in bad cases a different version of the same) class might be found within the classpath several times.
      Parameters:
      clazz - A Class to import
      Returns:
      Locations of the respective class file within the classpath
    • inClassPath

      @PublicAPI(usage=ACCESS) public static java.util.Set<Location> inClassPath()
      Returns:
      All classes that can be found within the classpath. Note that ArchUnit does not distinguish between the classpath and the modulepath, thus for Java >= 9 all locations of class files from the modulepath with be returned as well.