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 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
    • 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