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

Allow PluginXmlPatcher to patch multi-line tags #129

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

zhutmost
Copy link

If my plugin.xml have a multi-line tag (i.e., includes '\n') like this:

<idea-plugin>
    ...
    <description>
        determined by build.sbt
        some else
    </description>
    ...

the current PluginXmlPatcher cannot patch it correctly.
The current code is:

    if (str.matches(s"(?s)^.*<$name>.+</$name>.*$$"))
        str.replaceAll(s"<$name>.+</$name>", s"<$name>$value</$name>")
    else {
       log.warn(s"$input doesn't have $name tag defined, not patching")
       ...

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.

@zhutmost
Copy link
Author

zhutmost commented May 12, 2024

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.

@unkarjedy
Copy link
Member

Thanks for the PR!
One final touch — please ensure the change is covered in tests.
See org.jetbrains.sbtidea.xml.PluginXmlPatchingTest

@zhutmost
Copy link
Author

zhutmost commented May 13, 2024

@unkarjedy OK. but there is a small issue that the current master version cannot pass all the tests. The error message is that:

[info] - dumb mode settings are honored *** FAILED ***
[info]   ArrayBuffer("[warn] Failed to check locally installed JBR version(assuming true): /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.jbr.JbrInstallerTest15312656226632746885/211.5538.2/jbr/release", "[info] extracting jbr to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.jbr.JbrInstallerTest14470914910496959726/211.5538.2/jbr-extract9289551102093443505", "[info] installed JBR into /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.jbr.JbrInstallerTest14470914910496959726/211.5538.2/jbr") was not empty (IdeaInstallerTest.scala:27)

Looks that it is unrelated to my PR

@zhutmost
Copy link
Author

zhutmost commented May 13, 2024

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.
But I find another critical bug that running sbt test will not trigger org.jetbrains.sbtidea.xml.PluginXmlPatchingTest. I am a newbie to SBT flow (I am a MIll user >_<) so I don't know whether the command sbt test is correct. (I find your CI workflow scala.yml also uses sbt test?)

Here is my all sbt test log:

~/Workspace/linter/sbt-idea-plugin fix/plugin-xml-patch !1 ·················································································································································································································································   base 12:21:33
❯ sbt test
[info] welcome to sbt 1.9.8 (Homebrew Java 21.0.3)
[info] loading settings for project sbt-idea-plugin-build from plugins.sbt ...
[info] loading project definition from /Users/zhutmost/Workspace/linter/sbt-idea-plugin/project
[info] loading settings for project sbtIdeaPlugin from build.sbt ...
[info] set current project to sbtIdeaPlugin (in build file:/Users/zhutmost/Workspace/linter/sbt-idea-plugin/)
[info] compiling 4 Scala sources to /Users/zhutmost/Workspace/linter/sbt-idea-plugin/packaging/target/scala-2.12/sbt-1.0/test-classes ...
[info] compiling 3 Java sources to /Users/zhutmost/Workspace/linter/sbt-idea-plugin/ideaSupport/target/scala-2.12/sbt-1.0/classes ...
[warn] source value 8 is obsolete and will be removed in a future release
[warn] target value 8 is obsolete and will be removed in a future release
[warn] To suppress warnings about obsolete options, use -Xlint:-options.
[info] Annotation processing is enabled because one or more processors were found
[info]   on the class path. A future release of javac may disable annotation processing
[info]   unless at least one processor is specified by name (-processor), or a search
[info]   path is specified (--processor-path, --processor-module-path), or annotation
[info]   processing is enabled explicitly (-proc:only, -proc:full).
[info]   Use -Xlint:-options to suppress this message.
[info]   Use -proc:none to disable annotation processing.
[info] compiling 1 Scala source to /Users/zhutmost/Workspace/linter/sbt-idea-plugin/ideaSupport/target/scala-2.12/sbt-1.0/test-classes ...
[info] LinearMappingsBuilderTest:
[info] Feature: mappings equality on various builds
[info]   Scenario: revision: scioIdeaPlugin
[info]   Scenario: revision: sbtIdeaPlugin
[info]   Scenario: revision: zio-intellij
[info]   Scenario: revision: scioIdeaPlugin-qualified-names-grouping
[info]   Scenario: revision: zio-intellij-qualified-names-grouping
[info] IdeaInstallerTest:
[info] - dumb mode settings are honored
[info] - IdeaInstaller installs IDEA dist
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.tasks.SearchPluginIdTest2988603466873341226/211.5538.2
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.tasks.SearchPluginIdTest7682973847791223806/211.5538.2
[info] SearchPluginIdTest:
[info] - search plugin: local only
[info] - search plugin: marketplace only
[info] UtilsTest:
[info] Feature: All example strings can be parse using `toPlugin`
[info]   Scenario: Parse org.intellij.scala
[info]   Scenario: Parse org.intellij.scala:2023.3.6
[info]   Scenario: Parse org.intellij.scala:2023.3.6:Eap
[info]   Scenario: Parse org.intellij.scala:2023.3.6:Nightly
[info]   Scenario: Parse org.custom.plugin
[info]   Scenario: Parse org.custom.plugin:2022.1.1
[info]   Scenario: Parse org.custom.plugin:https://org.example/path/to/your/plugin.zip
[info] IdeaVmOptionsTest:
[info] - paths are quoted in xml version
[info] - paths are NOT quoted in SBT version
[info] ProgressInfoTest:
[info] Feature: render progress bar
[info]   Scenario: percent: 0
[info]   Scenario: percent: 1
[info]   Scenario: percent: 4
[info]   Scenario: percent: 5
[info]   Scenario: percent: 6
[info]   Scenario: percent: 9
[info]   Scenario: percent: 10
[info]   Scenario: percent: 11
[info]   Scenario: percent: 14
[info]   Scenario: percent: 15
[info]   Scenario: percent: 16
[info]   Scenario: percent: 19
[info]   Scenario: percent: 20
[info]   Scenario: percent: 21
[info]   Scenario: percent: 89
[info]   Scenario: percent: 90
[info]   Scenario: percent: 91
[info]   Scenario: percent: 94
[info]   Scenario: percent: 95
[info]   Scenario: percent: 96
[info]   Scenario: percent: 99
[info]   Scenario: percent: 100
[info] Feature: health check FileDownloader creation
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.jbr.JbrInstallerTest2859222685012025331/211.5538.2
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.jbr.JbrInstallerTest800654224097168771/211.5538.2
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.jbr.JbrInstallerTest11708508266697252736/211.5538.2
[info] JbrInstallerTest:
[info] - detect jbr is not installed
[info] - detect jbr is installed
[info] - jbr is installed
[info] PluginDescriptorParserTest:
[info] - parses simple plugin
[info] - parses plugin with optional dependencies
[info] - parses plugin with required dependencies
[info] - parses plugin with mixed dependencies
[info] - parses plugin absent until-build
[info] - parses simple plugin with '&' in name
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.LocalPluginRegistryTest4162065802454422825/211.5538.2
[info] Extracting ideaIU dist to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.idea.IdeaInstallerTest15276485692019485855/ideaIU-211.5538.2-TMP
[info] Installed ideaIU(BuildInfo(ideaIU-211.5538.2)) to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.idea.IdeaInstallerTest15276485692019485855/211.5538.2
[info] Plugin ids from plugins.idx: com.intellij.properties, com.jetbrains.codeWithMe, org.jetbrains.plugins.yaml
[warn] Failed to check locally installed JBR version(assuming true): /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.jbr.JbrInstallerTest800654224097168771/211.5538.2/jbr/release
[info] extracting jbr to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.jbr.JbrInstallerTest11708508266697252736/211.5538.2/jbr-extract1288333155212174340
[info] installed JBR into /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.jbr.JbrInstallerTest11708508266697252736/211.5538.2/jbr
[info] Plugin ids from plugins.idx: com.intellij.properties, com.jetbrains.codeWithMe, org.jetbrains.plugins.yaml
[info] Plugin ids from plugins.idx: com.intellij.properties, com.jetbrains.codeWithMe, org.jetbrains.plugins.yaml
[info] Plugin ids from plugins.idx: com.intellij.properties, com.jetbrains.codeWithMe, org.jetbrains.plugins.yaml
[info] Plugin ids from plugins.idx: com.intellij.properties, com.jetbrains.codeWithMe, org.jetbrains.plugins.hocon, org.jetbrains.plugins.yaml
[info] Plugin ids from plugins.idx: com.intellij.properties, com.jetbrains.codeWithMe, org.jetbrains.plugins.hocon, org.jetbrains.plugins.yaml
[warn] Failed to load plugin index from disk: java.io.EOFException
[info] Plugin ids from plugins.idx: com.intellij.properties, com.jetbrains.codeWithMe, org.jetbrains.plugins.yaml
[warn] Failed to add plugin to index: Couldn't find plugin.xml in /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.LocalPluginRegistryTest4162065802454422825/211.5538.2/plugins/.DS_Store
[warn] Failed to add plugin to index: Plugin root /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.LocalPluginRegistryTest4162065802454422825/211.5538.2/plugins/NON-PLUGIN has no lib directory
[info] Plugin ids from plugins.idx: com.intellij.properties, com.jetbrains.codeWithMe, org.jetbrains.plugins.yaml
[info] LocalPluginRegistryTest:
[info] - LocalPluginRegistry builds bundled plugin index
[info] - LocalPluginRegistry extracts plugin descriptor from
[info] - LocalPluginRegistry extracts and merges plugin descriptor from from plugin.xml and pluginBase.xml
[info] - LocalPluginRegistry detects plugin roots
[info] - LocalPluginRegistry fails when no descriptor was found
[info] - LocalPluginRegistry reports error when plugin is not in the index
[info] - Plugin descriptor not extracted from invalid plugins
[info] - LocalPluginRegistry saves and restores plugin index
[info] - LocalPluginRegistry should handle corrupt index
[info] - irrelevant files and folders are ignored when building index
[warn] [IntellijRepositories] Using non-default IntelliJ repository URL: https://127.0.0.1:/non-existing-path
[warn] [IntellijVersionUtils] Cannot detect artifact location for version 211.5538.2, fallback to: (211.5538-EAP-CANDIDATE-SNAPSHOT,intellij-repository-eap: https://127.0.0.1:/non-existing-path/snapshots)
[warn] [IJRepoIdeaResolver] Artifact location for build number 211.5538.2: version: 211.5538-EAP-CANDIDATE-SNAPSHOT, url: https://127.0.0.1:/non-existing-path/snapshots/com/jetbrains/intellij/idea/ideaIU/211.5538-EAP-CANDIDATE-SNAPSHOT/ideaIU-211.5538-EAP-CANDIDATE-SNAPSHOT.zip
[warn] [IntellijVersionUtils] Cannot detect artifact location for version 211.5538.2, fallback to: (211.5538-EAP-CANDIDATE-SNAPSHOT,intellij-repository-eap: https://127.0.0.1:/non-existing-path/snapshots)
[warn] [IJRepoIdeaResolver] Artifact location for build number 211.5538.2: version: 211.5538-EAP-CANDIDATE-SNAPSHOT, url: https://127.0.0.1:/non-existing-path/snapshots/com/jetbrains/intellij/idea/ideaIC/211.5538-EAP-CANDIDATE-SNAPSHOT/ideaIC-211.5538-EAP-CANDIDATE-SNAPSHOT-sources.jar
[info] IJRepoResolverTest:
[info] - IJ repo overriding property
[info] IntellijPluginParserTest:
[info] - Id parser should parse simple id
[info] - plugin with url should parse as Id with optional URL set
[info] - id should parse with with mixed segments
[info] - parser should not parse invalid strings
[info] PluginSigningTest:
[info] - sign with cert and key without password
[info] - sign with cert and key WITH password
[info] - sign should fail with a wrong password
[info] - sign task should fail if signing is disabled in options
[info] IntelliJVersionDetectorTest:
[info] - readVersionFromBuildTxt
[info] - readVersionFromIntellijDirectory
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.jbr.JbrResolverTest10713695950352781029/211.5538.2
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.jbr.JbrResolverTest2932184596870208967/211.5538.2
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.jbr.JbrResolverTest15971275839059886247/211.5538.2
[info] JbrResolverTest:
[info] - extract jbr version from dependencies.txt
[info] - jbr version major/minor split
[info] - jbr resolves to correct url
[info] - NoJbr jbrInfo resolves to 0 artifacts
[info] JbIdeaRepoArtifactResolverTest:
[info] - latest eap is resolved
[info] - latest 192 release is resolved
[info] - latest 191 release is resolved
[info] CommunityIdeaUpdaterTest:
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.PluginClassPathTest15542903800195863891/211.5538.2
Extracting plugin 'org.intellij.scala to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.PluginClassPathTest15542903800195863891/211.5538.2/ideaIU-211.5538.2-plugin7367832138076999969
Installed plugin 'org.intellij.scala to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.PluginClassPathTest15542903800195863891/211.5538.2/plugins/Scala
Plugin ids from plugins.idx: com.intellij.properties, com.jetbrains.codeWithMe, org.intellij.scala, org.jetbrains.plugins.yaml
Installed plugin 'org.jetbrains.plugins.hocon to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.PluginClassPathTest15542903800195863891/211.5538.2/plugins/HOCON.jar
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.PluginClassPathTest13050495959832406235/211.5538.2
Failed to add plugin to index: Error during detecting plugin.xml: java.util.zip.ZipException: zip END header not found
Plugin ids from plugins.idx: com.intellij.properties, com.jetbrains.codeWithMe, org.jetbrains.plugins.yaml
[info] PluginClassPathTest:
[info] - plugin classpath contains all necessary jars
[info] - plugin classpath doesn't contain jars other than from 'lib'
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.IntellijPluginInstallerTest10635877714035203052/211.5538.2
Plugin ids from plugins.idx: com.intellij.properties, com.jetbrains.codeWithMe, org.jetbrains.plugins.yaml
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.IntellijPluginInstallerTest1362613191250240249/211.5538.2
Extracting plugin 'org.intellij.scala to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.IntellijPluginInstallerTest1362613191250240249/211.5538.2/ideaIU-211.5538.2-plugin12434278385873806104
Installed plugin 'org.intellij.scala to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.IntellijPluginInstallerTest1362613191250240249/211.5538.2/plugins/Scala
Plugin ids from plugins.idx: com.intellij.properties, com.jetbrains.codeWithMe, org.intellij.scala, org.jetbrains.plugins.yaml
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.IntellijPluginInstallerTest11989197623799818217/211.5538.2
Installed plugin 'org.intellij.scala to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.IntellijPluginInstallerTest11989197623799818217/211.5538.2/plugins/Scala.jar
Plugin ids from plugins.idx: com.intellij.properties, com.jetbrains.codeWithMe, org.intellij.scala, org.jetbrains.plugins.yaml
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.IntellijPluginInstallerTest15038316407172439978/211.5538.2
Installed plugin 'org.intellij.scala to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.IntellijPluginInstallerTest15038316407172439978/211.5538.2/plugins/Scala.jar
Plugin ids from plugins.idx: com.intellij.properties, com.jetbrains.codeWithMe, org.intellij.scala, org.jetbrains.plugins.yaml
[warn] Plugin org.intellij.scala is incompatible with current ideaVersion(211.5538.2): PluginDescriptor(org.intellij.scala,JetBrains,Scala,2019.2.423,193.123,193.4,List())
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.IntellijPluginInstallerTest2286507051384835523/211.5538.2
Installed plugin 'org.intellij.scala to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.IntellijPluginInstallerTest2286507051384835523/211.5538.2/plugins/Scala.jar
Plugin ids from plugins.idx: com.intellij.properties, com.jetbrains.codeWithMe, org.intellij.scala, org.jetbrains.plugins.yaml
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.IntellijPluginInstallerTest4155313226859739132/211.5538.2
Installed plugin 'org.intellij.scala to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.IntellijPluginInstallerTest4155313226859739132/211.5538.2/plugins/Scala.jar
Plugin ids from plugins.idx: com.intellij.properties, com.jetbrains.codeWithMe, org.intellij.scala, org.jetbrains.plugins.yaml
[warn] Newer version of plugin org.intellij.scala is available: 2019.2.1 -> 2021.1.22
[info] IntellijPluginInstallerTest:
[info] - Plugin installer reports non-installed plugins
[info] - Plugin installer installs zip artifact
[info] - Plugin installer installs jar artifact
[info] - Plugin installer checks IDEA compatibility
[info] - Plugin installer checks IDEA compatibility using wildcards
[info] - Plugin installer checks for newer plugin version
[info] IdeaVersionCompareTest:
[info] - versions greater
[info] - versions equal
[info] - version wildcards greater
[info] - version case class
[info] PluginRepoUtilsTest:
[info] Feature: getPluginDownloadURL
[info]   Scenario: id
[info]   Scenario: id with chanel
[info]   Scenario: id with version
[info]   Scenario: id with version and channel
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.IntellijPluginResolverTest9935407997854380259/211.5538.2
[error] Failed to resolve PluginDependency(org.myFake.plugin): java.lang.RuntimeException: TestPluginRepoApi error for getRemotePluginXmlDescriptor
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.IntellijPluginResolverTest289124885464962665/211.5538.2
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.IntellijPluginResolverTest6839641142510967962/211.5538.2
[warn] Circular plugin dependency detected: PluginDependency(org.E) already processed
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.IntellijPluginResolverTest12898681203034679035/211.5538.2
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.IntellijPluginResolverTest439845872442589985/211.5538.2
installed IDEA mock to /var/folders/k3/zhkh4sc901368bx7wwmnzrd40000gn/T/org.jetbrains.sbtidea.download.plugin.IntellijPluginResolverTest14911743003473798163/211.5538.2
[info] IntellijPluginResolverTest:
[info] - plugin resolver doesn't resolve fake plugin
[info] - transitive plugin dependencies are resolved
[info] - cyclic dependencies are detected
[info] - plugin exclude rules work
[info] - disable transitive resolution
[info] - disable optional plugins
[info] Run completed in 3 seconds, 864 milliseconds.
[info] Total number of tests run: 5
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 5, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[info] Run completed in 3 seconds, 884 milliseconds.
[info] Total number of tests run: 94
[info] Suites: completed 20, aborted 0
[info] Tests: succeeded 94, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 14 s, completed May 13, 2024, 12:21:57 PM

@unkarjedy
Copy link
Member

But I find another critical bug that running sbt test will not trigger org.jetbrains.sbtidea.xml.PluginXmlPatchingTest. I am a newbie to SBT flow (I am a MIll user >_<) so I don't know whether the command sbt test is correct. (I find your CI workflow scala.yml also uses sbt test?)

Thanks for noticing this!
Indeed, it seems like the test is ignored in SBT because it's made package private (private class PluginXmlPatchingTest)
No idea why it was done so.
Removing private helps

@zhutmost
Copy link
Author

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
Copy link
Member

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") {
Copy link
Member

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

Copy link
Member

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

Copy link
Member

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

Copy link
Author

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.

@zhutmost
Copy link
Author

zhutmost commented May 17, 2024

@unkarjedy I have fixed your two issues. please review.

I check all the comments and , pairs, and only replace non-comment ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants