IJPL-148249 intellij.java.structuralSearch as a v2 module

GitOrigin-RevId: d540bab6fb28d6b8bee8df5697c3667211d20d50
This commit is contained in:
Vladimir Krivosheev
2024-04-15 18:52:29 +02:00
committed by intellij-monorepo-bot
parent b9b606a86e
commit a936474ee7
12 changed files with 137 additions and 74 deletions

View File

@@ -29,7 +29,10 @@
<xi:fallback/>
</xi:include>
<depends optional="true" config-file="intellij.java.structuralSearch.xml">com.intellij.modules.structuralsearch</depends>
<content>
<module name="intellij.java.structuralSearch"/>
</content>
<depends optional="true" config-file="intellij.java.remoteServers.impl.xml">com.intellij.modules.remoteServers</depends>
<depends optional="true" config-file="intellij.java.featuresTrainer.xml">training</depends>
<depends optional="true" config-file="intellij.java.performancePlugin.xml">com.jetbrains.performancePlugin</depends>

View File

@@ -1,4 +1,7 @@
<idea-plugin package="com.intellij.structuralsearch">
<idea-plugin>
<dependencies>
<plugin id="com.intellij.modules.structuralsearch"/>
</dependencies>
<extensions defaultExtensionNs="com.intellij">
<applicationService serviceInterface="com.intellij.structuralsearch.plugin.ui.StructuralSearchTemplateBuilder"

View File

@@ -78,7 +78,6 @@ object JavaPluginLayout {
"intellij.java.impl.refactorings",
"intellij.jsp.spi",
"intellij.java.uast",
"intellij.java.structuralSearch",
"intellij.java.typeMigration",
"intellij.java.featuresTrainer",
"intellij.java.performancePlugin"
@@ -107,7 +106,6 @@ object JavaPluginLayout {
}
}
/**
* A special plugin for JetBrains Client
*/

View File

