spring-projects-experimental / spring-boot-migrator

Spring Boot Migrator (SBM) is a tool for automated code migrations to upgrade or migrate to Spring Boot
Apache License 2.0
444 stars 88 forks source link

Publish parsing events registered through the `ExecutionContext` as Spring application events #892

Closed fabapp2 closed 1 year ago

fabapp2 commented 1 year ago

This has been done.

OpenRewrite allows registering a ParsingEventListener with the ExecutionContext. The listener will then be informed about parsed resources. A RewriteParsingEventListenerAdapter implements the ParsingEventListener and publishes ParsedResourceEvent as Spring application events copying the information provided to the listener.

See RewriteProjectParserIntegrationTest

Events

Spring @EventListsner can be used to listen to these events

@EventListener(ParsedResourceEvent.class)
public void onEvent(ParsedResourceEvent event) {
    // handle new parsed resource
}

@EventListener(StartedParsingProjectEvent.class)
public void onStartedParsingProjectEvent(StartedParsingProjectEvent event) {
    // handle start of parsing
}

@EventListener(FinishedParsingProjectEvent.class)
public void onFinishedParsingProjectEvent(FinishedParsingProjectEvent event) {
    // handle finish parsing
}
fabapp2 commented 1 year ago

This has been implemented already