openrewrite / rewrite-gradle-plugin

OpenRewrite's Gradle plugin.
Apache License 2.0
60 stars 37 forks source link

Gradle parser does not parse subproject resources #252

Closed travisboettcher closed 8 months ago

travisboettcher commented 8 months ago

When using the org.openrewrite.properties.AddProperty recipe, I noticed that the file I was trying to target (hibernate.properties) was not being updated. In trying to get it to work, I've seen the recipe work on other properties files, so I don't believe it's the recipe.

I'm wondering it the culprit is here when it is parsing the resources of a project:

for (File resourcesDir : sourceSet.getResources().getSourceDirectories()) {
    if (resourcesDir.exists()) {
        OmniParser omniParser = omniParser(alreadyParsed);
        List<Path> accepted = omniParser.acceptedPaths(resourcesDir.toPath());
        sourceSetSourceFiles = Stream.concat(
                sourceSetSourceFiles,
                omniParser.parse(accepted, resourcesDir.toPath(), new InMemoryExecutionContext())
        );
        sourceSetSize += accepted.size();
    }
}

In particular, passing a new InMemoryExecutionContext into the omniparser rather than the existing ctx.

What version of OpenRewrite are you using?

I am using the OpenRewrite Gradle plugin v6.6.2 (I also tried 6.6.3 just in case)

How are you running OpenRewrite?

I am using the Gradle plugin and it is a multi-module project.

What is the smallest, simplest way to reproduce the problem?

Reproduced here: OpenRewrite-bug.zip

What did you expect to see?

The file example/src/main/resources/hibernate.properties should be updated to include a new property, hibernate.type.preferred_uuid_jdbc_type=CHAR

What did you see instead?

The file is not updated, although if I move it to the top-level directory, it does get updated. If I remove the precondition, the gradle/gradle-wrapper.properties file gets updated - so I don't believe it's the recipe.

Are you interested in contributing a fix to OpenRewrite?

Possibly!