From 710fbe6476dd5c8bf1cc56023e3f263141ce64f7 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 25 Mar 2024 08:59:51 +0100 Subject: [PATCH] IJPL-866 cleanup GitOrigin-RevId: ff98899ebb964b2e8a4bd87989434452e4f18dc5 --- .../dev-server/src/IdeBuilder.kt | 2 +- .../org/jetbrains/intellij/build/classpath.kt | 27 +++--- .../build/impl/DistributionJARsBuilder.kt | 2 +- .../ide/plugins/ClassLoaderConfigurator.kt | 9 +- .../ide/plugins/ClassPathXmlPathResolver.kt | 86 +++++++++++-------- 5 files changed, 66 insertions(+), 60 deletions(-) diff --git a/platform/build-scripts/dev-server/src/IdeBuilder.kt b/platform/build-scripts/dev-server/src/IdeBuilder.kt index afc0fe5ff2b3..f7c0279489f1 100644 --- a/platform/build-scripts/dev-server/src/IdeBuilder.kt +++ b/platform/build-scripts/dev-server/src/IdeBuilder.kt @@ -154,7 +154,7 @@ internal suspend fun buildProduct(productConfiguration: ProductConfiguration, re } val pluginDistributionEntriesDeferred = async { - buildPlugins(request, context, runDir, platformLayout, artifactTask) + buildPlugins(request = request, context = context, runDir = runDir, platformLayout = platformLayout, artifactTask = artifactTask) } launch { diff --git a/platform/build-scripts/src/org/jetbrains/intellij/build/classpath.kt b/platform/build-scripts/src/org/jetbrains/intellij/build/classpath.kt index e42c474e0c9b..c3d23a6c3b05 100644 --- a/platform/build-scripts/src/org/jetbrains/intellij/build/classpath.kt +++ b/platform/build-scripts/src/org/jetbrains/intellij/build/classpath.kt @@ -23,8 +23,6 @@ import java.nio.file.Files import java.nio.file.Path import kotlin.io.path.invariantSeparatorsPathString -private val excludedLibJars = java.util.Set.of(PlatformJarNames.TEST_FRAMEWORK_JAR, "junit.jar") - private fun processClassReport(consumer: (String, String) -> Unit) { val osName = System.getProperty("os.name") val classifier = when { @@ -58,25 +56,23 @@ fun reorderJar(relativePath: String, file: Path) { } } +private val excludedLibJars = java.util.Set.of(PlatformJarNames.TEST_FRAMEWORK_JAR, "junit.jar") + fun generateClasspath(homeDir: Path, libDir: Path): List { spanBuilder("generate classpath") .setAttribute("dir", homeDir.toString()) .useWithoutActiveScope { span -> - val files = computeAppClassPath(homeDir = homeDir, libDir = libDir) + val existing = HashSet() + addJarsFromDir(dir = libDir) { paths -> + paths.filterTo(existing) { !excludedLibJars.contains(it.fileName.toString()) } + } + val files = computeAppClassPath(libDir = libDir, existing = existing, homeDir = homeDir) val result = files.map { libDir.relativize(it).toString() } span.setAttribute(AttributeKey.stringArrayKey("result"), result) return result } } -private fun computeAppClassPath(homeDir: Path, libDir: Path): LinkedHashSet { - val existing = HashSet() - addJarsFromDir(libDir) { paths -> - paths.filterTo(existing) { !excludedLibJars.contains(it.fileName.toString()) } - } - return computeAppClassPath(libDir = libDir, existing = existing, homeDir = homeDir) -} - fun computeAppClassPath(libDir: Path, existing: Set, homeDir: Path): LinkedHashSet { val result = LinkedHashSet(existing.size + 4) // add first - should be listed first @@ -197,9 +193,9 @@ fun generatePluginClassPath( .map { it.path } .distinct() .toMutableList() - allEntries += pluginAsset.dir to files + allEntries.add(pluginAsset.dir to files) } - return generatePluginClassPathFromFiles(allEntries, writeDescriptor) + return generatePluginClassPathFromFiles(pluginEntries = allEntries, writeDescriptor = writeDescriptor) } fun generatePluginClassPathFromFiles(pluginEntries: List>>, writeDescriptor: Boolean): ByteArray { @@ -210,13 +206,14 @@ fun generatePluginClassPathFromFiles(pluginEntries: List>> val files = entries.asSequence() .onEach { check(!it.startsWith(pluginDir) || pluginDir.relativize(it).nameCount == 2) { - "plugin entry is not specified correctly: ${it}" + "plugin entry is not specified correctly: $it" } } .distinct() .toMutableList() if (files.size > 1) { - putMoreLikelyPluginJarsFirst(pluginDir.fileName.toString(), filesInLibUnderPluginDir = files) // always sort + // always sort + putMoreLikelyPluginJarsFirst(pluginDir.fileName.toString(), filesInLibUnderPluginDir = files) } // move dir with plugin.xml to top (it may not exist if for some reason the main module dir still being packed into JAR) diff --git a/platform/build-scripts/src/org/jetbrains/intellij/build/impl/DistributionJARsBuilder.kt b/platform/build-scripts/src/org/jetbrains/intellij/build/impl/DistributionJARsBuilder.kt index 555351df0939..0ecadc280071 100644 --- a/platform/build-scripts/src/org/jetbrains/intellij/build/impl/DistributionJARsBuilder.kt +++ b/platform/build-scripts/src/org/jetbrains/intellij/build/impl/DistributionJARsBuilder.kt @@ -180,7 +180,7 @@ private suspend fun buildBundledPluginsForAllPlatforms( val specific = specificDeferred.await() for ((supportedDist) in pluginDirs) { val specificList = specific.get(supportedDist) - val specificClasspath = specificList?.let { generatePluginClassPath(it, writeDescriptor = true) } + val specificClasspath = specificList?.let { generatePluginClassPath(pluginEntries = it, writeDescriptor = true) } val byteOut = ByteArrayOutputStream() val out = DataOutputStream(byteOut) diff --git a/platform/core-impl/src/com/intellij/ide/plugins/ClassLoaderConfigurator.kt b/platform/core-impl/src/com/intellij/ide/plugins/ClassLoaderConfigurator.kt index 97b970e0e6bc..28b2668ca0f3 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/ClassLoaderConfigurator.kt +++ b/platform/core-impl/src/com/intellij/ide/plugins/ClassLoaderConfigurator.kt @@ -212,11 +212,7 @@ class ClassLoaderConfigurator( } private fun getCoreUrlClassLoaderIfPossible(): UrlClassLoader? { - val coreUrlClassLoader = coreLoader as? UrlClassLoader - if (coreUrlClassLoader == null) { - return null - } - + val coreUrlClassLoader = coreLoader as? UrlClassLoader ?: return null if (coreUrlClassLoader.resolveScopeManager == null) { val corePlugin = pluginSet.enabledPlugins.first() assert(corePlugin.pluginId == PluginManagerCore.CORE_ID) @@ -365,7 +361,8 @@ fun createPluginDependencyAndContentBasedScope(descriptor: IdeaPluginDescriptorI return null } - }} + } +} private fun getContentPackagePrefixes(descriptor: IdeaPluginDescriptorImpl): List> { val modules = descriptor.content.modules diff --git a/platform/core-impl/src/com/intellij/ide/plugins/ClassPathXmlPathResolver.kt b/platform/core-impl/src/com/intellij/ide/plugins/ClassPathXmlPathResolver.kt index 3e4bd579e671..bad03f16a641 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/ClassPathXmlPathResolver.kt +++ b/platform/core-impl/src/com/intellij/ide/plugins/ClassPathXmlPathResolver.kt @@ -1,4 +1,4 @@ -// 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 com.intellij.ide.plugins import com.intellij.openapi.diagnostic.Logger @@ -6,15 +6,17 @@ import com.intellij.util.lang.UrlClassLoader import com.intellij.util.xml.dom.createNonCoalescingXmlStreamReader import org.codehaus.stax2.XMLStreamReader2 -internal class ClassPathXmlPathResolver(private val classLoader: ClassLoader, val isRunningFromSources: Boolean) : PathResolver { +internal class ClassPathXmlPathResolver(private val classLoader: ClassLoader, @JvmField val isRunningFromSources: Boolean) : PathResolver { override val isFlat: Boolean get() = true - override fun loadXIncludeReference(readInto: RawPluginDescriptor, - readContext: ReadModuleContext, - dataLoader: DataLoader, - base: String?, - relativePath: String): Boolean { + override fun loadXIncludeReference( + readInto: RawPluginDescriptor, + readContext: ReadModuleContext, + dataLoader: DataLoader, + base: String?, + relativePath: String, + ): Boolean { val path = PluginXmlPathResolver.toLoadPath(relativePath, base) val reader: XMLStreamReader2 if (classLoader is UrlClassLoader) { @@ -23,32 +25,38 @@ internal class ClassPathXmlPathResolver(private val classLoader: ClassLoader, va else { reader = createNonCoalescingXmlStreamReader(classLoader.getResourceAsStream(path) ?: return false, dataLoader.toString()) } - readModuleDescriptor(reader = reader, - readContext = readContext, - pathResolver = this, - dataLoader = dataLoader, - includeBase = PluginXmlPathResolver.getChildBase(base = base, relativePath = relativePath), - readInto = readInto) + readModuleDescriptor( + reader = reader, + readContext = readContext, + pathResolver = this, + dataLoader = dataLoader, + includeBase = PluginXmlPathResolver.getChildBase(base = base, relativePath = relativePath), + readInto = readInto, + ) return true } - override fun resolveModuleFile(readContext: ReadModuleContext, - dataLoader: DataLoader, - path: String, - readInto: RawPluginDescriptor?): RawPluginDescriptor { + override fun resolveModuleFile( + readContext: ReadModuleContext, + dataLoader: DataLoader, + path: String, + readInto: RawPluginDescriptor?, + ): RawPluginDescriptor { val resource: ByteArray? if (classLoader is UrlClassLoader) { resource = classLoader.getResourceAsBytes(path, true) } else { classLoader.getResourceAsStream(path)?.let { - return readModuleDescriptor(input = it, - readContext = readContext, - pathResolver = this, - dataLoader = dataLoader, - includeBase = null, - readInto = readInto, - locationSource = dataLoader.toString()) + return readModuleDescriptor( + input = it, + readContext = readContext, + pathResolver = this, + dataLoader = dataLoader, + includeBase = null, + readInto = readInto, + locationSource = dataLoader.toString(), + ) } resource = null } @@ -77,13 +85,15 @@ internal class ClassPathXmlPathResolver(private val classLoader: ClassLoader, va throw RuntimeException("Cannot resolve $path (dataLoader=$dataLoader, classLoader=$classLoader)") } - return readModuleDescriptor(input = resource, - readContext = readContext, - pathResolver = this, - dataLoader = dataLoader, - includeBase = null, - readInto = readInto, - locationSource = dataLoader.toString()) + return readModuleDescriptor( + input = resource, + readContext = readContext, + pathResolver = this, + dataLoader = dataLoader, + includeBase = null, + readInto = readInto, + locationSource = dataLoader.toString(), + ) } override fun resolvePath(readContext: ReadModuleContext, @@ -91,12 +101,14 @@ internal class ClassPathXmlPathResolver(private val classLoader: ClassLoader, va relativePath: String, readInto: RawPluginDescriptor?): RawPluginDescriptor? { val path = PluginXmlPathResolver.toLoadPath(relativePath, null) - return readModuleDescriptor(getXmlReader(classLoader, path, dataLoader) ?: return null, - readContext = readContext, - pathResolver = this, - dataLoader = dataLoader, - includeBase = null, - readInto = readInto) + return readModuleDescriptor( + getXmlReader(classLoader = classLoader, path = path, dataLoader = dataLoader) ?: return null, + readContext = readContext, + pathResolver = this, + dataLoader = dataLoader, + includeBase = null, + readInto = readInto, + ) } private fun getXmlReader(classLoader: ClassLoader, path: String, dataLoader: DataLoader): XMLStreamReader2? {