Skip to content
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

Declarative Preconditions - or association #4003

Open
nmck257 opened this issue Feb 14, 2024 · 0 comments
Open

Declarative Preconditions - or association #4003

nmck257 opened this issue Feb 14, 2024 · 0 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@nmck257
Copy link
Collaborator

nmck257 commented Feb 14, 2024

What problem are you trying to solve?

Declarative preconditions currently associate via AND if you declare multiple on the same recipe.
If you want to achieve an OR relationship, you can do it, but through a much more verbose "diamond" pattern.

Sample:

---
type: specs.openrewrite.org/v1beta/recipe
name: org.sample.DoSomething
displayName: Do Something
recipeList:
  - org.sample.DoSomething.condition.1
  - org.sample.DoSomething.condition.2
  - org.sample.DoSomething.condition.3

---
type: specs.openrewrite.org/v1beta/recipe
name: org.sample.DoSomething.condition.1
displayName: Do Something (condition 1)
preconditions:
  - org.openrewrite.FindSourceFiles:
      filePattern: "**/my.json"
recipeList:
  - org.sample.DoSomething.for.real

---
type: specs.openrewrite.org/v1beta/recipe
name: org.sample.DoSomething.condition.2
displayName: Do Something (condition 2)
preconditions:
  - org.openrewrite.FindSourceFiles:
      filePattern: "**/your.json"
recipeList:
  - org.sample.DoSomething.for.real  

---
type: specs.openrewrite.org/v1beta/recipe
name: org.sample.DoSomething.condition.3
displayName: Do Something (condition 3)
preconditions:
  - org.openrewrite.FindSourceFiles:
      filePattern: "**/our.json"
recipeList:
  - org.sample.DoSomething.for.real

---
type: specs.openrewrite.org/v1beta/recipe
name: org.sample.DoSomething.for.real
displayName: Do Something (for real)
recipeList:
  - org.openrewrite.json.ChangeKey:
      qwe: qwe

(if you imagine graphing how those 5 recipes relate to each other, it kinda looks like a diamond)

Describe the solution you'd like

---
type: specs.openrewrite.org/v1beta/recipe
name: org.sample.DoSomething
displayName: Do Something
preconditionAssociation: OR
preconditions:
  - org.openrewrite.FindSourceFiles:
      filePattern: "**/my.json"
  - org.openrewrite.FindSourceFiles:
      filePattern: "**/your.json"
  - org.openrewrite.FindSourceFiles:
      filePattern: "**/our.json"
recipeList:
  - org.openrewrite.json.ChangeKey:
      qwe: qwe

Have you considered any alternatives or workarounds?

Support for passing nested recipes as recipe arguments in declarative recipes? :)
This could allow something like:

---
type: specs.openrewrite.org/v1beta/recipe
name: org.sample.DoSomething
displayName: Do Something
preconditionAssociation: OR
preconditions:
  - org.openrewrite.Preconditions.Or:
      recipeList:
        - org.openrewrite.FindSourceFiles:
            filePattern: "**/my.json"
        - org.openrewrite.FindSourceFiles:
            filePattern: "**/your.json"
        - org.openrewrite.FindSourceFiles:
            filePattern: "**/our.json"
recipeList:
  - org.openrewrite.json.ChangeKey:
      qwe: qwe

Additional context

cc @sambsnyd

Are you interested in contributing this feature to OpenRewrite?

Assuming we can bless a design, yeah, I suspect the code won't be too treacherous

@nmck257 nmck257 added the enhancement New feature or request label Feb 14, 2024
@timtebeek timtebeek added the question Further information is requested label Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
Status: No status
Development

No branches or pull requests

2 participants