Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Introduce bean scopes for scan and recipe#785

fabapp2 started this conversation inIdeas
Discussion options

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'sExecutionContext is such a class.
TheExecutionContext 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 theExecutionContext to Spring would simplify usage and code.
Clients could just inject the current instance using Spring and theExecutionContext is not required to be passed down the object tree.

By providing a dedicated scope likerecipe-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, ...)

publicMyAction {// The context from current 'recipe-scope' will be injected@AutowiredprivateExecutionContextctx;}

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:

  1. 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 toscan which is then used to createExecutionContexts when a recipe starts.
  2. The ExecutionContext has itself a scope ofscan and the bean is recreated on each scan. The data with a shorter lifespan needs to be removed after each recipe execution

RewriteMavenParser

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

You must be logged in to vote

Replies: 2 comments

Comment options

TheExecutionContext is also required inApplicableRecipeListCommand. This prevents theExecutionContext lifetime to span a recipe run only.

  • Messages added while evaluating recipe conditions would be lost when the recipe runs and a new ExecutionContext is created
You must be logged in to vote
0 replies
Comment options

Another attempt...

  • ExecutionContext has scan scope instead.
    • ExistingExecutionContext is removed from scope.
    • A new ExecutionContext gets created on each scan.
  • During condition evaluation new messages can be added to the ExecutionContext.
  • Recipes can add messages to the ExecutionContext. These messages must be removed after every recipe run
  • The messages that were added during parsing/scan must be kept until a new condition evaluation or finishing a recipe run
You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Ideas
Labels
None yet
1 participant
@fabapp2

[8]ページ先頭

©2009-2025 Movatter.jp