Package com.tngtech.archunit
Class ArchConfiguration
java.lang.Object
com.tngtech.archunit.ArchConfiguration
Allows access to configured properties in "archunit.properties".
-
Nested Class Summary
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionconfigureExtension
(String extensionIdentifier) boolean
containsProperty
(String propertyName) static ArchConfiguration
get()
getExtensionProperties
(String extensionIdentifier) getProperty
(String propertyName) getPropertyOrDefault
(String propertyName, String defaultValue) getSubProperties
(String propertyPrefix) Returns a set of properties where all keys share a common prefix.boolean
void
reset()
boolean
void
setClassResolver
(Class<? extends ClassResolver> classResolver) void
setClassResolverArguments
(String... args) void
setExtensionProperties
(String extensionIdentifier, Properties properties) void
setMd5InClassSourcesEnabled
(boolean enabled) void
setProperty
(String propertyName, String value) Overwrites a property of the global ArchUnit configuration.void
setResolveMissingDependenciesFromClassPath
(boolean newValue) void
static void
withThreadLocalScope
(Consumer<ArchConfiguration> doWithThreadLocalConfiguration) Same aswithThreadLocalScope(Function)
but does not return a value.static <T> T
withThreadLocalScope
(Function<ArchConfiguration, T> doWithThreadLocalConfiguration) Sets up a thread local copy of the currentArchConfiguration
to be freely modified.
-
Field Details
-
ARCHUNIT_PROPERTIES_RESOURCE_NAME
- See Also:
-
RESOLVE_MISSING_DEPENDENCIES_FROM_CLASS_PATH
- See Also:
-
ENABLE_MD5_IN_CLASS_SOURCES
- See Also:
-
-
Method Details
-
get
-
reset
-
resolveMissingDependenciesFromClassPath
-
setResolveMissingDependenciesFromClassPath
-
md5InClassSourcesEnabled
-
setMd5InClassSourcesEnabled
-
getClassResolver
-
setClassResolver
-
unsetClassResolver
-
getClassResolverArguments
-
setClassResolverArguments
-
setExtensionProperties
@PublicAPI(usage=ACCESS) public void setExtensionProperties(String extensionIdentifier, Properties properties) -
getExtensionProperties
-
configureExtension
@PublicAPI(usage=ACCESS) public ArchConfiguration.ExtensionProperties configureExtension(String extensionIdentifier) -
getSubProperties
Returns a set of properties where all keys share a common prefix. The prefix is removed from those property names. Example:
Thensome.custom.prop1=value1 some.custom.prop2=value2 unrelated=irrelevant
getSubProperties("some.custom")
would return the propertiesprop1=value1 prop2=value2
- Parameters:
propertyPrefix
- A prefix for a set of properties- Returns:
- All properties with this prefix, where the prefix is removed from the keys.
-
containsProperty
- Parameters:
propertyName
- Full name of a property- Returns:
- true, if and only if the property is configured within the global ArchUnit configuration.
- See Also:
-
getProperty
- Parameters:
propertyName
- Full name of a property- Returns:
- A property of the global ArchUnit configuration. This method will throw an exception if the property is not set within the configuration.
- See Also:
-
setProperty
Overwrites a property of the global ArchUnit configuration. Note that this change will persist for the whole life time of this JVM unless overwritten another time.- Parameters:
propertyName
- Full name of a propertyvalue
- The new value to set. Overwrites any existing property with the same name.- See Also:
-
getPropertyOrDefault
@PublicAPI(usage=ACCESS) public String getPropertyOrDefault(String propertyName, String defaultValue) - Parameters:
propertyName
- Full name of a propertydefaultValue
- A value to return if property is not configured- Returns:
- The property of the global ArchUnit configuration with the supplied name
or
defaultValue
if this property is not configured.
-
withThreadLocalScope
@PublicAPI(usage=ACCESS) public static void withThreadLocalScope(Consumer<ArchConfiguration> doWithThreadLocalConfiguration) Same aswithThreadLocalScope(Function)
but does not return a value. -
withThreadLocalScope
@PublicAPI(usage=ACCESS) public static <T> T withThreadLocalScope(Function<ArchConfiguration, T> doWithThreadLocalConfiguration) Sets up a thread local copy of the currentArchConfiguration
to be freely modified. Within the current thread and the scope ofdoWithThreadLocalConfiguration
ArchConfiguration.get()
will return the thread local configuration, i.e. adjustments to the configuration passed todoWithThreadLocalConfiguration
will be picked up by ArchUnit while executing from this thread within the scope ofdoWithThreadLocalConfiguration
.
For example:ArchConfiguration.get().setResolveMissingDependenciesFromClassPath(true); JavaClasses classesWithoutResolvingFromClasspath = ArchConfiguration.withThreadLocalScope((ArchConfiguration configuration) -> { configuration.setResolveMissingDependenciesFromClassPath(false); return new ClassFileImporter().importPackages(..) // will now not resolve from classpath }); JavaClasses classesWithResolvingFromClasspath = new ClassFileImporter().importPackages(..) // will now see the original value and resolve from classpath
- Parameters:
doWithThreadLocalConfiguration
- A lambda that allows to execute code that will see the thread localArchConfiguration
instead of the global one. Once the lambda has been executed the thread local configuration is cleaned up and all threads will see the global configuration again.
-