mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Refactor tests: simplify support for optional plugin descriptors in PluginBuilder
GitOrigin-RevId: cf3cca76b5cea3f57605fde8895d38da7cce6fe0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
abe415faac
commit
0b884f5a9a
+2
-1
@@ -68,7 +68,8 @@ internal class ClassLoaderConfiguratorTest {
|
||||
.noDepends()
|
||||
.packagePrefix("com.example")
|
||||
// dependent must not be empty, add some extension
|
||||
.depends(pluginDependency.buildToAutoGeneratedSubDir(rootDir).id, dependent().extensions("""<barExtension key="foo" implementationClass="y"/>""", "bar"), rootDir)
|
||||
.depends(pluginDependency.buildToAutoGeneratedSubDir(rootDir).id,
|
||||
dependent().extensions("""<barExtension key="foo" implementationClass="y"/>""", "bar"))
|
||||
.buildToAutoGeneratedSubDir(rootDir)
|
||||
val loadResult = loadDescriptors(rootDir)
|
||||
val plugins: List<IdeaPluginDescriptorImpl> = loadResult.enabledPlugins
|
||||
|
||||
@@ -35,7 +35,6 @@ import com.intellij.testFramework.rules.InMemoryFsRule
|
||||
import com.intellij.ui.switcher.ShowQuickActionPopupAction
|
||||
import com.intellij.util.KeyedLazyInstanceEP
|
||||
import com.intellij.util.io.Ksuid
|
||||
import com.intellij.util.io.write
|
||||
import com.intellij.util.ui.UIUtil
|
||||
import com.intellij.util.xmlb.annotations.Attribute
|
||||
import org.junit.ClassRule
|
||||
@@ -363,7 +362,7 @@ class DynamicPluginsTest {
|
||||
Disposer.dispose(pluginOneDisposable)
|
||||
}
|
||||
finally {
|
||||
pluginTwoDisposable.dispose()
|
||||
Disposer.dispose(pluginTwoDisposable)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,18 +506,16 @@ class DynamicPluginsTest {
|
||||
val quuxBuilder = PluginBuilder().randomId("quux")
|
||||
|
||||
val quuxDependencyDescriptor = PluginBuilder().extensions("""<barExtension key="foo" implementationClass="y"/>""", "foo")
|
||||
val barDependencyDescriptor = PluginBuilder().depends(quuxBuilder.id, "quux.xml")
|
||||
val mainDescriptor = PluginBuilder().randomId("main").depends(barBuilder.id, "bar.xml")
|
||||
val barDependencyDescriptor = PluginBuilder().depends(quuxBuilder.id, quuxDependencyDescriptor)
|
||||
val mainDescriptor = PluginBuilder().randomId("main").depends(barBuilder.id, barDependencyDescriptor)
|
||||
|
||||
val barDisposable = loadPluginWithText(barBuilder)
|
||||
try {
|
||||
val quuxDisposable = loadPluginWithText(quuxBuilder)
|
||||
try {
|
||||
val directory = Files.createTempDirectory(inMemoryFs.fs.getPath("/"), null).resolve("plugin/META-INF")
|
||||
directory.resolve("bar.xml").write(barDependencyDescriptor.text(requireId = false))
|
||||
directory.resolve("quux.xml").write(quuxDependencyDescriptor.text(requireId = false))
|
||||
directory.resolve("plugin.xml").write(mainDescriptor.text())
|
||||
val descriptor = loadDescriptorInTest(directory.parent)
|
||||
val directory = Files.createTempDirectory(inMemoryFs.fs.getPath("/"), null).resolve("plugin")
|
||||
mainDescriptor.build(directory)
|
||||
val descriptor = loadDescriptorInTest(directory)
|
||||
setPluginClassLoaderForMainAndSubPlugins(descriptor, DynamicPluginsTest::class.java.classLoader)
|
||||
assertThat(DynamicPlugins.checkCanUnloadWithoutRestart(descriptor)).isEqualTo(
|
||||
"Plugin ${mainDescriptor.id} is not unload-safe because of extension to non-dynamic EP foo.barExtension in optional dependency on ${quuxBuilder.id} in optional dependency on ${barBuilder.id}")
|
||||
@@ -537,18 +534,17 @@ class DynamicPluginsTest {
|
||||
val barBuilder = PluginBuilder().randomId("bar")
|
||||
val quuxBuilder = PluginBuilder().randomId("quux")
|
||||
|
||||
val quuxDependencyDescriptor = PluginBuilder().extensions("""<applicationService serviceImplementation="${MyPersistentComponent::class.java.name}"/>""")
|
||||
val barDependencyDescriptor = PluginBuilder().depends(quuxBuilder.id, "quux.xml")
|
||||
val mainDescriptor = PluginBuilder().depends(barBuilder.id, "bar.xml")
|
||||
val quuxDependencyDescriptor = PluginBuilder().extensions(
|
||||
"""<applicationService serviceImplementation="${MyPersistentComponent::class.java.name}"/>""")
|
||||
val barDependencyDescriptor = PluginBuilder().depends(quuxBuilder.id, quuxDependencyDescriptor)
|
||||
val mainDescriptor = PluginBuilder().depends(barBuilder.id, barDependencyDescriptor)
|
||||
val barDisposable = loadPluginWithText(barBuilder)
|
||||
try {
|
||||
val quuxDisposable = loadPluginWithText(quuxBuilder)
|
||||
try {
|
||||
val directory = Files.createTempDirectory(inMemoryFs.fs.getPath("/"), null).resolve("plugin/META-INF")
|
||||
directory.resolve("bar.xml").write(barDependencyDescriptor.text(requireId = false))
|
||||
directory.resolve("quux.xml").write(quuxDependencyDescriptor.text(requireId = false))
|
||||
directory.resolve("plugin.xml").write(mainDescriptor.text())
|
||||
val descriptor = loadDescriptorInTest(directory.parent)
|
||||
val directory = Files.createTempDirectory(inMemoryFs.fs.getPath("/"), null).resolve("plugin")
|
||||
mainDescriptor.build(directory)
|
||||
val descriptor = loadDescriptorInTest(directory)
|
||||
setPluginClassLoaderForMainAndSubPlugins(descriptor, DynamicPluginsTest::class.java.classLoader)
|
||||
assertThat(DynamicPlugins.checkCanUnloadWithoutRestart(descriptor)).isNull()
|
||||
|
||||
@@ -557,7 +553,7 @@ class DynamicPluginsTest {
|
||||
assertThat(ApplicationManager.getApplication().getService(MyPersistentComponent::class.java)).isNotNull()
|
||||
}
|
||||
finally {
|
||||
val unloadDescriptor = loadDescriptorInTest(directory.parent)
|
||||
val unloadDescriptor = loadDescriptorInTest(directory)
|
||||
val canBeUnloaded = DynamicPlugins.allowLoadUnloadWithoutRestart(unloadDescriptor)
|
||||
DynamicPlugins.unloadPlugin(unloadDescriptor)
|
||||
assertThat(canBeUnloaded).isTrue()
|
||||
@@ -575,20 +571,21 @@ class DynamicPluginsTest {
|
||||
|
||||
@Test
|
||||
fun unloadNestedOptionalDependency() {
|
||||
val directory = Files.createTempDirectory(inMemoryFs.fs.getPath("/"), null).resolve("plugin")
|
||||
|
||||
val barBuilder = PluginBuilder().randomId("bar")
|
||||
val quuxBuilder = PluginBuilder().randomId("quux")
|
||||
|
||||
val quuxDependencyDescriptor = PluginBuilder().extensions("""<applicationService serviceImplementation="${MyPersistentComponent::class.java.name}"/>""")
|
||||
val barDependencyDescriptor = PluginBuilder().depends(quuxBuilder.id, "quux.xml")
|
||||
val mainDescriptor = PluginBuilder().depends(barBuilder.id, "bar.xml")
|
||||
val quuxDependencyDescriptor = PluginBuilder().extensions(
|
||||
"""<applicationService serviceImplementation="${MyPersistentComponent::class.java.name}"/>""")
|
||||
val barDependencyDescriptor = PluginBuilder().depends(quuxBuilder.id, quuxDependencyDescriptor)
|
||||
val mainDescriptor = PluginBuilder().depends(barBuilder.id, barDependencyDescriptor)
|
||||
|
||||
val barDisposable = loadPluginWithText(barBuilder)
|
||||
try {
|
||||
val quuxDisposable = loadPluginWithText(quuxBuilder)
|
||||
val directory = Files.createTempDirectory(inMemoryFs.fs.getPath("/"), null).resolve("plugin/META-INF")
|
||||
directory.resolve("bar.xml").write(barDependencyDescriptor.text(requireId = false))
|
||||
directory.resolve("quux.xml").write(quuxDependencyDescriptor.text(requireId = false))
|
||||
directory.resolve("plugin.xml").write(mainDescriptor.text())
|
||||
val descriptor = loadDescriptorInTest(directory.parent)
|
||||
mainDescriptor.build(directory)
|
||||
val descriptor = loadDescriptorInTest(directory)
|
||||
setPluginClassLoaderForMainAndSubPlugins(descriptor, DynamicPluginsTest::class.java.classLoader)
|
||||
assertThat(DynamicPlugins.checkCanUnloadWithoutRestart(descriptor)).isNull()
|
||||
|
||||
@@ -599,7 +596,7 @@ class DynamicPluginsTest {
|
||||
assertThat(ApplicationManager.getApplication().getService(MyPersistentComponent::class.java)).isNull()
|
||||
}
|
||||
finally {
|
||||
val unloadDescriptor = loadDescriptorInTest(directory.parent)
|
||||
val unloadDescriptor = loadDescriptorInTest(directory)
|
||||
val canBeUnloaded = DynamicPlugins.allowLoadUnloadWithoutRestart(unloadDescriptor)
|
||||
DynamicPlugins.unloadPlugin(unloadDescriptor)
|
||||
assertThat(canBeUnloaded).isTrue()
|
||||
@@ -613,20 +610,17 @@ class DynamicPluginsTest {
|
||||
private fun loadPluginWithOptionalDependency(pluginDescriptor: PluginBuilder,
|
||||
optionalDependencyDescriptor: PluginBuilder,
|
||||
dependsOn: PluginBuilder): Disposable {
|
||||
val directory = inMemoryFs.fs.getPath("/").resolve(Ksuid.generate()).resolve("plugin/META-INF")
|
||||
val plugin = directory.resolve("plugin.xml")
|
||||
pluginDescriptor.depends(dependsOn.id, "bar.xml")
|
||||
plugin.write(pluginDescriptor.text().trimIndent())
|
||||
directory.resolve("bar.xml").write(optionalDependencyDescriptor.text(requireId = false))
|
||||
val directory = inMemoryFs.fs.getPath("/").resolve(Ksuid.generate()).resolve("plugin")
|
||||
pluginDescriptor.depends(dependsOn.id, optionalDependencyDescriptor).build(directory)
|
||||
|
||||
val descriptor = loadDescriptorInTest(plugin.parent.parent)
|
||||
val descriptor = loadDescriptorInTest(directory)
|
||||
setPluginClassLoaderForMainAndSubPlugins(descriptor, DynamicPluginsTest::class.java.classLoader)
|
||||
assertThat(DynamicPlugins.checkCanUnloadWithoutRestart(descriptor)).isNull()
|
||||
|
||||
DynamicPlugins.loadPlugin(descriptor)
|
||||
|
||||
return Disposable {
|
||||
val unloadDescriptor = loadDescriptorInTest(plugin.parent.parent)
|
||||
val unloadDescriptor = loadDescriptorInTest(directory)
|
||||
val canBeUnloaded = DynamicPlugins.allowLoadUnloadWithoutRestart(unloadDescriptor)
|
||||
DynamicPlugins.unloadPlugin(unloadDescriptor)
|
||||
assertThat(canBeUnloaded).isTrue()
|
||||
|
||||
@@ -31,6 +31,8 @@ class PluginBuilder {
|
||||
private var untilBuild: String? = null
|
||||
private var version: String? = null
|
||||
|
||||
private val subDescriptors = mutableMapOf<String, PluginBuilder>()
|
||||
|
||||
init {
|
||||
depends("com.intellij.modules.lang")
|
||||
}
|
||||
@@ -65,9 +67,9 @@ class PluginBuilder {
|
||||
return this
|
||||
}
|
||||
|
||||
fun depends(pluginId: String, subDescriptor: PluginBuilder, parentDir: Path): PluginBuilder {
|
||||
fun depends(pluginId: String, subDescriptor: PluginBuilder): PluginBuilder {
|
||||
val fileName = "dep_${pluginIdCounter.incrementAndGet()}.xml"
|
||||
parentDir.resolve(id).resolve("META-INF").resolve(fileName).write(subDescriptor.text(requireId = false))
|
||||
subDescriptors[fileName] = subDescriptor
|
||||
depends(pluginId, fileName)
|
||||
return this
|
||||
}
|
||||
@@ -156,9 +158,17 @@ class PluginBuilder {
|
||||
|
||||
fun build(path: Path): PluginBuilder {
|
||||
path.resolve("META-INF/plugin.xml").write(text())
|
||||
writeSubDescriptors(path)
|
||||
return this
|
||||
}
|
||||
|
||||
fun writeSubDescriptors(path: Path) {
|
||||
for ((fileName, subDescriptor) in subDescriptors) {
|
||||
path.resolve("META-INF/$fileName").write(subDescriptor.text(requireId = false))
|
||||
subDescriptor.writeSubDescriptors(path)
|
||||
}
|
||||
}
|
||||
|
||||
fun buildJar(path: Path): PluginBuilder {
|
||||
buildJarToStream(Files.newOutputStream(path))
|
||||
return this
|
||||
|
||||
Reference in New Issue
Block a user