openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
2.19k stars 329 forks source link

Yaml recipes do not working in linux if there is a target directory in base folder #1293

Closed ruben-garciapariente closed 2 years ago

ruben-garciapariente commented 2 years ago

Hello,

The incident I am going to tell you about is really funny. To prove this case I have a very simple project https://github.com/ruben-garciapariente/test-openwrite/tree/yaml-files-unix In the project there is only one pom.xml file and one application.xml file.

application.yml

noncore:
  key1: value01

pom.xml

....
                        <plugin>
                                <groupId>org.openrewrite.maven</groupId>
                                <artifactId>rewrite-maven-plugin</artifactId>
                                <version>4.16.0</version>
                                <configuration>
                                        <activeRecipes>
                                                <recipe>org.openrewrite.yaml.CoalesceProperties</recipe>
                                        </activeRecipes>
                                </configuration>
                        </plugin>
....

If I run the command mvn rewrite:dryRun on a linux using as a base folder "/test" everything works correctly, the recipe applies

root@bcc33cccab75:/test# mvn rewrite:dryRun
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< com.test.project:test-openrewrite >------------------
[INFO] Building Test 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
INFO]
[INFO] >>> rewrite-maven-plugin:4.16.0:dryRun (default-cli) > process-test-classes @ test-openrewrite >>>
[INFO]
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ test-openrewrite ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /test/src/main/resources
[INFO] skip non existing resourceDirectory /test/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test-openrewrite ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ test-openrewrite ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /test/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ test-openrewrite ---
[INFO] No sources to compile
[INFO]
[INFO] <<< rewrite-maven-plugin:4.16.0:dryRun (default-cli) < process-test-classes @ test-openrewrite <<<
[INFO]
[INFO]
[INFO] --- rewrite-maven-plugin:4.16.0:dryRun (default-cli) @ test-openrewrite ---
[INFO] Using active recipe(s) [org.openrewrite.yaml.CoalesceProperties]
[INFO] Using active styles(s) []
[INFO] Validating active recipes...
[INFO] Parsing Java main files...
[WARNING] Failed to determine version for org.springframework.boot:spring-boot-starter-actuator. Initial value was null. Including POM is at RawMaven{from=file:///test/pom.xml / pom=RawPom(groupId=com.test.project, artifactId=test-openrewrite, version=1.0.0-SNAPSHOT, snapshotVersion=null)}
[WARNING] Failed to determine version for org.springframework.boot:spring-boot-starter-web. Initial value was null. Including POM is at RawMaven{from=file:///test/pom.xml / pom=RawPom(groupId=com.test.project, artifactId=test-openrewrite, version=1.0.0-SNAPSHOT, snapshotVersion=null)}
[WARNING] Failed to determine version for org.springframework.boot:spring-boot-starter-test. Initial value was null. Including POM is at RawMaven{from=file:///test/pom.xml / pom=RawPom(groupId=com.test.project, artifactId=test-openrewrite, version=1.0.0-SNAPSHOT, snapshotVersion=null)}
[WARNING] Unable to download org.openrewrite.maven:rewrite-maven-plugin:4.16.0. Including POM is at RawMaven{from=file:///test/pom.xml / pom=RawPom(groupId=com.test.project, artifactId=test-openrewrite, version=1.0.0-SNAPSHOT, snapshotVersion=null)}
[INFO] Parsing Java test files...
[INFO] Running recipe(s)...
[WARNING] These recipes would make changes to bootstrap.yml:
[WARNING]     org.openrewrite.yaml.CoalesceProperties
[WARNING] Patch file available:
[WARNING]     /test/target/site/rewrite/rewrite.patch
[WARNING] Run 'mvn rewrite:run' to apply the recipes.
[INFO[m] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  14.046 s
[INFO] Finished at: 2021-12-23T11:44:33Z
[INFO] ------------------------------------------------------------------------

But if I run it on the /target folder on a linux (I think it is enough that there is a target folder in the path for it to fail), the recipe does not apply.

root@bcc33cccab75:/target# mvn rewrite:dryRun
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< com.test.project:test-openrewrite >------------------
[INFO] Building Test 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> rewrite-maven-plugin:4.16.0:dryRun (default-cli) > process-test-classes @ test-openrewrite >>>
[INFO]
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ test-openrewrite ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /target/src/main/resources
[INFO] skip non existing resourceDirectory /target/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test-openrewrite ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ test-openrewrite ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /target/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ test-openrewrite ---
[INFO] No sources to compile
[INFO]
[INFO] <<< rewrite-maven-plugin:4.16.0:dryRun (default-cli) < process-test-classes @ test-openrewrite <<<
[INFO]
[INFO]
[INFO] --- rewrite-maven-plugin:4.16.0:dryRun (default-cli) @ test-openrewrite ---
[INFO] Using active recipe(s) [org.openrewrite.yaml.CoalesceProperties]
[INFO] Using active styles(s) []
[INFO] Validating active recipes...
[INFO] Parsing Java main files...
[WARNING] Failed to determine version for org.springframework.boot:spring-boot-starter-actuator. Initial value was null. Including POM is at RawMaven{from=file:///target/pom.xml / pom=RawPom(groupId=com.test.project, artifactId=test-openrewrite, version=1.0.0-SNAPSHOT, snapshotVersion=null)}
[WARNING] Failed to determine version for org.springframework.boot:spring-boot-starter-web. Initial value was null. Including POM is at RawMaven{from=file:///target/pom.xml / pom=RawPom(groupId=com.test.project, artifactId=test-openrewrite, version=1.0.0-SNAPSHOT, snapshotVersion=null)}
[WARNING] Failed to determine version for org.springframework.boot:spring-boot-starter-test. Initial value was null. Including POM is at RawMaven{from=file:///target/pom.xml / pom=RawPom(groupId=com.test.project, artifactId=test-openrewrite, version=1.0.0-SNAPSHOT, snapshotVersion=null)}
[WARNING] Unable to download org.openrewrite.maven:rewrite-maven-plugin:4.16.0. Including POM is at RawMaven{from=file:///target/pom.xml / pom=RawPom(groupId=com.test.project, artifactId=test-openrewrite, version=1.0.0-SNAPSHOT, snapshotVersion=null)}
[INFO] Parsing Java test files...
[INFO] Running recipe(s)...
[INFO] Applying recipes would make no changes. No patch file generated.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  20.742 s
[INFO] Finished at: 2021-12-23T15:42:39Z
[INFO] ------------------------------------------------------------------------

I have tested on a windows system on c:\target and it works correctly.

Thanks & regards

sambsnyd commented 2 years ago

Thanks for reporting @ruben-garciapariente we will look into it

sambsnyd commented 2 years ago

@ruben-garciapariente this is fixed in the gradle and maven plugins and will go out in the next release of each of those, likely within the next week or so. gradle plugin fix: https://github.com/openrewrite/rewrite-gradle-plugin/commit/8110f7d875a33a8bd2b9f2b86f7f12273c7eb61b maven plugin fix: https://github.com/openrewrite/rewrite-maven-plugin/commit/b8106e2c92c31cd5d59eac4511327e9ce5be2dea

Thanks for reporting this issue!