mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
[runtime module repository] refactoring: extract utility methods to a separate class (IJPL-189949)
This is needed to reuse them for another implementation. GitOrigin-RevId: 6ca3357c80dc02e9cdf8aaaad0d97b84f8098ef4
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e08a0b3328
commit
1ad00d2a66
@@ -0,0 +1,33 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.platform.runtime.repository.serialization.impl;
|
||||
|
||||
import com.intellij.platform.runtime.repository.serialization.RawRuntimeModuleDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
final class CachedClasspathComputation {
|
||||
|
||||
static @NotNull Collection<String> computeClasspath(Collection<RawRuntimeModuleDescriptor> descriptors, String moduleName) {
|
||||
Set<String> classpath = new LinkedHashSet<>();
|
||||
Map<String, RawRuntimeModuleDescriptor> descriptorMap = new HashMap<>();
|
||||
for (RawRuntimeModuleDescriptor descriptor : descriptors) {
|
||||
descriptorMap.put(descriptor.getId(), descriptor);
|
||||
}
|
||||
collectClasspathEntries(moduleName, descriptorMap, new HashSet<>(), classpath);
|
||||
return classpath;
|
||||
}
|
||||
|
||||
private static void collectClasspathEntries(String moduleName,
|
||||
Map<String, RawRuntimeModuleDescriptor> descriptorMap,
|
||||
Set<String> processedModules,
|
||||
Set<String> classpath) {
|
||||
if (!processedModules.add(moduleName)) return;
|
||||
RawRuntimeModuleDescriptor descriptor = descriptorMap.get(moduleName);
|
||||
if (descriptor == null) return;
|
||||
classpath.addAll(descriptor.getResourcePaths());
|
||||
for (String dependency : descriptor.getDependencies()) {
|
||||
collectClasspathEntries(dependency, descriptorMap, processedModules, classpath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,7 +91,8 @@ public final class JarFileSerializer {
|
||||
attributes.put(Attributes.Name.IMPLEMENTATION_VERSION, SPECIFICATION_VERSION + "." + generatorVersion);
|
||||
if (bootstrapModuleName != null) {
|
||||
attributes.put(BOOTSTRAP_MODULE_ATTRIBUTE_NAME, bootstrapModuleName);
|
||||
attributes.put(BOOTSTRAP_CLASSPATH_ATTRIBUTE_NAME, computeClasspath(descriptors, bootstrapModuleName));
|
||||
Collection<String> bootstrapClasspath = CachedClasspathComputation.computeClasspath(descriptors, bootstrapModuleName);
|
||||
attributes.put(BOOTSTRAP_CLASSPATH_ATTRIBUTE_NAME, String.join(" ", bootstrapClasspath));
|
||||
}
|
||||
if (mainPluginModuleId != null) {
|
||||
attributes.put(MAIN_PLUGIN_MODULE_ATTRIBUTE_NAME, mainPluginModuleId);
|
||||
@@ -107,27 +108,4 @@ public final class JarFileSerializer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String computeClasspath(Collection<RawRuntimeModuleDescriptor> descriptors, String moduleName) {
|
||||
Set<String> classpath = new LinkedHashSet<>();
|
||||
Map<String, RawRuntimeModuleDescriptor> descriptorMap = new HashMap<>();
|
||||
for (RawRuntimeModuleDescriptor descriptor : descriptors) {
|
||||
descriptorMap.put(descriptor.getId(), descriptor);
|
||||
}
|
||||
collectClasspathEntries(moduleName, descriptorMap, new HashSet<String>(), classpath);
|
||||
return String.join(" ", classpath);
|
||||
}
|
||||
|
||||
private static void collectClasspathEntries(String moduleName,
|
||||
Map<String, RawRuntimeModuleDescriptor> descriptorMap,
|
||||
Set<String> processedModules,
|
||||
Set<String> classpath) {
|
||||
if (!processedModules.add(moduleName)) return;
|
||||
RawRuntimeModuleDescriptor descriptor = descriptorMap.get(moduleName);
|
||||
if (descriptor == null) return;
|
||||
classpath.addAll(descriptor.getResourcePaths());
|
||||
for (String dependency : descriptor.getDependencies()) {
|
||||
collectClasspathEntries(dependency, descriptorMap, processedModules, classpath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user