IJPL-149476 do not use plugin directory name - it is an implementation detail, workaround for bad CWM plugin layout

GitOrigin-RevId: 6265943857e89aa48d18ed99331ef3625a8fbbdc
This commit is contained in:
Vladimir Krivosheev
2024-05-12 08:59:21 +02:00
committed by intellij-monorepo-bot
parent 9fed1bb028
commit 2d9faf0dab
5 changed files with 27 additions and 35 deletions

View File

@@ -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 org.jetbrains.intellij.build
import org.jetbrains.intellij.build.impl.ModuleItem
@@ -21,7 +21,7 @@ interface ScrambleTool {
*/
suspend fun scramble(platform: PlatformLayout, context: BuildContext)
suspend fun scramblePlugin(context: BuildContext, pluginLayout: PluginLayout, targetDir: Path, additionalPluginsDir: Path)
suspend fun scramblePlugin(pluginLayout: PluginLayout, targetDir: Path, additionalPluginDir: Path, layouts: Collection<PluginLayout>, context: BuildContext)
/**
* Returns list of module names which cannot be included in the product without scrambling.

View File

@@ -65,7 +65,8 @@ internal suspend fun computeModuleSourcesByContent(
) {
for (moduleName in helper.readPluginContentFromDescriptor(context.findRequiredModule(layout.mainModule), jarPackager.moduleOutputPatcher)) {
// todo PyCharm team why this module is being incorrectly published
if (layout.mainModule == "intellij.pycharm.ds.remoteInterpreter" || !addedModules.add(moduleName)) {
// CWM plugin is overcomplicated without any valid reason - it must be refactored
if ((layout.mainModule == "intellij.pycharm.ds.remoteInterpreter" || moduleName == "intellij.cwm.plugin.driver") || !addedModules.add(moduleName)) {
continue
}

View File

@@ -922,7 +922,6 @@ private fun checkProductLayout(context: BuildContext) {
val messages = context.messages
val pluginLayouts = layout.pluginLayouts
checkScrambleClasspathPlugins(pluginLayouts)
checkPluginDuplicates(pluginLayouts)
checkPluginModules(layout.bundledPluginModules, "productProperties.productLayout.bundledPluginModules", context)
checkPluginModules(layout.pluginModulesToPublish, "productProperties.productLayout.pluginModulesToPublish", context)
@@ -1044,18 +1043,6 @@ private fun checkArtifacts(names: Collection<String>, fieldName: String, context
}
}
private fun checkScrambleClasspathPlugins(pluginLayoutList: List<PluginLayout>) {
val pluginDirectories = pluginLayoutList.mapTo(HashSet()) { it.directoryName }
for (pluginLayout in pluginLayoutList) {
for ((pluginDirectoryName, _) in pluginLayout.scrambleClasspathPlugins) {
check(pluginDirectories.contains(pluginDirectoryName)) {
"Layout of plugin '${pluginLayout.mainModule}' declares an unresolved plugin directory name" +
" in ${pluginLayout.scrambleClasspathPlugins}: $pluginDirectoryName"
}
}
}
}
private fun checkPluginModules(pluginModules: Collection<String>?, fieldName: String, context: BuildContext) {
if (pluginModules == null) {
return

View File

@@ -649,10 +649,11 @@ internal suspend fun buildPlugins(
for (scrambleTask in scrambleTasks) {
launch {
scrambleTool.scramblePlugin(
context = context,
pluginLayout = scrambleTask.plugin,
targetDir = scrambleTask.pluginDir,
additionalPluginsDir = scrambleTask.targetDir,
additionalPluginDir = scrambleTask.targetDir,
layouts = plugins,
context = context,
)
}
}
@@ -1331,11 +1332,11 @@ private fun buildBlockMap(file: Path, json: JSON) {
}
}
suspend fun createIdeClassPath(platform: PlatformLayout, context: BuildContext): Set<String> {
suspend fun createIdeClassPath(platform: PlatformLayout, context: BuildContext): Collection<String> {
val (lib, plugins) = generateProjectStructureMapping(context = context, platformLayout = platform)
val pluginLayouts = context.productProperties.productLayout.pluginLayouts
val classPath = LinkedHashSet<String>()
val classPath = LinkedHashSet<Path>()
val libDir = context.paths.distAllDir.resolve("lib")
for (entry in lib) {
@@ -1348,9 +1349,9 @@ suspend fun createIdeClassPath(platform: PlatformLayout, context: BuildContext):
when (entry) {
is ModuleOutputEntry -> {
classPath.add(context.getModuleOutputDir(context.findRequiredModule(entry.moduleName)).toString())
classPath.add(context.getModuleOutputDir(context.findRequiredModule(entry.moduleName)))
}
is LibraryFileEntry -> classPath.add(entry.libraryFile.toString())
is LibraryFileEntry -> classPath.add(entry.libraryFile!!)
else -> throw UnsupportedOperationException("Entry $entry is not supported")
}
}
@@ -1365,17 +1366,14 @@ suspend fun createIdeClassPath(platform: PlatformLayout, context: BuildContext):
when (entry) {
is ModuleOutputEntry -> {
classPath.add(context.getModuleOutputDir(context.findRequiredModule(entry.moduleName)).toString())
(pluginLayouts.firstOrNull { it.mainModule == entry.moduleName } ?: continue)
.scrambleClasspathPlugins
.asSequence()
.map { it.first }
.map { directoryName -> pluginLayouts.single { it.directoryName == directoryName } }
.mapTo(classPath) { context.getModuleOutputDir(context.findRequiredModule(it.mainModule)).toString() }
classPath.add(context.getModuleOutputDir(context.findRequiredModule(entry.moduleName)))
for (classpathPluginEntry in pluginLayouts.firstOrNull { it.mainModule == entry.moduleName }?.scrambleClasspathPlugins ?: emptyList()) {
context.getModuleOutputDir(context.findRequiredModule(classpathPluginEntry.pluginMainModuleName)).toString()
}
}
is LibraryFileEntry -> classPath.add(entry.libraryFile.toString())
is LibraryFileEntry -> classPath.add(entry.libraryFile!!)
else -> throw UnsupportedOperationException("Entry $entry is not supported")
}
}
return classPath
return classPath.map { it.toString() }
}

View File

@@ -59,7 +59,9 @@ class PluginLayout private constructor(
var scrambleSkipStatements: PersistentList<Pair<String, String>> = persistentListOf()
private set
var scrambleClasspathPlugins: PersistentList<Pair<String /*plugin directory name*/, String /*relative path*/>> = persistentListOf()
data class ScrambleClasspathPluginEntry(@JvmField val pluginMainModuleName: String, @JvmField val relativePath: String?)
var scrambleClasspathPlugins: PersistentList<ScrambleClasspathPluginEntry> = persistentListOf()
private set
var scrambleClasspathFilter: (BuildContext, Path) -> Boolean = { _, _ -> true }
@@ -374,11 +376,15 @@ class PluginLayout private constructor(
* If scramble tool is not defined, scrambling will not be performed
* Multiple invocations of this method will add corresponding plugin names to a list of name to be added to scramble classpath
*
* @param pluginDirectoryName - a name of the dependent plugin's directory, whose jars should be added to scramble classpath
* @param pluginMainModuleName - a name of the dependent plugin's directory, whose jars should be added to scramble classpath
* @param relativePath - a directory where jars should be searched (relative to plugin home directory, "lib" by default)
*/
fun scrambleClasspathPlugin(pluginDirectoryName: String, relativePath: String = "lib") {
layout.scrambleClasspathPlugins = layout.scrambleClasspathPlugins.add(Pair(pluginDirectoryName, relativePath))
fun scrambleClasspathPlugin(pluginMainModuleName: String) {
layout.scrambleClasspathPlugins = layout.scrambleClasspathPlugins.add(ScrambleClasspathPluginEntry(pluginMainModuleName = pluginMainModuleName, relativePath = null))
}
fun scrambleClasspathPlugin(pluginId: String, relativePath: String) {
layout.scrambleClasspathPlugins = layout.scrambleClasspathPlugins.add(ScrambleClasspathPluginEntry(pluginMainModuleName = pluginId, relativePath = relativePath))
}
/**