mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Refactor tests: use loadPluginWithText for all plugin loading tasks
GitOrigin-RevId: d8fa2d45a961245c860b533148622b0225f08399
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0b884f5a9a
commit
bf032008e8
@@ -542,21 +542,12 @@ class DynamicPluginsTest {
|
||||
try {
|
||||
val quuxDisposable = loadPluginWithText(quuxBuilder)
|
||||
try {
|
||||
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()
|
||||
|
||||
DynamicPlugins.loadPlugin(descriptor)
|
||||
val mainDisposable = loadPluginWithText(mainDescriptor)
|
||||
try {
|
||||
assertThat(ApplicationManager.getApplication().getService(MyPersistentComponent::class.java)).isNotNull()
|
||||
}
|
||||
finally {
|
||||
val unloadDescriptor = loadDescriptorInTest(directory)
|
||||
val canBeUnloaded = DynamicPlugins.allowLoadUnloadWithoutRestart(unloadDescriptor)
|
||||
DynamicPlugins.unloadPlugin(unloadDescriptor)
|
||||
assertThat(canBeUnloaded).isTrue()
|
||||
Disposer.dispose(mainDisposable)
|
||||
assertThat(ApplicationManager.getApplication().getService(MyPersistentComponent::class.java)).isNull()
|
||||
}
|
||||
}
|
||||
@@ -571,8 +562,6 @@ 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")
|
||||
|
||||
@@ -584,22 +573,14 @@ class DynamicPluginsTest {
|
||||
val barDisposable = loadPluginWithText(barBuilder)
|
||||
try {
|
||||
val quuxDisposable = loadPluginWithText(quuxBuilder)
|
||||
mainDescriptor.build(directory)
|
||||
val descriptor = loadDescriptorInTest(directory)
|
||||
setPluginClassLoaderForMainAndSubPlugins(descriptor, DynamicPluginsTest::class.java.classLoader)
|
||||
assertThat(DynamicPlugins.checkCanUnloadWithoutRestart(descriptor)).isNull()
|
||||
|
||||
DynamicPlugins.loadPlugin(descriptor)
|
||||
val mainDisposable = loadPluginWithText(mainDescriptor)
|
||||
try {
|
||||
assertThat(ApplicationManager.getApplication().getService(MyPersistentComponent::class.java)).isNotNull()
|
||||
Disposer.dispose(quuxDisposable)
|
||||
assertThat(ApplicationManager.getApplication().getService(MyPersistentComponent::class.java)).isNull()
|
||||
}
|
||||
finally {
|
||||
val unloadDescriptor = loadDescriptorInTest(directory)
|
||||
val canBeUnloaded = DynamicPlugins.allowLoadUnloadWithoutRestart(unloadDescriptor)
|
||||
DynamicPlugins.unloadPlugin(unloadDescriptor)
|
||||
assertThat(canBeUnloaded).isTrue()
|
||||
Disposer.dispose(mainDisposable)
|
||||
}
|
||||
}
|
||||
finally {
|
||||
@@ -610,21 +591,8 @@ class DynamicPluginsTest {
|
||||
private fun loadPluginWithOptionalDependency(pluginDescriptor: PluginBuilder,
|
||||
optionalDependencyDescriptor: PluginBuilder,
|
||||
dependsOn: PluginBuilder): Disposable {
|
||||
val directory = inMemoryFs.fs.getPath("/").resolve(Ksuid.generate()).resolve("plugin")
|
||||
pluginDescriptor.depends(dependsOn.id, optionalDependencyDescriptor).build(directory)
|
||||
|
||||
val descriptor = loadDescriptorInTest(directory)
|
||||
setPluginClassLoaderForMainAndSubPlugins(descriptor, DynamicPluginsTest::class.java.classLoader)
|
||||
assertThat(DynamicPlugins.checkCanUnloadWithoutRestart(descriptor)).isNull()
|
||||
|
||||
DynamicPlugins.loadPlugin(descriptor)
|
||||
|
||||
return Disposable {
|
||||
val unloadDescriptor = loadDescriptorInTest(directory)
|
||||
val canBeUnloaded = DynamicPlugins.allowLoadUnloadWithoutRestart(unloadDescriptor)
|
||||
DynamicPlugins.unloadPlugin(unloadDescriptor)
|
||||
assertThat(canBeUnloaded).isTrue()
|
||||
}
|
||||
pluginDescriptor.depends(dependsOn.id, optionalDependencyDescriptor)
|
||||
return loadPluginWithText(pluginDescriptor)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-12
@@ -11,7 +11,6 @@ import com.intellij.openapi.util.BuildNumber
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.testFramework.assertions.Assertions.assertThat
|
||||
import com.intellij.util.io.Ksuid
|
||||
import com.intellij.util.io.write
|
||||
import java.nio.file.FileSystem
|
||||
import java.nio.file.FileSystems
|
||||
import java.nio.file.Files
|
||||
@@ -45,7 +44,14 @@ fun loadExtensionWithText(
|
||||
}
|
||||
|
||||
internal fun loadPluginWithText(pluginBuilder: PluginBuilder, loader: ClassLoader, fs: FileSystem): Disposable {
|
||||
val descriptor = preparePluginDescriptor(pluginBuilder.text(), fs).second
|
||||
val directory = if (fs == FileSystems.getDefault())
|
||||
FileUtil.createTempDirectory("test", "test", true).toPath()
|
||||
else
|
||||
fs.getPath("/").resolve(Ksuid.generate())
|
||||
val pluginDirectory = directory.resolve("plugin")
|
||||
|
||||
pluginBuilder.build(pluginDirectory)
|
||||
val descriptor = loadDescriptorInTest(pluginDirectory)
|
||||
assertThat(DynamicPlugins.checkCanUnloadWithoutRestart(descriptor)).isNull()
|
||||
setPluginClassLoaderForMainAndSubPlugins(descriptor, loader)
|
||||
try {
|
||||
@@ -57,22 +63,14 @@ internal fun loadPluginWithText(pluginBuilder: PluginBuilder, loader: ClassLoade
|
||||
}
|
||||
|
||||
return Disposable {
|
||||
val canBeUnloaded = DynamicPlugins.allowLoadUnloadWithoutRestart(descriptor)
|
||||
val unloadDescriptor = loadDescriptorInTest(pluginDirectory)
|
||||
val canBeUnloaded = DynamicPlugins.allowLoadUnloadWithoutRestart(unloadDescriptor)
|
||||
unloadPlugin(descriptor)
|
||||
|
||||
assertThat(canBeUnloaded).isTrue()
|
||||
}
|
||||
}
|
||||
|
||||
private fun preparePluginDescriptor(pluginXml: String, fs: FileSystem): Pair<Path, IdeaPluginDescriptorImpl> {
|
||||
val directory = if (fs == FileSystems.getDefault()) FileUtil.createTempDirectory("test", "test", true).toPath() else fs.getPath("/").resolve(
|
||||
Ksuid.generate())
|
||||
val plugin = directory.resolve("plugin/META-INF/plugin.xml")
|
||||
plugin.write(pluginXml)
|
||||
val descriptor = loadDescriptorInTest(plugin.parent.parent)
|
||||
return Pair(plugin, descriptor)
|
||||
}
|
||||
|
||||
internal fun setPluginClassLoaderForMainAndSubPlugins(rootDescriptor: IdeaPluginDescriptorImpl, classLoader: ClassLoader?) {
|
||||
rootDescriptor.classLoader = classLoader
|
||||
for (dependency in rootDescriptor.getPluginDependencies()) {
|
||||
|
||||
Reference in New Issue
Block a user