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

Recipe org.openrewrite.text.FindAndReplace ignores files that have "build" or "out" directories in its path #850

Closed
ErhardSiegl opened this issue Aug 29, 2024 · 1 comment · Fixed by #868
Labels
bug Something isn't working

Comments

@ErhardSiegl
Copy link

ErhardSiegl commented Aug 29, 2024

What version of OpenRewrite are you using?

I am using

  • OpenRewrite 8.33.7
  • Maven plugin 5.39.1

How are you running OpenRewrite?

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

Run the following script:

#!/bin/sh

# set -x

for f in src src/build src/build/dir src/out src/dir; do
    mkdir $f  # ignore errors
    echo hello > $f/hello.txt
done

cat <<'EOF' > pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>at.gepardec.openrewrite</groupId>
  <artifactId>findreplace</artifactId>
  <version>1.0.0</version>
  <packaging>pom</packaging>

  <build>
    <plugins>
      <plugin>
        <groupId>org.openrewrite.maven</groupId>
        <artifactId>rewrite-maven-plugin</artifactId>
        <version>5.39.1</version>
        <configuration>
          <activeRecipes>
            <recipe>at.gepardec.hello</recipe>
          </activeRecipes>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
EOF

cat <<'EOF' > rewrite.yml
---
type: specs.openrewrite.org/v1beta/recipe
name: at.gepardec.hello
displayName: Test FindAndReplace
recipeList:
  - org.openrewrite.text.FindAndReplace:
      find: hello
      replace: welcome
      filePattern: '**/hello.txt'
EOF

mvn org.openrewrite.maven:rewrite-maven-plugin:dryRun

What did you see instead?

I expect that changes would be made in the 5 directories src, src/build, src/build/dir, src/out, src/dir. Instead you see in the output that only files in src and src/dir are changed, files that don't have out or build in their pathname.

[INFO] Running recipe(s)...
[WARNING] These recipes would make changes to src/dir/hello.txt:
[WARNING]     org.openrewrite.text.FindAndReplace: {find=hello, replace=welcome, filePattern=**/hello.txt}
[WARNING] These recipes would make changes to src/hello.txt:
[WARNING]     org.openrewrite.text.FindAndReplace: {find=hello, replace=welcome, filePattern=**/hello.txt}
[WARNING] Patch file available:
[WARNING]     /Users/esiegl/Documents/Develop/OpenRewrite/Tmp2/target/rewrite/rewrite.patch
[WARNING] Estimate time saved: 10m
[WARNING] Run 'mvn rewrite:run' to apply the recipes.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

Are you interested in contributing a fix to OpenRewrite?

Yes

@ErhardSiegl ErhardSiegl added the bug Something isn't working label Aug 29, 2024
@ErhardSiegl
Copy link
Author

ErhardSiegl commented Aug 29, 2024

In https://rewriteoss.slack.com/archives/C01A843MWG5/p1724938610370409?thread_ts=1724935505.161649&cid=C01A843MWG5 Shannon Pamperl suggests that the problem might be related to

private static final Set<String> DEFAULT_IGNORED_DIRECTORIES = new HashSet<>(Arrays.asList("build", "target", "out", ".sonar", ".gradle", ".idea", ".project", "node_modules", ".git", ".metadata", ".DS_Store"));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant