Class ClassFileImporter
- java.lang.Object
-
- com.tngtech.archunit.core.importer.ClassFileImporter
-
public final class ClassFileImporter extends java.lang.Object
The central API to importJavaClasses
. Supports various types ofLocation
, e.g.Path
,JarFile
orURL
. TheLocation
s that are scanned, can be filtered by passing any number ofImportOption
towithImportOption(ImportOption)
, which will then be ANDed (compareImportOptions
).
Note that information about a class is only complete, if all necessary classes are imported. For example, if class A is imported, and A accesses class B, but class B is not imported, the import will behave according to the configuredClassResolver
. With the default configuration, the importer will just create a stub with all information known from the access, i.e. the fully qualified name of B and not much more. In particular the stub class B will miss any information like super classes, interfaces, etc. The stub class B will also miss information like "accesses to self" and similar. In short, if one wants to write rules about certain properties of classes, it is important to ensure that all relevant classes are imported, even if those might be classes from the JDK (likeRuntimeException
orException
).
The resolution behavior, i.e. what the importer does if a class is missing from the context, can be configured by providing a respectiveClassResolver
. ArchUnit provides a secondClassResolver
to import referenced classes more widely, namely theClassResolverFromClasspath
. This resolver will attempt to import missing classes from the classpath, and by that complete any information necessary for rules. In the above case this would mean, if class A accesses B, but B is missing from the set of imported classes, the importer will try to locate the class on the classpath and then import that class, thus acquiring more information like superclasses and interfaces. However, it will not transitively go on to resolve access targets of these classes.
TheClassResolverFromClasspath
can easily be activated by setting
within your "/archunit.properties". For further information consult the ArchUnit user guide."resolveMissingDependenciesFromClassPath"=true
- See Also:
ArchConfiguration
-
-
Constructor Summary
Constructors Constructor Description ClassFileImporter()
ClassFileImporter(ImportOptions importOptions)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JavaClass
importClass(java.lang.Class<?> clazz)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.JavaClasses
importClasses(java.lang.Class<?>... classes)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.JavaClasses
importClasses(java.util.Collection<java.lang.Class<?>> classes)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.JavaClasses
importClasspath()
Imports classes from the whole classpath without archives (JARs or JRTs).JavaClasses
importClasspath(ImportOptions options)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.JavaClasses
importJar(java.util.jar.JarFile jar)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.JavaClasses
importJars(java.lang.Iterable<java.util.jar.JarFile> jarFiles)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.JavaClasses
importJars(java.util.jar.JarFile... jarFiles)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.JavaClasses
importLocations(java.util.Collection<Location> locations)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.JavaClasses
importPackages(java.lang.String... packages)
Imports packages viaLocations.ofPackage(String)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.JavaClasses
importPackages(java.util.Collection<java.lang.String> packages)
Imports packages viaLocations.ofPackage(String)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.JavaClasses
importPackagesOf(java.lang.Class<?>... classes)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.JavaClasses
importPackagesOf(java.util.Collection<java.lang.Class<?>> classes)
Takes the packages of the supplied classes and delegates toimportPackages(String...)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.JavaClasses
importPath(java.lang.String path)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.JavaClasses
importPath(java.nio.file.Path path)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.JavaClasses
importPaths(java.lang.String... paths)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.JavaClasses
importPaths(java.nio.file.Path... paths)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.JavaClasses
importPaths(java.util.Collection<java.nio.file.Path> paths)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.JavaClasses
importUrl(java.net.URL url)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.JavaClasses
importUrls(java.util.Collection<java.net.URL> urls)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.ClassFileImporter
withImportOption(ImportOption option)
-
-
-
Constructor Detail
-
ClassFileImporter
@PublicAPI(usage=ACCESS) public ClassFileImporter()
-
ClassFileImporter
@PublicAPI(usage=ACCESS) public ClassFileImporter(ImportOptions importOptions)
-
-
Method Detail
-
withImportOption
@PublicAPI(usage=ACCESS) public ClassFileImporter withImportOption(ImportOption option)
-
importPath
@PublicAPI(usage=ACCESS) public JavaClasses importPath(java.lang.String path)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.
-
importPath
@PublicAPI(usage=ACCESS) public JavaClasses importPath(java.nio.file.Path path)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.
-
importPaths
@PublicAPI(usage=ACCESS) public JavaClasses importPaths(java.lang.String... paths)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.
-
importPaths
@PublicAPI(usage=ACCESS) public JavaClasses importPaths(java.nio.file.Path... paths)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.
-
importPaths
@PublicAPI(usage=ACCESS) public JavaClasses importPaths(java.util.Collection<java.nio.file.Path> paths)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.
-
importJar
@PublicAPI(usage=ACCESS) public JavaClasses importJar(java.util.jar.JarFile jar)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.
-
importJars
@PublicAPI(usage=ACCESS) public JavaClasses importJars(java.util.jar.JarFile... jarFiles)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.
-
importJars
@PublicAPI(usage=ACCESS) public JavaClasses importJars(java.lang.Iterable<java.util.jar.JarFile> jarFiles)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.
-
importPackages
@PublicAPI(usage=ACCESS) public JavaClasses importPackages(java.util.Collection<java.lang.String> packages)
Imports packages viaLocations.ofPackage(String)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.
-
importPackages
@PublicAPI(usage=ACCESS) public JavaClasses importPackages(java.lang.String... packages)
Imports packages viaLocations.ofPackage(String)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.
-
importPackagesOf
@PublicAPI(usage=ACCESS) public JavaClasses importPackagesOf(java.lang.Class<?>... classes)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.- See Also:
importPackagesOf(Collection)
-
importPackagesOf
@PublicAPI(usage=ACCESS) public JavaClasses importPackagesOf(java.util.Collection<java.lang.Class<?>> classes)
Takes the packages of the supplied classes and delegates toimportPackages(String...)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.
-
importClasspath
@PublicAPI(usage=ACCESS) public JavaClasses importClasspath()
Imports classes from the whole classpath without archives (JARs or JRTs).
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.- Returns:
- Imported classes
-
importClasspath
@PublicAPI(usage=ACCESS) public JavaClasses importClasspath(ImportOptions options)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.
-
importClass
@PublicAPI(usage=ACCESS) public JavaClass importClass(java.lang.Class<?> clazz)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.
-
importClasses
@PublicAPI(usage=ACCESS) public JavaClasses importClasses(java.lang.Class<?>... classes)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.
-
importClasses
@PublicAPI(usage=ACCESS) public JavaClasses importClasses(java.util.Collection<java.lang.Class<?>> classes)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.
-
importUrl
@PublicAPI(usage=ACCESS) public JavaClasses importUrl(java.net.URL url)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.
-
importUrls
@PublicAPI(usage=ACCESS) public JavaClasses importUrls(java.util.Collection<java.net.URL> urls)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.
-
importLocations
@PublicAPI(usage=ACCESS) public JavaClasses importLocations(java.util.Collection<Location> locations)
For information about the impact of the imported classes on the evaluation of rules, as well as configuration and details, refer toClassFileImporter
.
-
-