Skip to content

Introduce recipe-scoped beans #786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task
fabapp2 opened this issue May 9, 2023 Discussed in #785 · 0 comments · Fixed by #792
Closed
1 task

Introduce recipe-scoped beans #786

fabapp2 opened this issue May 9, 2023 Discussed in #785 · 0 comments · Fixed by #792
Assignees
Labels
type: enhancement New feature or request

Comments

@fabapp2
Copy link
Contributor

fabapp2 commented May 9, 2023

Discussed in #785

Originally posted by fabapp2 May 9, 2023

Scoped Spring Beans

Some objects must exist only once per application, these are a perfect fit for singleton-scoped beans.
But, some other beans have a lifetime shorter than the application itself.
Additionally, these should exist once per thread that executes (theoretically, because static instances currently prevent parallel threads).

ExecutionContext

OpenRewrite's ExecutionContext is such a class.
The ExecutionContext is populated with data available on every new scan, e.g. Maven configuration information.
Additionally, it contains data with a potentially shorter lifespan (of a recipe execution), e.g. error information or messages.

Moving the creation and destruction (or clean up) of the ExecutionContext to Spring would simplify usage and code.
Clients could just inject the current instance using Spring and the ExecutionContext is not required to be passed down the object tree.

By providing a dedicated scope like recipe-scope it would be possible to inject the "right" instance (scoped to current thread and recipe execution) to all objects that share the same or narrower lifespan (Recipe, Action(s), Conditions, ...)

public MyAction {
   // The context from current 'recipe-scope' will be injected
   @Autowired
   private ExecutionContext ctx;
}

OpenRewrite populates data to the ExecutionContext as early as during the scan of an application.

From SBM's perspective, the ExecutionContext contains data with different scopes: scan and recipe-execution.

This means either:

  • The ExecutionContext is created on each recipe execution and the data normally set during scan (in OR) is kept and passed to the ExecutionContext when the first recipe gets executed. This could be done by keeping this data in a bean scoped to scan which is then used to create ExecutionContexts when a recipe starts.
  • The ExecutionContext has itself a scope of scan and the bean is recreated on each scan. The data with a shorter lifespan needs to be removed after each recipe execution

RewriteMavenParser

The RewriteMavenParser reads the .mvn/maven.config from project root. This makes this class a scan-scoped bean.
It has to be recreated on each new scan of a project. It also requires access to the ExecutionContext.


What needs to be done

  • Introduce custom bean scope recipe-scope and verify in test
@fabapp2 fabapp2 linked a pull request May 26, 2023 that will close this issue
@fabapp2 fabapp2 self-assigned this Aug 30, 2023
@fabapp2 fabapp2 added type: enhancement New feature or request in: sbm-support-rewrite Issue is related to the sbm-support-rewrite compionent revamp and removed in: sbm-support-rewrite Issue is related to the sbm-support-rewrite compionent revamp labels Aug 30, 2023
@fabapp2 fabapp2 closed this as completed Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant