Closed maxime-michel closed 6 months ago
It looks like your file isn't parsed as plain text, but instead as a Quark; https://docs.openrewrite.org/concepts-explanations/quarks
You might have better luck when you specifically mark that file as a file type that should be parsed as plain text: https://openrewrite.github.io/rewrite-maven-plugin/run-mojo.html#plainTextMasks
Hope that helps and let us know if this issue can be closed.
Thanks for your help and sorry I didn't find this configuration option on my own. Unfortunately in the same test project as in my initial post, running mvn org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.activeRecipes=info.magnolia.rewrite.AddToList -Drewrite.plainTextMasks="**/TEST_LIST"
is still not enough. The exception with the Quark is now gone, but the desired addition to the file is not made. The logs do not say much other than the configuration is properly applied, and there is no exclusion that may get in the way:
[DEBUG] (f) exclusions = []
[DEBUG] (f) plainTextMasks = [**/TEST_LIST]
Hmm; it seems our docs don't format a particular option well that I don't yet see you using: https://github.com/openrewrite/rewrite/blob/22eef9abff1494d650d54425682db9dc7994fa60/rewrite-core/src/main/java/org/openrewrite/text/AppendToTextFile.java#L55-L66
While perhaps surprising, the default extistingFileStrategy
is Leave
, which does not change your file.
https://github.com/openrewrite/rewrite/blob/22eef9abff1494d650d54425682db9dc7994fa60/rewrite-core/src/main/java/org/openrewrite/text/AppendToTextFile.java#L138-L147
Perhaps it helps to set an explicit strategy of Continue
if your file already existings when the first recipe runs.
Awesome, thank you, so if I got it right we could consider the following improvements for this to be a better experience for the next user:
plainTextMasks
on the pageI know I'm looking at it from a very specific angle, and probably missing some context on why some things are the way they are, so please let me know your thoughts on the above? I may then contribute.
Thanks for your suggestions ! Definitely agree we need to fix the formatting for that option table in the presence of newlines. That'll be in our RecipeMarkdownGenerator. /cc @mike-solomon
Changing the default might surprise existing users, so I'd think that's best avoided (unfortunately).
A reference to plainTextMasks could be helpful. That could probably go into the description as a link to the Maven and Gradle plugin configuration pages in the docs. https://github.com/openrewrite/rewrite/blob/22eef9abff1494d650d54425682db9dc7994fa60/rewrite-core/src/main/java/org/openrewrite/text/AppendToTextFile.java#L74-L75
Any help with those updates much appreciated; Mike can help review as I'm off for the next couple of weeks.
Here'd be my suggestion. Will take a look at the Markdown generator later, though I guess the first step there would be an exact description of the issue as well as an issue in the repo itself.
Much appreciated! Mike can likely help with the reviews in my absence. :)
Thanks a lot for the fix to the docs! I think we can close this issue now, but let me know if I missed something.
What version of OpenRewrite are you using?
I am using
How are you running OpenRewrite?
I am using the Maven plugin, and my project is a single module dummy project:
TEST_LIST
:rewrite.yml
:What is the smallest, simplest way to reproduce the problem?
Simply run
mvn org.openrewrite.maven:rewrite-maven-plugin:LATEST:run -Drewrite.activeRecipes=info.magnolia.rewrite.AddToList
What did you expect to see?
I would have expected to see
TEST3
appended to the existing plain text file. Instead, the logs output:What did you see instead?
TEST_LIST_NEW
was created with the expected content, showing that everything is correctly wired, but the format used by my already-existing text file is not parsed. The documentation however doesn't hint at anything peculiar, only brings up 'plaintext', which my file is.