Class ArchConfiguration

java.lang.Object
com.tngtech.archunit.ArchConfiguration

public final class ArchConfiguration extends Object
Allows access to configured properties in "archunit.properties".
  • Field Details

  • Method Details

    • get

      @PublicAPI(usage=ACCESS) public static ArchConfiguration get()
    • reset

      @PublicAPI(usage=ACCESS) public void reset()
    • resolveMissingDependenciesFromClassPath

      @PublicAPI(usage=ACCESS) public boolean resolveMissingDependenciesFromClassPath()
    • setResolveMissingDependenciesFromClassPath

      @PublicAPI(usage=ACCESS) public void setResolveMissingDependenciesFromClassPath(boolean newValue)
    • md5InClassSourcesEnabled

      @PublicAPI(usage=ACCESS) public boolean md5InClassSourcesEnabled()
    • setMd5InClassSourcesEnabled

      @PublicAPI(usage=ACCESS) public void setMd5InClassSourcesEnabled(boolean enabled)
    • getClassResolver

      @PublicAPI(usage=ACCESS) public Optional<String> getClassResolver()
    • setClassResolver

      @PublicAPI(usage=ACCESS) public void setClassResolver(Class<? extends ClassResolver> classResolver)
    • unsetClassResolver

      @PublicAPI(usage=ACCESS) public void unsetClassResolver()
    • getClassResolverArguments

      @PublicAPI(usage=ACCESS) public List<String> getClassResolverArguments()
    • setClassResolverArguments

      @PublicAPI(usage=ACCESS) public void setClassResolverArguments(String... args)
    • setExtensionProperties

      @PublicAPI(usage=ACCESS) public void setExtensionProperties(String extensionIdentifier, Properties properties)
    • getExtensionProperties

      @PublicAPI(usage=ACCESS) public Properties getExtensionProperties(String extensionIdentifier)
    • configureExtension

      @PublicAPI(usage=ACCESS) public ArchConfiguration.ExtensionProperties configureExtension(String extensionIdentifier)
    • getSubProperties

      @PublicAPI(usage=ACCESS) public Properties getSubProperties(String propertyPrefix)
      Returns a set of properties where all keys share a common prefix. The prefix is removed from those property names. Example:
      
       some.custom.prop1=value1
       some.custom.prop2=value2
       unrelated=irrelevant
      Then getSubProperties("some.custom") would return the properties
      
       prop1=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

      @PublicAPI(usage=ACCESS) public boolean containsProperty(String propertyName)
      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

      @PublicAPI(usage=ACCESS) public String getProperty(String propertyName)
      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

      @PublicAPI(usage=ACCESS) public void setProperty(String propertyName, String value)
      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 property
      value - 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 property
      defaultValue - 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 as withThreadLocalScope(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 current ArchConfiguration to be freely modified. Within the current thread and the scope of doWithThreadLocalConfiguration ArchConfiguration.get() will return the thread local configuration, i.e. adjustments to the configuration passed to doWithThreadLocalConfiguration will be picked up by ArchUnit while executing from this thread within the scope of doWithThreadLocalConfiguration.

      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 local ArchConfiguration 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.