migrate_jackson3.py 963 B

12345678910111213141516171819202122232425262728293031323334
  1. # -*- coding: utf-8 -*-
  2. """Spring Boot 4 / Jackson 3 迁移:包名批量替换。
  3. Jackson 3 把 com.fasterxml.jackson.databind|core 迁到 tools.jackson.*,
  4. 但注解(com.fasterxml.jackson.annotation)为向后兼容保持在原包,不能动。
  5. 用法:python tools/migrate_jackson3.py [--dry]
  6. """
  7. import sys
  8. from _root import ROOT
  9. SRC = ROOT / "yoshop-java/src/main/java"
  10. RULES = [
  11. ("com.fasterxml.jackson.databind", "tools.jackson.databind"),
  12. ("com.fasterxml.jackson.core", "tools.jackson.core"),
  13. ]
  14. dry = "--dry" in sys.argv
  15. changed = []
  16. for f in SRC.rglob("*.java"):
  17. text = f.read_text(encoding="utf-8")
  18. new = text
  19. for old, rep in RULES:
  20. new = new.replace(old, rep)
  21. if new != text:
  22. changed.append(f)
  23. if not dry:
  24. f.write_text(new, encoding="utf-8")
  25. print("%s %d files" % ("would change" if dry else "changed", len(changed)))
  26. for f in changed[:10]:
  27. print(" ", f.relative_to(ROOT))