@@ -302,10 +302,13 @@ class JarPackager private constructor(
continue
}
val descriptor = readXmlAsModel(context.findFileInModuleSources(moduleName, "$moduleName.xml")!!)
computeSourcesForModule(
item = ModuleItem(
moduleName = moduleName,
relativeOutputFile = layout.getMainJarName(),
// relative path with `/` is always packed by dev-mode, so, we don't need to fix resolving for now and can imporove it later
relativeOutputFile = if (descriptor.getAttributeValue("package") == null) "modules/$moduleName.jar" else layout.getMainJarName(),
reason = "<- ${layout.mainModule} (plugin content)",
),
moduleOutputPatcher = moduleOutputPatcher,

View File

@@ -0,0 +1,3 @@
[*]
# critical subsystem - named params used a lot
max_line_length = 180

View File

@@ -133,7 +133,7 @@ class ClassLoaderConfigurator(
configureDependenciesInOldFormat(module, mainDependentClassLoader)
}
else {
if (module.packagePrefix == null && module.pluginId != PluginManagerCore.CORE_ID) {
if (module.packagePrefix == null && module.pluginId != PluginManagerCore.CORE_ID && module.jarFiles == null) {
throw PluginException("Package is not specified (module=$module)", module.pluginId)
}
@@ -159,7 +159,8 @@ class ClassLoaderConfigurator(
}
else {
module.pluginClassLoader = PluginClassLoader(
classPath = mainInfo.classPath,
classPath = module.jarFiles?.let { ClassPath(it, DEFAULT_CLASSLOADER_CONFIGURATION, resourceFileFactory, false) }
?: mainInfo.classPath,
parents = dependencies,
pluginDescriptor = module,
coreLoader = coreLoader,
@@ -366,11 +367,22 @@ private fun getContentPackagePrefixes(descriptor: IdeaPluginDescriptorImpl): Lis
return emptyList()
}
val result = Array(modules.size) {
val module = modules.get(it).requireDescriptor()
"${module.packagePrefix ?: throw PluginException("Package is not specified (module=$module)", module.pluginId)}." to module.moduleName
val result = ArrayList<Pair<String, String?>>(modules.size)
for (item in modules) {
val module = item.requireDescriptor()
val packagePrefix = module.packagePrefix
if (packagePrefix == null) {
if (module.jarFiles.isNullOrEmpty()) {
// If jarFiles is not set for a module, the only way to separate it is by package prefix. Therefore, we require the package prefix.
throw PluginException("Package is not specified (module=$module)", module.pluginId)
}
else {
continue
}
}
result.add("$packagePrefix." to module.moduleName)
}
return result.asList()
return result
}
private fun getDependencyPackagePrefixes(descriptor: IdeaPluginDescriptorImpl, pluginSet: PluginSet): List<String> {

View File

@@ -65,12 +65,6 @@ internal class ClassPathXmlPathResolver(
}
if (resource == null) {
if (path == "intellij.profiler.clion") {
val descriptor = RawPluginDescriptor()
descriptor.`package` = "com.intellij.profiler.clion"
return descriptor
}
val log = logger<ClassPathXmlPathResolver>()
val moduleName = path.removeSuffix(".xml")
if (isRunningFromSources && path.startsWith("intellij.") && dataLoader.emptyDescriptorIfCannotResolve) {

View File

@@ -230,21 +230,11 @@ class IdeaPluginDescriptorImpl(
context: DescriptorListLoadingContext,
dataLoader: DataLoader,
) {
// include module file descriptor if not specified as `depends` (old way - xi:include)
// must be first because merged into raw descriptor
for (module in content.modules) {
val subDescriptorFile = module.configFile ?: "${module.name}.xml"
module.descriptor = createSub(
raw = pathResolver.resolveModuleFile(
readContext = context,
dataLoader = dataLoader,
path = subDescriptorFile,
readInto = null,
),
descriptorPath = subDescriptorFile,
context = context,
moduleName = module.name,
)
val subRaw = pathResolver.resolveModuleFile(readContext = context, dataLoader = dataLoader, path = subDescriptorFile, readInto = null)
val subDescriptor = createSub(raw = subRaw, descriptorPath = subDescriptorFile, context = context, moduleName = module.name)
module.descriptor = subDescriptor
}
initByRawDescriptor(raw = raw, context = context, pathResolver = pathResolver, dataLoader = dataLoader)

View File

@@ -792,23 +792,14 @@ private fun loadProductModule(
moduleRaw = RawPluginDescriptor().apply { `package` = "unresolved.$moduleName" }
}
else {
val resolver = pool.load(jarFile)
try {
val entry = resolver.loadZipEntry(subDescriptorFile)
?: throw IllegalStateException("Module descriptor $subDescriptorFile not found in $jarFile")
moduleRaw = readModuleDescriptor(
input = entry,
readContext = context,
pathResolver = pathResolver,
dataLoader = dataLoader,
includeBase = null,
readInto = null,
locationSource = jarFile.toString(),
)
}
finally {
(resolver as? Closeable)?.close()
}
moduleRaw = loadModuleFromSeparateJar(
pool = pool,
jarFile = jarFile,
subDescriptorFile = subDescriptorFile,
context = context,
pathResolver = pathResolver,
dataLoader = dataLoader,
)
}
}
else {
@@ -833,6 +824,33 @@ private fun loadProductModule(
return true
}
internal fun loadModuleFromSeparateJar(
pool: ZipFilePool,
jarFile: Path,
subDescriptorFile: String,
context: DescriptorListLoadingContext,
pathResolver: PathResolver,
dataLoader: DataLoader,
): RawPluginDescriptor {
val resolver = pool.load(jarFile)
try {
val entry = resolver.loadZipEntry(subDescriptorFile)
?: throw IllegalStateException("Module descriptor $subDescriptorFile not found in $jarFile")
return readModuleDescriptor(
input = entry,
readContext = context,
pathResolver = pathResolver,
dataLoader = dataLoader,
includeBase = null,
readInto = null,
locationSource = jarFile.toString(),
)
}
finally {
(resolver as? Closeable)?.close()
}
}
private fun collectPluginFilesInClassPath(loader: ClassLoader): Map<URL, String> {
val urlToFilename = LinkedHashMap<URL, String>()
try {
@@ -1048,31 +1066,25 @@ private fun loadDescriptorFromResource(
)
// it is very important to not set `useCoreClassLoader = true` blindly
// - product modules must use their own class loader if not running from sources
val descriptor = IdeaPluginDescriptorImpl(
raw = raw,
path = basePath,
isBundled = true,
id = null,
moduleName = null,
useCoreClassLoader = useCoreClassLoader,
)
val descriptor = IdeaPluginDescriptorImpl(raw = raw, path = basePath, isBundled = true, id = null, moduleName = null, useCoreClassLoader = useCoreClassLoader)
context.debugData?.recordDescriptorPath(descriptor = descriptor, rawPluginDescriptor = raw, path = filename)
if (libDir == null) {
descriptor.readExternal(raw = raw, pathResolver = pathResolver, context = context, dataLoader = dataLoader)
// do not set jarFiles by intention - doesn't make sense
for (module in descriptor.content.modules) {
val subDescriptorFile = module.configFile ?: "${module.name}.xml"
val subRaw = pathResolver.resolveModuleFile(readContext = context, dataLoader = dataLoader, path = subDescriptorFile, readInto = null)
val subDescriptor = descriptor.createSub(raw = subRaw, descriptorPath = subDescriptorFile, context = context, moduleName = module.name)
if (pathResolver.isRunningFromSources && subDescriptor.packagePrefix == null) {
// no package in run from sources - load module from main classpath
subDescriptor.jarFiles = Collections.emptyList()
}
module.descriptor = subDescriptor
}
}
else {
loadModuleDescriptors(
descriptor = descriptor,
pathResolver = pathResolver,
libDir = libDir,
pool = pool,
context = context,
dataLoader = dataLoader,
)
descriptor.initByRawDescriptor(raw = raw, context = context, pathResolver = pathResolver, dataLoader = dataLoader)
loadModuleDescriptors(descriptor = descriptor, pathResolver = pathResolver, libDir = libDir, pool = pool, context = context, dataLoader = dataLoader)
}
descriptor.initByRawDescriptor(raw = raw, context = context, pathResolver = pathResolver, dataLoader = dataLoader)
return descriptor
}
catch (e: CancellationException) {

View File

@@ -148,7 +148,7 @@ class PluginXmlPathResolver(private val pluginJarFiles: List<Path>, private val
throw RuntimeException("Cannot resolve $path (dataLoader=$dataLoader, pluginJarFiles=${pluginJarFiles.joinToString(separator = "\n ")})")
}
return readModuleDescriptor(
val descriptor = readModuleDescriptor(
input = input,
readContext = readContext,
pathResolver = this,
@@ -157,6 +157,7 @@ class PluginXmlPathResolver(private val pluginJarFiles: List<Path>, private val
readInto = readInto,
locationSource = null,
)
return descriptor
}
private fun findInJarFiles(

View File

@@ -92,7 +92,7 @@ private class PathBasedProductLoadingStrategy : ProductLoadingStrategy() {
/* This property returns hardcoded Strings instead of ProductMode, because currently ProductMode class isn't available in dependencies of
this module */
override val currentModeId: String
get() = if (AppMode.isRemoteDevHost()) "backend" else "local_IDE"
get() = if (AppMode.isRemoteDevHost()) "backend" else "local_IDE"
override fun addMainModuleGroupToClassPath(bootstrapClassLoader: ClassLoader) {
}
@@ -229,16 +229,60 @@ private class PathBasedProductLoadingStrategy : ProductLoadingStrategy() {
moduleName = null,
)
context.debugData?.recordDescriptorPath(descriptor, raw, PluginManagerCore.PLUGIN_XML_PATH)
descriptor.readExternal(raw = raw, pathResolver = pluginPathResolver, context = context, dataLoader = dataLoader)
for (module in descriptor.content.modules) {
val subDescriptorFile = module.configFile ?: "${module.name}.xml"
val input = dataLoader.load(subDescriptorFile, pluginDescriptorSourceOnly = true)
var classPath: List<Path>? = null
val subRaw = if (input == null) {
val jarFile = pluginDir.resolve("lib/modules/${module.name}.jar")
if (Files.exists(jarFile)) {
classPath = Collections.singletonList(jarFile)
loadModuleFromSeparateJar(
pool = zipFilePool,
jarFile = jarFile,
subDescriptorFile = subDescriptorFile,
context = context,
pathResolver = pluginPathResolver,
dataLoader = dataLoader,
)
}
else {
throw RuntimeException("Cannot resolve $subDescriptorFile (dataLoader=$dataLoader)")
}
}
else {
readModuleDescriptor(
input = input,
readContext = context,
pathResolver = pluginPathResolver,
dataLoader = dataLoader,
includeBase = null,
readInto = null,
locationSource = null,
)
}
val subDescriptor = descriptor.createSub(
raw = subRaw,
descriptorPath = subDescriptorFile,
context = context,
moduleName = module.name,
)
if (classPath != null) {
subDescriptor.jarFiles = classPath
}
module.descriptor = subDescriptor
}
descriptor.initByRawDescriptor(raw = raw, context = context, pathResolver = pluginPathResolver, dataLoader = dataLoader)
descriptor.jarFiles = fileItems.map { it.file }
return descriptor
}
override fun isOptionalProductModule(moduleName: String): Boolean = false
override fun findProductContentModuleClassesRoot(moduleName: String, moduleDir: Path): Path {
return moduleDir.resolve("$moduleName.jar")
}
}
override val shouldLoadDescriptorsFromCoreClassPath: Boolean
get() = true

View File

@@ -326,9 +326,9 @@ public class PluginManagerTest {
@Override
public @NotNull RawPluginDescriptor resolveModuleFile(@NotNull ReadModuleContext readContext,
@NotNull DataLoader dataLoader,
@NotNull String path,
@Nullable RawPluginDescriptor readInto) {
@NotNull DataLoader dataLoader,
@NotNull String path,
@Nullable RawPluginDescriptor readInto) {
if (autoGenerateModuleDescriptor.get() && path.startsWith("intellij.")) {
var element = moduleMap.get(path);
if (element != null) {