OpenRewrite: Not visiting files from src/main/resources directory

214 Views Asked by At

I am using OpenRewrite recipe org.openrewrite.DeleteSourceFiles to delete some files. But it is not detecting or deleting files from src/main/resources directory or src/test/resources. I have basic gradle java project which have src/main/java src/main/resources src/test/java & src/test/resources directories. I am using gradle plugin of openrewrite to run recipe.

I tried running this recipe in dry run mode with "**" as filePattern just to check what all files it detects. Seems like it does not even detect files from src/main/resources & src/test/resources. It detects files from src/main/java, src/test/java & also some other random directories I have at the root but not resources under main or test. Due to this it doesn't delete it. Not sure what's the issue specifically with resources directories?

2

There are 2 best solutions below

0
KidDaedalus On BEST ANSWER

The fix for this issue is now available in rewrite-gradle-plugin 6.8.3 and rewrite-maven-plugin 5.23.0.

Your debugging narrowing the problem to TreeWalk helped to fix this! I've made this commit to rewrite-polyglot so that it produces the same list of files-to-parse on Windows as it does on unix-style paths.

2
Jonathan Schneider On

OpenRewrite does in fact visit files in src/main/resources and indeed every other file whether or not it is in a source directory or not (provided that the file is under the configurable maximum threshold of 10MB).

DeleteSourceFiles works as intended as far as I can tell. I will provide the exact setup I used below to test in the hopes that this helps you as well.

Cloning a repository and adding the Rewrite plugin

I used Steps 1 and 2 here to add the Rewrite Gradle plugin to a sample project.

Create a rewrite.yml

Create a new file rewrite.yml at the root of the repository:

---
type: specs.openrewrite.org/v1beta/recipe
name: io.moderne.DeleteApplicationProperties
recipeList:
  - org.openrewrite.DeleteSourceFiles:
      filePattern: '**/application*.properties'

Activate the recipe

In your build.gradle, activate the recipe:

rewrite {
  activeRecipe(
    'io.moderne.DeleteApplicationProperties'
  )
}

Run

./gradlew rewriteDryRun

enter image description here