IJPL-866 cleanup

GitOrigin-RevId: ff98899ebb964b2e8a4bd87989434452e4f18dc5
This commit is contained in:
Vladimir Krivosheev
2024-03-27 09:35:41 +00:00
committed by intellij-monorepo-bot
parent 4e4db04795
commit 710fbe6476
5 changed files with 66 additions and 60 deletions
@@ -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 {
@@ -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<String> {
spanBuilder("generate classpath")
.setAttribute("dir", homeDir.toString())
.useWithoutActiveScope { span ->
val files = computeAppClassPath(homeDir = homeDir, libDir = libDir)
val existing = HashSet<Path>()
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<Path> {
val existing = HashSet<Path>()
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<Path>, homeDir: Path): LinkedHashSet<Path> {
val result = LinkedHashSet<Path>(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<Pair<Path, List<Path>>>, writeDescriptor: Boolean): ByteArray {
@@ -210,13 +206,14 @@ fun generatePluginClassPathFromFiles(pluginEntries: List<Pair<Path, List<Path>>>
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)
@@ -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)
@@ -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<Pair<String, String?>> {
val modules = descriptor.content.modules
@@ -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? {