-
Notifications
You must be signed in to change notification settings - Fork 28
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
Allow PluginXmlPatcher to patch multi-line tags #129
base: master
Are you sure you want to change the base?
Conversation
And I also check whether multiple tags with a same name are defined. If so, a warning will be printed and only the first one will be replaced. That is because sometime I write comments in plugin.xml, the original version will patch all of them like this: <description>
determined by build.sbt
</description>
<!-- <description>
This is commented out.
</description> -->
... will be changed to: <description>
replacer
</description> -->
... That is not what I want. |
Thanks for the PR! |
@unkarjedy OK. but there is a small issue that the current
Looks that it is unrelated to my PR |
Forgive my last comment. (I dont know what happened. After multi-runs, it looks good now.) I have added pluginXmlPatching tests for multiple tags and duplicated tags. Here is my all sbt test log:
|
Thanks for noticing this! |
OK, done. Looks good. You can consider merging now. |
val newContent = Files.readAllLines(result).asScala | ||
|
||
val newContentPattern = s"(?s).*<description>${options.pluginDescription}</description>.*$$".r | ||
newContent.mkString("\n") should fullyMatch regex newContentPattern |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using regular expressions in tests over-complicates it. It will be harder to read failed test output and maintain the test.
Let's use a simple equality test (shouldEqual/shouldBe?)
newContent.mkString("\n") should fullyMatch regex newContentPattern | ||
} | ||
|
||
test("duplicate tags are only patched the first one") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the issues you tried to fix in org.jetbrains.sbtidea.xml.PluginXmlPatcher#tag
is to ignore comments.
(due to the description in PR comments)
However, it doesn't do it.
If you go to plugin-duplicatedtags.xml
and move the commented description to the top, the patcher will edit the commented description.
What's more, this test would pass and not detect the bug.
But if it used simple shouldEqual/shouldBe
it would fail and we would notice the issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After fixing this, I would add two comments—before and after the main description tag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To address it, we could first find all the ranges of the comments using something like
import scala.util.matching.Regex
val CommentPattern = new Regex("(?s)<!--.*?-->")
def findCommentRanges(xml: String): Seq[Range] =
CommentPattern.findAllMatchIn(xml).map(m => m.start until m.end).toList
and then ignore those pattern matches which are inside those ranges
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I will fix them. Just a few days (~1 week), because I've got something else going on.
@unkarjedy I have fixed your two issues. please review. I check all the comments and , pairs, and only replace non-comment ones. |
If my plugin.xml have a multi-line tag (i.e., includes '\n') like this:
the current PluginXmlPatcher cannot patch it correctly.
The current code is:
Detailed reason analysis:
The regex in the if-condition with "(?s)" enables DOTALL mode, so it can match the string with '\n'. And, the regex in the
replace
statement does not have a "(?s)", so it cannot match multiline tags, and nothing will be replaced.