Class MigrationEngine

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

public final class MigrationEngine extends Object
Plans and applies migrations of deprecated Spring Boot configuration properties.

The engine never rewrites a whole file. It parses a document, locates the exact source span of each deprecated key and replaces only those spans, so line terminators, indentation, comments, quoting and the presence or absence of a trailing newline all survive untouched, and the resulting diff shows only the keys that actually changed.

A key is rewritten only when doing so is provably safe. Anything else - a replacement whose value type changed, a target that already exists, several keys collapsing onto one replacement, or a YAML key whose replacement belongs under a different parent - is reported for manual action rather than guessed at.

  • Constructor Details

    • MigrationEngine

      public MigrationEngine()
  • Method Details

    • plan

      public MigrationPlan plan(Path rootDir, List<Path> files, DeprecationCatalog catalog, String springBootVersion)
      Analyses the given files without modifying anything.
      Parameters:
      rootDir - the project root, used to render relative paths
      files - the configuration files to analyse
      catalog - the deprecations known to the project's classpath
      springBootVersion - the detected Spring Boot version, or null
      Returns:
      the plan describing every finding and every pending write
    • plan

      public MigrationPlan plan(Path rootDir, List<Path> files, DeprecationCatalog catalog, String springBootVersion, UnknownKeyOptions unknownKeys)
      Analyses the given files without modifying anything.
      Parameters:
      rootDir - the project directory that paths are reported relative to
      files - the configuration files to inspect
      catalog - the deprecations known to the project classpath
      springBootVersion - the detected Spring Boot version, or null
      unknownKeys - how to treat keys the metadata does not describe
      Returns:
      the plan describing every finding and every pending write
    • apply

      public void apply(MigrationPlan plan) throws IOException
      Writes every pending change from a plan.

      Each file is written to a sibling temporary file and then moved into place, so an interrupted run cannot leave a half-written configuration file behind.

      Parameters:
      plan - the plan to apply
      Throws:
      IOException - if a file cannot be written