Class DeprecationCatalog

java.lang.Object
com.patbaumgartner.spring.migrator.core.DeprecationCatalog

public final class DeprecationCatalog extends Object
The set of deprecated properties known to the configuration metadata on a project's classpath, indexed so that lookups honour Spring Boot's relaxed binding.

The catalog also knows the declared type of every metadata property, which lets the engine detect renames whose value would no longer be valid, and it resolves chained deprecations (a -> b -> c) to their terminal replacement so that migrating twice is a no-op.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns whether migrating from to to is known to change the value type, which means the existing value is unlikely to remain valid.
    int
    Returns how many deprecated properties the catalog knows about.
    boolean
    Returns whether the metadata describes at least one property in a namespace.
    Returns an empty catalog, used when no metadata could be resolved.
    find(String key)
    Looks up a deprecated property, honouring relaxed binding so that server.maxHttpHeaderSize matches server.max-http-header-size.
    from(Map<String,org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty> metadataProperties)
    Builds a catalog from raw configuration metadata properties.
    boolean
    Returns whether the catalog holds no metadata at all, which usually means the project classpath could not be resolved rather than that the project is clean.
    boolean
    Returns whether the metadata describes the given key, honouring the fact that aggregate properties are declared at their prefix rather than per entry.
    Follows chained deprecations to the property a user should end up with.
    Returns the declared type of a property, when the metadata knows it.

    Methods inherited from class java.lang.Object

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

    • from

      public static DeprecationCatalog from(Map<String,org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty> metadataProperties)
      Builds a catalog from raw configuration metadata properties.
      Parameters:
      metadataProperties - all properties known to the resolved metadata repository
      Returns:
      the catalog
    • empty

      public static DeprecationCatalog empty()
      Returns an empty catalog, used when no metadata could be resolved.
      Returns:
      an empty catalog
    • find

      public Optional<DeprecatedProperty> find(String key)
      Looks up a deprecated property, honouring relaxed binding so that server.maxHttpHeaderSize matches server.max-http-header-size.
      Parameters:
      key - the property name exactly as written in the configuration file
      Returns:
      the deprecation, if the property is deprecated
    • resolveReplacement

      public Optional<String> resolveReplacement(DeprecatedProperty property)
      Follows chained deprecations to the property a user should end up with.

      Metadata may declare a -> b while b is itself deprecated in favour of c. Migrating straight to c keeps a second migration run a no-op.

      Parameters:
      property - the deprecated property to resolve
      Returns:
      the terminal replacement, or empty when the chain is cyclic
    • changesType

      public boolean changesType(String from, String to)
      Returns whether migrating from to to is known to change the value type, which means the existing value is unlikely to remain valid.

      A missing type on either side is not treated as a mismatch: the metadata simply does not say, and refusing to migrate then would block many safe renames.

      Parameters:
      from - the deprecated property name
      to - the replacement property name
      Returns:
      whether both types are known and differ
    • typeOf

      public Optional<String> typeOf(String key)
      Returns the declared type of a property, when the metadata knows it.
      Parameters:
      key - the property name
      Returns:
      the fully qualified type name
    • isKnown

      public boolean isKnown(String key)
      Returns whether the metadata describes the given key, honouring the fact that aggregate properties are declared at their prefix rather than per entry.

      A Map-typed property such as logging.level stands for every key written below it, and a collection-typed property such as spring.config.import stands for every indexed element. Without that rule every map entry in a project would look unrecognised.

      Parameters:
      key - the property name exactly as written in the configuration file
      Returns:
      whether the key is backed by a metadata property
    • describesNamespace

      public boolean describesNamespace(String namespace)
      Returns whether the metadata describes at least one property in a namespace.

      This is what tells an absent optional module apart from a wrong key. When Actuator is not on the classpath nothing describes management.*, and every key a project writes there would otherwise look unrecognised.

      Parameters:
      namespace - the top-level namespace, such as management
      Returns:
      whether any known property lives under the namespace
    • isEmpty

      public boolean isEmpty()
      Returns whether the catalog holds no metadata at all, which usually means the project classpath could not be resolved rather than that the project is clean.
      Returns:
      whether no metadata was loaded
    • deprecationCount

      public int deprecationCount()
      Returns how many deprecated properties the catalog knows about.
      Returns:
      the number of deprecated properties