From 5063cd0284cf9db23aa3bb24f0a61894e62d53f8 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 25 Mar 2024 12:29:02 +0100 Subject: [PATCH] IJPL-866 refactor - extract readSubModuleExternal and inline it (it makes clear that pathResolver and dataLoader are not required to read module) GitOrigin-RevId: f7399a0780c08e73e6d053da13d32e616d907fb4 --- .../ide/plugins/IdeaPluginDescriptorImpl.kt | 126 ++++++++++-------- .../ide/plugins/PathBasedJdomXIncluder.kt | 32 +++-- .../ide/plugins/PluginDescriptorLoader.kt | 8 +- .../ide/plugins/ProductLoadingStrategy.kt | 2 +- .../ide/plugins/PluginDescriptorTest.kt | 7 +- 5 files changed, 98 insertions(+), 77 deletions(-) diff --git a/platform/core-impl/src/com/intellij/ide/plugins/IdeaPluginDescriptorImpl.kt b/platform/core-impl/src/com/intellij/ide/plugins/IdeaPluginDescriptorImpl.kt index 57303edd3f9d..3cd262ba03e9 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/IdeaPluginDescriptorImpl.kt +++ b/platform/core-impl/src/com/intellij/ide/plugins/IdeaPluginDescriptorImpl.kt @@ -58,12 +58,14 @@ class IdeaPluginDescriptorImpl( // only for sub descriptors @JvmField internal var descriptorPath: String? = null + @Volatile private var description: String? = null private val productCode = raw.productCode private var releaseDate: Date? = raw.releaseDate?.let { Date.from(it.atStartOfDay(ZoneOffset.UTC).toInstant()) } private val releaseVersion = raw.releaseVersion private val isLicenseOptional = raw.isLicenseOptional + @NonNls private var resourceBundleBaseName: String? = null private val changeNotes = raw.changeNotes @@ -72,10 +74,13 @@ class IdeaPluginDescriptorImpl( private val vendorEmail = raw.vendorEmail private val vendorUrl = raw.vendorUrl private var category: String? = raw.category + @JvmField internal val url: String? = raw.url + @JvmField val pluginDependencies: List + @JvmField val incompatibilities: List = raw.incompatibilities ?: Java11Shim.INSTANCE.listOf() @@ -140,8 +145,10 @@ class IdeaPluginDescriptorImpl( @JvmField val appContainerDescriptor: ContainerDescriptor = raw.appContainerDescriptor + @JvmField val projectContainerDescriptor: ContainerDescriptor = raw.projectContainerDescriptor + @JvmField val moduleContainerDescriptor: ContainerDescriptor = raw.moduleContainerDescriptor @@ -151,6 +158,7 @@ class IdeaPluginDescriptorImpl( @JvmField val dependencies: ModuleDependenciesDescriptor = raw.dependencies + @JvmField var modules: List = raw.modules ?: Java11Shim.INSTANCE.listOf() @@ -158,12 +166,16 @@ class IdeaPluginDescriptorImpl( @JvmField val isUseIdeaClassLoader: Boolean = raw.isUseIdeaClassLoader + @JvmField val isBundledUpdateAllowed: Boolean = raw.isBundledUpdateAllowed + @JvmField internal val implementationDetail: Boolean = raw.implementationDetail + @JvmField internal val isRestartRequired: Boolean = raw.isRestartRequired + @JvmField val packagePrefix: String? = raw.`package` @@ -185,9 +197,7 @@ class IdeaPluginDescriptorImpl( private fun createSub( raw: RawPluginDescriptor, descriptorPath: String, - pathResolver: PathResolver, context: DescriptorListLoadingContext, - dataLoader: DataLoader, moduleName: String?, ): IdeaPluginDescriptorImpl { raw.name = name @@ -202,10 +212,13 @@ class IdeaPluginDescriptorImpl( context.debugData?.recordDescriptorPath(descriptor = result, rawPluginDescriptor = raw, path = descriptorPath) result.descriptorPath = descriptorPath result.vendor = vendor - result.version = version - result.resourceBundleBaseName = resourceBundleBaseName - result.readExternal(raw = raw, pathResolver = pathResolver, context = context, isSub = true, dataLoader = dataLoader) + result.resourceBundleBaseName = resourceBundleBaseName + if (raw.resourceBundleBaseName != null) { + result.readResourceBundleBaseName(raw = raw) + } + + result.version = version ?: context.defaultVersion return result } @@ -213,73 +226,63 @@ class IdeaPluginDescriptorImpl( raw: RawPluginDescriptor, pathResolver: PathResolver, context: DescriptorListLoadingContext, - isSub: Boolean, dataLoader: DataLoader, ) { // include module file descriptor if not specified as `depends` (old way - xi:include) // must be first because merged into raw descriptor - if (!isSub) { - for (module in content.modules) { - val subDescriptorFile = module.configFile ?: "${module.name}.xml" - val subDescriptor = createSub( - raw = pathResolver.resolveModuleFile( - readContext = context, - dataLoader = dataLoader, - path = subDescriptorFile, - readInto = null, - ), - descriptorPath = subDescriptorFile, - pathResolver = pathResolver, - context = context, + for (module in content.modules) { + val subDescriptorFile = module.configFile ?: "${module.name}.xml" + val subDescriptor = createSub( + raw = pathResolver.resolveModuleFile( + readContext = context, dataLoader = dataLoader, - moduleName = module.name, - ) - module.descriptor = subDescriptor - } + path = subDescriptorFile, + readInto = null, + ), + descriptorPath = subDescriptorFile, + context = context, + moduleName = module.name, + ) + module.descriptor = subDescriptor } if (raw.resourceBundleBaseName != null) { - if (id == PluginManagerCore.CORE_ID && !isSub) { + if (id == PluginManagerCore.CORE_ID) { LOG.warn("${raw.resourceBundleBaseName} tag is found in an xml descriptor" + " included into the platform part of the IDE but the platform part uses predefined bundles " + "(e.g. ActionsBundle for actions) anyway; this tag must be replaced by a corresponding attribute in some inner tags " + "(e.g. by 'resource-bundle' attribute in 'actions' tag)") } - if (resourceBundleBaseName != null && resourceBundleBaseName != raw.resourceBundleBaseName) { - LOG.warn("Resource bundle redefinition for plugin $id. " + - "Old value: $resourceBundleBaseName, new value: ${raw.resourceBundleBaseName}") - } - resourceBundleBaseName = raw.resourceBundleBaseName + readResourceBundleBaseName(raw) } if (version == null) { version = context.defaultVersion } - if (!isSub) { - if (id == PluginManagerCore.CORE_ID) { - modules = modules + IdeaPluginOsRequirement.getHostOsModuleIds() - if (!AppMode.isRemoteDevHost()) { - /* dependency on this ID may be used to enable some functionality in local IDE and in JetBrains Client, but disable it in product - running in backend mode; this is needed because the backend process currently doesn't use module-based loader and therefore cannot - use marker modules from ProductModes. */ - modules = modules + PluginId.getId("com.intellij.platform.experimental.frontend") - } + if (id == PluginManagerCore.CORE_ID) { + modules = modules + IdeaPluginOsRequirement.getHostOsModuleIds() + if (!AppMode.isRemoteDevHost()) { + // Dependency on this ID may be used to enable some functionality in the local IDE + // and in JetBrains Client, but disable it in product running in backend mode. + // This is needed because the backend process currently doesn't use module-based loader and therefore cannot + // use marker modules from ProductModes. + modules = modules + PluginId.getId("com.intellij.platform.experimental.frontend") + } + } + + if (context.isPluginDisabled(id)) { + markAsIncomplete(disabledDependency = null, shortMessage = null) + } + else { + checkCompatibility(context) + if (isIncomplete != null) { + return } - if (context.isPluginDisabled(id)) { - markAsIncomplete(disabledDependency = null, shortMessage = null) - } - else { - checkCompatibility(context) - if (isIncomplete != null) { - return - } - - for (pluginDependency in dependencies.plugins) { - if (context.isPluginDisabled(pluginDependency.id)) { - markAsIncomplete(pluginDependency.id, shortMessage = "plugin.loading.error.short.depends.on.disabled.plugin") - } + for (pluginDependency in dependencies.plugins) { + if (context.isPluginDisabled(pluginDependency.id)) { + markAsIncomplete(pluginDependency.id, shortMessage = "plugin.loading.error.short.depends.on.disabled.plugin") } } } @@ -293,6 +296,13 @@ class IdeaPluginDescriptorImpl( } } + private fun readResourceBundleBaseName(raw: RawPluginDescriptor) { + if (resourceBundleBaseName != null && resourceBundleBaseName != raw.resourceBundleBaseName) { + LOG.warn("Resource bundle redefinition for plugin $id. Old value: $resourceBundleBaseName, new value: ${raw.resourceBundleBaseName}") + } + resourceBundleBaseName = raw.resourceBundleBaseName + } + private fun processOldDependencies(descriptor: IdeaPluginDescriptorImpl, context: DescriptorListLoadingContext, pathResolver: PathResolver, @@ -346,11 +356,21 @@ class IdeaPluginDescriptorImpl( val subDescriptor = descriptor.createSub( raw = raw, descriptorPath = configFile, - pathResolver = pathResolver, context = context, - dataLoader = dataLoader, moduleName = null, ) + + if (subDescriptor.isIncomplete == null) { + processOldDependencies( + descriptor = subDescriptor, + context = context, + pathResolver = pathResolver, + dependencies = subDescriptor.pluginDependencies, + dataLoader = dataLoader, + ) + } + + dependency.subDescriptor = subDescriptor visitedFiles.clear() } diff --git a/platform/core-impl/src/com/intellij/ide/plugins/PathBasedJdomXIncluder.kt b/platform/core-impl/src/com/intellij/ide/plugins/PathBasedJdomXIncluder.kt index 8063c8e35498..2e9e4538b65f 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/PathBasedJdomXIncluder.kt +++ b/platform/core-impl/src/com/intellij/ide/plugins/PathBasedJdomXIncluder.kt @@ -7,20 +7,26 @@ interface PathResolver { val isFlat: Boolean get() = false - fun loadXIncludeReference(readInto: RawPluginDescriptor, - readContext: ReadModuleContext, - dataLoader: DataLoader, - base: String?, - relativePath: String): Boolean + fun loadXIncludeReference( + readInto: RawPluginDescriptor, + readContext: ReadModuleContext, + dataLoader: DataLoader, + base: String?, + relativePath: String, + ): Boolean - fun resolvePath(readContext: ReadModuleContext, - dataLoader: DataLoader, - relativePath: String, - readInto: RawPluginDescriptor?): RawPluginDescriptor? + fun resolvePath( + readContext: ReadModuleContext, + dataLoader: DataLoader, + relativePath: String, + readInto: RawPluginDescriptor?, + ): RawPluginDescriptor? // module in a new file name format must always be resolved - fun resolveModuleFile(readContext: ReadModuleContext, - dataLoader: DataLoader, - path: String, - readInto: RawPluginDescriptor?): RawPluginDescriptor + fun resolveModuleFile( + readContext: ReadModuleContext, + dataLoader: DataLoader, + path: String, + readInto: RawPluginDescriptor?, + ): RawPluginDescriptor } \ No newline at end of file diff --git a/platform/core-impl/src/com/intellij/ide/plugins/PluginDescriptorLoader.kt b/platform/core-impl/src/com/intellij/ide/plugins/PluginDescriptorLoader.kt index 3fb9e25eff28..8a168f87c3e7 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/PluginDescriptorLoader.kt +++ b/platform/core-impl/src/com/intellij/ide/plugins/PluginDescriptorLoader.kt @@ -113,7 +113,7 @@ fun loadDescriptorFromDir( useCoreClassLoader = useCoreClassLoader, ) context.debugData?.recordDescriptorPath(descriptor = descriptor, rawPluginDescriptor = raw, path = descriptorRelativePath) - descriptor.readExternal(raw = raw, pathResolver = pathResolver, context = context, isSub = false, dataLoader = dataLoader) + descriptor.readExternal(raw = raw, pathResolver = pathResolver, context = context, dataLoader = dataLoader) descriptor.jarFiles = Collections.singletonList(dir) return descriptor } @@ -171,7 +171,7 @@ fun loadDescriptorFromJar( useCoreClassLoader = useCoreClassLoader, ) parentContext.debugData?.recordDescriptorPath(descriptor, raw, descriptorRelativePath) - descriptor.readExternal(raw = raw, pathResolver = pathResolver, context = parentContext, isSub = false, dataLoader = dataLoader) + descriptor.readExternal(raw = raw, pathResolver = pathResolver, context = parentContext, dataLoader = dataLoader) descriptor.jarFiles = Collections.singletonList(descriptor.pluginPath) return descriptor } @@ -691,7 +691,7 @@ private fun loadCoreProductPlugin( useCoreClassLoader = useCoreClassLoader, ) context.debugData?.recordDescriptorPath(descriptor, raw, path) - descriptor.readExternal(raw = raw, pathResolver = pathResolver, context = context, isSub = false, dataLoader = dataLoader) + descriptor.readExternal(raw = raw, pathResolver = pathResolver, context = context, dataLoader = dataLoader) return descriptor } @@ -932,7 +932,7 @@ private fun loadDescriptorFromResource( useCoreClassLoader = useCoreClassLoader, ) context.debugData?.recordDescriptorPath(descriptor, raw, filename) - descriptor.readExternal(raw = raw, pathResolver = pathResolver, context = context, isSub = false, dataLoader = dataLoader) + descriptor.readExternal(raw = raw, pathResolver = pathResolver, context = context, dataLoader = dataLoader) // do not set jarFiles by intention - doesn't make sense return descriptor } diff --git a/platform/core-impl/src/com/intellij/ide/plugins/ProductLoadingStrategy.kt b/platform/core-impl/src/com/intellij/ide/plugins/ProductLoadingStrategy.kt index 29908a6c0a42..45e2867fdd6d 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/ProductLoadingStrategy.kt +++ b/platform/core-impl/src/com/intellij/ide/plugins/ProductLoadingStrategy.kt @@ -223,7 +223,7 @@ private class PathBasedProductLoadingStrategy : ProductLoadingStrategy() { moduleName = null, ) context.debugData?.recordDescriptorPath(descriptor, raw, PluginManagerCore.PLUGIN_XML_PATH) - descriptor.readExternal(raw = raw, pathResolver = pluginPathResolver, context = context, isSub = false, dataLoader = dataLoader) + descriptor.readExternal(raw = raw, pathResolver = pluginPathResolver, context = context, dataLoader = dataLoader) descriptor.jarFiles = fileItems.map { it.file } return descriptor } diff --git a/platform/platform-tests/testSrc/com/intellij/ide/plugins/PluginDescriptorTest.kt b/platform/platform-tests/testSrc/com/intellij/ide/plugins/PluginDescriptorTest.kt index 381f07dd9085..3ab71fae164e 100644 --- a/platform/platform-tests/testSrc/com/intellij/ide/plugins/PluginDescriptorTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/ide/plugins/PluginDescriptorTest.kt @@ -588,7 +588,6 @@ fun readDescriptorForTest(path: Path, isBundled: Boolean, input: ByteArray, id: val result = IdeaPluginDescriptorImpl(raw = raw, path = path, isBundled = isBundled, id = id, moduleName = null) result.readExternal( raw = raw, - isSub = false, context = DescriptorListLoadingContext(customDisabledPlugins = emptySet()), pathResolver = pathResolver, dataLoader = dataLoader, @@ -610,10 +609,6 @@ fun createFromDescriptor(path: Path, readInto = null, locationSource = path.toString()) val result = IdeaPluginDescriptorImpl(raw = raw, path = path, isBundled = isBundled, id = null, moduleName = null) - result.readExternal(raw = raw, - pathResolver = pathResolver, - context = context, - isSub = false, - dataLoader = dataLoader) + result.readExternal(raw = raw, pathResolver = pathResolver, context = context, dataLoader = dataLoader) return result }