Skip to content

feat: incremental AST processing with AutoCloseable resource management - #93

Merged
yannickebongue merged 2 commits into
mainfrom
feature/incremental-ast-processing
Oct 22, 2026
Merged

yannickebongue merged 2 commits into
mainfrom
feature/incremental-ast-processing

Conversation

@yannickebongue

Copy link
Copy Markdown
Contributor

Summary

Add incremental compilation support to the Jakarta Persistence Gradle linter task and make NamedObjectParser AutoCloseable to prevent Hibernate resource leaks.

This PR touches 20 files across both the libraries and plugins modules, delivering two tightly coupled improvements: a resource-safe parser SPI and a delta-aware Gradle task that leverages it.


Libraries — AutoCloseable NamedObjectParser

  • NamedObjectParser SPI now extends AutoCloseable, giving callers a clear lifecycle contract for releasing Hibernate internals.
  • JakartaNamedObjectParser reuses a single SessionFactory and HqlTranslator across parseQuery calls instead of rebuilding per invocation; close() destroys both the SessionFactory and ServiceRegistry.
  • LegacyNamedObjectParser receives equivalent close() cleanup logic.
  • JakartaSchemaValidator / LegacySchemaValidator refactored to use try-with-resources for BootstrapServiceRegistry and StandardServiceRegistry.
  • NamedObjectParserFactory Javadoc updated to document the caller's responsibility for closing.
  • Unit tests updated in both Jakarta and Legacy modules to cover the new AutoCloseable behaviour.
  • libraries/README.md updated with try-with-resources usage examples.

Plugins — Incremental Compilation & Worker Refactoring

  • LintNamedQueries task now uses Gradle's InputChanges API with an @Incremental ConfigurableFileTree input, enabling delta-aware class-file tracking instead of full rescans.
  • Added @OutputFile JSON execution-metrics report for Gradle build-cache compatibility.
  • LintNamedQueriesWorker receives incrementalPass, affectedClassFiles, and removedClassFiles parameters; only changed bytecodes are routed through the ASM sweep on delta passes.
  • Extracted Helper.sweepClassFile() utility to deduplicate ASM scanning logic.
  • NamedObjectParser wrapped in withCloseable to honour the new AutoCloseable SPI contract.
  • Plugin registration wires an explicit dependsOn(compileJava) dependency and routes the lint report output to the build/reports layout.
  • Functional tests expanded with three incremental-compilation scenarios (new entity, no-op modification, entity deletion) and adjusted error assertions to match eager metamodel validation.
  • plugins/README.md, AsciiDoc, and overview.html documentation updated to reflect the new features.

Other

  • Bumped lint-persistence version from 2.1.0 → 2.2.0 in gradle/libs.versions.toml.

How to Verify

  1. Run the existing and new functional tests:

…urce leaks

Make NamedObjectParser extend AutoCloseable so that the underlying
Hibernate SessionFactory and ServiceRegistry are properly released
after use.

- Extend NamedObjectParser SPI with AutoCloseable
- Add close() to JakartaNamedObjectParser to destroy SessionFactory
  and ServiceRegistry; reuse a single SessionFactory and HqlTranslator
  across parseQuery calls instead of rebuilding per invocation
- Add close() to LegacyNamedObjectParser with equivalent cleanup
- Refactor JakartaSchemaValidator to use try-with-resources for
  BootstrapServiceRegistry and StandardServiceRegistry
- Update LegacySchemaValidator with matching resource management
- Update NamedObjectParserFactory Javadoc to document caller
  responsibility for closing
- Update README with try-with-resources usage examples
…up to linter task

Refactor LintNamedQueries to leverage Gradle's InputChanges API for
incremental builds, and adopt try-with-resources for the
NamedObjectParser to prevent Hibernate resource leaks.

- Replace DirectoryProperty input with @incremental ConfigurableFileTree
  to enable delta-aware class file tracking
- Add incremental/affected/removed file parameters to the worker and
  route only changed bytecodes through the ASM sweep on delta passes
- Wrap NamedObjectParser in withCloseable to match the new AutoCloseable
  SPI contract and ensure SessionFactory cleanup
- Add @OutputFile JSON execution metrics report for Gradle cache
  compatibility
- Extract Helper.sweepClassFile() to deduplicate ASM scanning logic
- Wire explicit dependsOn(compileJava) and route lint report output to
  build/reports layout in plugin registration
- Update functional tests: adjust error assertion to match eager
  metamodel validation, add three incremental compilation scenarios
  (new entity, no-op modification, entity deletion)
@yannickebongue yannickebongue self-assigned this Oct 22, 2026
@yannickebongue yannickebongue added documentation Improvements or additions to documentation enhancement New feature or request java Pull requests that update java code performance Improves build execution speeds, task caching, and incremental processing velocity. libraries Java Core SPI engine modules (Maven Central artifacts) plugins Gradle plugin wrappers (Gradle Plugin Portal artifacts) labels Oct 22, 2026
@sonarqubecloud

Copy link
Copy Markdown

@yannickebongue yannickebongue linked an issue Oct 22, 2026 that may be closed by this pull request
2 tasks
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed for 'persistence-plugins'

Failed conditions
64.6% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@yannickebongue
yannickebongue merged commit a893a49 into main Oct 22, 2026
3 of 4 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in JPersist Core Roadmap Oct 22, 2026
@yannickebongue
yannickebongue deleted the feature/incremental-ast-processing branch October 22, 2026 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request java Pull requests that update java code libraries Java Core SPI engine modules (Maven Central artifacts) performance Improves build execution speeds, task caching, and incremental processing velocity. plugins Gradle plugin wrappers (Gradle Plugin Portal artifacts)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[FEAT] High-Velocity AST Incremental Processing

1 participant