From 9b73ef4d95047c1a5c8f0bdc93ee414d0c1c1d79 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 7 May 2024 07:50:32 +0200 Subject: [PATCH] GTW-8605 use JDOM GitOrigin-RevId: 74148fc93bf8320a3ecb53d878b2f7e6b0064ca0 --- .idea/libraries/decentxml.xml | 18 -- .../intellij.platform.buildScripts.iml | 1 - .../build/CommunityLibraryLicenses.kt | 2 - .../intellij/build/impl/PluginXmlPatcher.kt | 97 +++++----- .../intellij.platform.buildScripts.tests.iml | 2 +- .../intellij/build/PluginXmlPatcherTest.kt | 180 +++++++++--------- 6 files changed, 131 insertions(+), 169 deletions(-) delete mode 100644 .idea/libraries/decentxml.xml diff --git a/.idea/libraries/decentxml.xml b/.idea/libraries/decentxml.xml deleted file mode 100644 index c44bf0c6a986..000000000000 --- a/.idea/libraries/decentxml.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - fe671ff552a8d724710e37fdb224b19c9aaf16ed3ce8dc8bbc694788f79edd41 - - - - - - - - - - - - \ No newline at end of file diff --git a/platform/build-scripts/intellij.platform.buildScripts.iml b/platform/build-scripts/intellij.platform.buildScripts.iml index 0ac4d14451e1..9011c0131473 100644 --- a/platform/build-scripts/intellij.platform.buildScripts.iml +++ b/platform/build-scripts/intellij.platform.buildScripts.iml @@ -61,7 +61,6 @@ - diff --git a/platform/build-scripts/src/org/jetbrains/intellij/build/CommunityLibraryLicenses.kt b/platform/build-scripts/src/org/jetbrains/intellij/build/CommunityLibraryLicenses.kt index 242bbe608e6f..d16b840095a1 100644 --- a/platform/build-scripts/src/org/jetbrains/intellij/build/CommunityLibraryLicenses.kt +++ b/platform/build-scripts/src/org/jetbrains/intellij/build/CommunityLibraryLicenses.kt @@ -313,8 +313,6 @@ object CommunityLibraryLicenses { url = "https://github.com/hypfvieh/dbus-java", licenseUrl = "https://github.com/hypfvieh/dbus-java/blob/dbus-java-3.0/LICENSE") .suppliedByPersons("David M. "), - LibraryLicense(name = "DecentXML", libraryName = "decentxml", - url = "https://code.google.com/p/decentxml").newBsd(), LibraryLicense(name = "docutils", attachedTo = "intellij.python", version = "0.12", url = "https://docutils.sourceforge.io/").simplifiedBsd(), LibraryLicense(name = "dotenv-kotlin", libraryName = "io.github.cdimascio.dotenv.kotlin", diff --git a/platform/build-scripts/src/org/jetbrains/intellij/build/impl/PluginXmlPatcher.kt b/platform/build-scripts/src/org/jetbrains/intellij/build/impl/PluginXmlPatcher.kt index 7d72162ae0ae..4c84f8b8193e 100644 --- a/platform/build-scripts/src/org/jetbrains/intellij/build/impl/PluginXmlPatcher.kt +++ b/platform/build-scripts/src/org/jetbrains/intellij/build/impl/PluginXmlPatcher.kt @@ -1,8 +1,10 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.intellij.build.impl -import de.pdark.decentxml.* +import com.intellij.openapi.util.JDOMUtil import io.opentelemetry.api.trace.Span +import org.jdom.Element +import org.jdom.Text import org.jetbrains.annotations.TestOnly import org.jetbrains.intellij.build.BuildContext import org.jetbrains.intellij.build.CompatibleBuildRange @@ -34,12 +36,14 @@ fun getCompatiblePlatformVersionRange(compatibleBuildRange: CompatibleBuildRange return Pair(sinceBuild, untilBuild) } -internal fun patchPluginXml(moduleOutputPatcher: ModuleOutputPatcher, - plugin: PluginLayout, - releaseDate: String, - releaseVersion: String, - pluginsToPublish: Set, - context: BuildContext) { +internal fun patchPluginXml( + moduleOutputPatcher: ModuleOutputPatcher, + plugin: PluginLayout, + releaseDate: String, + releaseVersion: String, + pluginsToPublish: Set, + context: BuildContext, +) { val moduleOutput = context.getModuleOutputDir(context.findRequiredModule(plugin.mainModule)) val pluginXmlFile = moduleOutput.resolve("META-INF/plugin.xml") if (Files.notExists(pluginXmlFile)) { @@ -59,17 +63,18 @@ internal fun patchPluginXml(moduleOutputPatcher: ModuleOutputPatcher, val sinceUntil = getCompatiblePlatformVersionRange(compatibleBuildRange, context.buildNumber) @Suppress("TestOnlyProblems") val content = try { plugin.pluginXmlPatcher( - // using input stream allows us to support BOM - doPatchPluginXml(document = Files.newInputStream(pluginXmlFile).use { XMLParser().parse(XMLIOSource(it)) }, - pluginModuleName = plugin.mainModule, - pluginVersion = pluginVersion, - releaseDate = releaseDate, - releaseVersion = releaseVersion, - compatibleSinceUntil = sinceUntil, - toPublish = pluginsToPublish.contains(plugin), - retainProductDescriptorForBundledPlugin = plugin.retainProductDescriptorForBundledPlugin, - isEap = context.applicationInfo.isEAP, - productName = context.applicationInfo.fullProductName), + doPatchPluginXml( + rootElement = JDOMUtil.load(pluginXmlFile), + pluginModuleName = plugin.mainModule, + pluginVersion = pluginVersion, + releaseDate = releaseDate, + releaseVersion = releaseVersion, + compatibleSinceUntil = sinceUntil, + toPublish = pluginsToPublish.contains(plugin), + retainProductDescriptorForBundledPlugin = plugin.retainProductDescriptorForBundledPlugin, + isEap = context.applicationInfo.isEAP, + productName = context.applicationInfo.fullProductName, + ), context, ) } @@ -80,17 +85,18 @@ internal fun patchPluginXml(moduleOutputPatcher: ModuleOutputPatcher, } @TestOnly -fun doPatchPluginXml(document: Document, - pluginModuleName: String, - pluginVersion: String?, - releaseDate: String, - releaseVersion: String, - compatibleSinceUntil: Pair, - toPublish: Boolean, - retainProductDescriptorForBundledPlugin: Boolean, - isEap: Boolean, - productName: String): String { - val rootElement = document.rootElement +fun doPatchPluginXml( + rootElement: Element, + pluginModuleName: String, + pluginVersion: String?, + releaseDate: String, + releaseVersion: String, + compatibleSinceUntil: Pair, + toPublish: Boolean, + retainProductDescriptorForBundledPlugin: Boolean, + isEap: Boolean, + productName: String, +): String { val ideaVersionElement = getOrCreateTopElement(rootElement, "idea-version", listOf("id", "name")) ideaVersionElement.setAttribute("since-build", compatibleSinceUntil.first) ideaVersionElement.setAttribute("until-build", compatibleSinceUntil.second) @@ -100,8 +106,7 @@ fun doPatchPluginXml(document: Document, if (productDescriptor != null) { if (!toPublish && !retainProductDescriptorForBundledPlugin) { Span.current().addEvent("skip $pluginModuleName ") - removeTextBeforeElement(productDescriptor) - productDescriptor.remove() + productDescriptor.detach() } else { Span.current().addEvent("patch $pluginModuleName ") @@ -122,7 +127,7 @@ fun doPatchPluginXml(document: Document, val replaced = replaceInElementText(description, "IntelliJ-based IDEs", "WebStorm") check(replaced) { "Could not find \'IntelliJ-based IDEs\' in plugin description of $pluginModuleName" } } - return document.toXML() + return JDOMUtil.write(rootElement) } fun getOrCreateTopElement(rootElement: Element, tagName: String, anchors: List): Element { @@ -133,39 +138,23 @@ fun getOrCreateTopElement(rootElement: Element, tagName: String, anchors: List= 0) { - "anchor < 0 when getting child index of \'${anchor.name}\' in root element of ${rootElement.toXML()}" + "anchor < 0 when getting child index of \'${anchor.name}\' in root element of ${JDOMUtil.write(rootElement)}" } - var indent = rootElement.getNode(anchorIndex - 1) - indent = if (indent is Text) indent.copy() else Text("") - rootElement.addNode(anchorIndex + 1, newElement) - rootElement.addNode(anchorIndex + 1, indent) + rootElement.addContent(anchorIndex + 1, newElement) } return newElement } -private fun removeTextBeforeElement(element: Element) { - val parentElement = element.parentElement ?: throw IllegalStateException("Could not find parent of \'${element.toXML()}\'") - val elementIndex = parentElement.nodeIndexOf(element) - check(elementIndex >= 0) { "Could not find element index \'${element.toXML()}\' in parent \'${parentElement.toXML()}\'" } - if (elementIndex > 0) { - val text = parentElement.getNode(elementIndex - 1) - if (text is Text) { - parentElement.removeNode(elementIndex - 1) - } - } -} - @Suppress("SameParameterValue") private fun replaceInElementText(element: Element, oldText: String, newText: String): Boolean { var replaced = false - for (node in element.nodes) { + for (node in element.content) { if (node is Text) { val textBefore = node.text val text = textBefore.replace(oldText, newText) diff --git a/platform/build-scripts/tests/intellij.platform.buildScripts.tests.iml b/platform/build-scripts/tests/intellij.platform.buildScripts.tests.iml index 7453fb355fa5..95b320112a6f 100644 --- a/platform/build-scripts/tests/intellij.platform.buildScripts.tests.iml +++ b/platform/build-scripts/tests/intellij.platform.buildScripts.tests.iml @@ -19,12 +19,12 @@ - + \ No newline at end of file diff --git a/platform/build-scripts/tests/testSrc/org/jetbrains/intellij/build/PluginXmlPatcherTest.kt b/platform/build-scripts/tests/testSrc/org/jetbrains/intellij/build/PluginXmlPatcherTest.kt index 7d88b31b6132..8238f4ee109f 100644 --- a/platform/build-scripts/tests/testSrc/org/jetbrains/intellij/build/PluginXmlPatcherTest.kt +++ b/platform/build-scripts/tests/testSrc/org/jetbrains/intellij/build/PluginXmlPatcherTest.kt @@ -1,8 +1,9 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.intellij.build -import de.pdark.decentxml.XMLParser +import com.intellij.openapi.util.JDOMUtil import org.assertj.core.api.Assertions.assertThat +import org.intellij.lang.annotations.Language import org.jetbrains.intellij.build.impl.doPatchPluginXml import org.junit.jupiter.api.Test @@ -17,12 +18,12 @@ class PluginXmlPatcherTest { """.trimIndent(), """ - - x-plugin-version - CSS - com.intellij.css - - + + x-plugin-version + CSS + com.intellij.css + + """.trimIndent()) @Test @@ -34,12 +35,12 @@ class PluginXmlPatcherTest { """.trimIndent(), """ - - CSS - com.intellij.css - x-plugin-version - - + + CSS + com.intellij.css + x-plugin-version + + """.trimIndent()) @Test @@ -48,9 +49,10 @@ class PluginXmlPatcherTest { """.trimIndent(), """ - - x-plugin-version - + + x-plugin-version + + """.trimIndent()) @Test @@ -63,12 +65,12 @@ class PluginXmlPatcherTest { """.trimIndent(), """ - - CSS - com.intellij.css - x-plugin-version - - + + CSS + com.intellij.css + x-plugin-version + + """.trimIndent()) } @@ -83,12 +85,12 @@ class PluginXmlPatcherTest { """.trimIndent(), """ - - CSS - com.intellij.css - x-plugin-version - - + + CSS + com.intellij.css + x-plugin-version + + """.trimIndent()) } @@ -105,12 +107,12 @@ class PluginXmlPatcherTest { """.trimIndent(), """ - - CSS - com.intellij.css - x-plugin-version - - + + CSS + com.intellij.css + x-plugin-version + + """.trimIndent(), toPublish = false ) @@ -128,14 +130,13 @@ class PluginXmlPatcherTest { """.trimIndent(), """ - - CSS - com.intellij.css - x-plugin-version - - - - + + CSS + com.intellij.css + x-plugin-version + + + """.trimIndent(), toPublish = true, isEap = false @@ -154,14 +155,13 @@ class PluginXmlPatcherTest { """.trimIndent(), """ - - CSS - com.intellij.css - x-plugin-version - - - - + + CSS + com.intellij.css + x-plugin-version + + + """.trimIndent(), toPublish = true, isEap = true @@ -182,18 +182,14 @@ class PluginXmlPatcherTest { """.trimIndent(), """ - - Database Tools and SQL for WebStorm - com.intellij.database - x-plugin-version - - - - - - + + Database Tools and SQL for WebStorm + com.intellij.database + x-plugin-version + + + xxx for WebStorm provides + """.trimIndent(), productName = "WebStorm", toPublish = true, @@ -214,18 +210,14 @@ class PluginXmlPatcherTest { """.trimIndent(), """ - - Database Tools and SQL - com.intellij.database - x-plugin-version - - - - - - + + Database Tools and SQL + com.intellij.database + x-plugin-version + + + xxx for IntelliJ-based IDEs provides + """.trimIndent(), toPublish = true, ) @@ -239,35 +231,37 @@ class PluginXmlPatcherTest { """.trimIndent(), """ - - com - x-plugin-version - - - + + com + x-plugin-version + + + """.trimIndent(), retainProductDescriptorForBundledPlugin = true, toPublish = false, ) private fun assertTransform( - before: String, - after: String, + @Language("XML") before: String, + @Language("XML") after: String, productName: String = "UnExistent", toPublish: Boolean = false, isEap: Boolean = false, retainProductDescriptorForBundledPlugin: Boolean = false, ) { - val result = doPatchPluginXml(document = XMLParser.parse(before), - pluginModuleName = "x-plugin-module-name", - pluginVersion = "x-plugin-version", - releaseDate = "X-RELEASE-DATE-X", - releaseVersion = "X-RELEASE-VERSION-X", - compatibleSinceUntil = Pair("new-since", "new-until"), - toPublish = toPublish, - retainProductDescriptorForBundledPlugin = retainProductDescriptorForBundledPlugin, - isEap = isEap, - productName = productName) + val result = doPatchPluginXml( + rootElement = JDOMUtil.load(before), + pluginModuleName = "x-plugin-module-name", + pluginVersion = "x-plugin-version", + releaseDate = "X-RELEASE-DATE-X", + releaseVersion = "X-RELEASE-VERSION-X", + compatibleSinceUntil = Pair("new-since", "new-until"), + toPublish = toPublish, + retainProductDescriptorForBundledPlugin = retainProductDescriptorForBundledPlugin, + isEap = isEap, + productName = productName, + ) assertThat(result).isEqualTo(after) } } \ No newline at end of file