Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.elasticsearch.plugins.spi.SPIClassIterator;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.lang.ModuleLayer.Controller;
import java.lang.module.Configuration;
import java.lang.module.ModuleFinder;
Expand Down Expand Up @@ -99,6 +98,17 @@ record LoadedPlugin(PluginDescriptor descriptor, Plugin instance, ClassLoader lo
private static final Logger logger = LogManager.getLogger(PluginsService.class);
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(PluginsService.class);

private static final Map<String, List<ModuleQualifiedExportsService>> exportsServices;

static {
Map<String, List<ModuleQualifiedExportsService>> qualifiedExports = new HashMap<>();
var loader = ServiceLoader.load(ModuleQualifiedExportsService.class, PluginsService.class.getClassLoader());
for (var exportsService : loader) {
addExportsService(qualifiedExports, exportsService, exportsService.getClass().getModule().getName());
}
exportsServices = Map.copyOf(qualifiedExports);
}

private final Settings settings;
private final Path configPath;

Expand All @@ -123,8 +133,7 @@ public PluginsService(Settings settings, Path configPath, Path modulesDirectory,
this.settings = settings;
this.configPath = configPath;

Map<String, List<ModuleQualifiedExportsService>> qualifiedExports = new HashMap<>();
loadExportsServices(qualifiedExports, PluginsService.class.getClassLoader());
Map<String, List<ModuleQualifiedExportsService>> qualifiedExports = new HashMap<>(exportsServices);
addServerExportsService(qualifiedExports);

Set<PluginBundle> seenBundles = new LinkedHashSet<>();
Expand Down Expand Up @@ -202,12 +211,21 @@ static void checkMandatoryPlugins(Set<String> existingPlugins, Set<String> manda
}
}

private static final Set<String> officialPlugins;

static {
try (var stream = PluginsService.class.getResourceAsStream("/plugins.txt")) {
officialPlugins = Streams.readAllLines(stream).stream().map(String::trim).collect(Collectors.toUnmodifiableSet());
} catch (final IOException e) {
throw new AssertionError(e);
}
}

private static List<PluginRuntimeInfo> getRuntimeInfos(
PluginIntrospector inspector,
List<PluginDescriptor> pluginDescriptors,
Map<String, LoadedPlugin> plugins
) {
var officialPlugins = getOfficialPlugins();
List<PluginRuntimeInfo> runtimeInfos = new ArrayList<>();
for (PluginDescriptor descriptor : pluginDescriptors) {
LoadedPlugin plugin = plugins.get(descriptor.getName());
Expand All @@ -223,14 +241,6 @@ private static List<PluginRuntimeInfo> getRuntimeInfos(
return runtimeInfos;
}

private static Set<String> getOfficialPlugins() {
try (var stream = PluginsService.class.getResourceAsStream("/plugins.txt")) {
return Streams.readAllLines(stream).stream().map(String::trim).collect(Sets.toUnmodifiableSortedSet());
} catch (final IOException e) {
throw new UncheckedIOException(e);
}
}

/**
* Map a function over all plugins
* @param function a function that takes a plugin and returns a result
Expand Down Expand Up @@ -788,13 +798,6 @@ private static void exposeQualifiedExportsAndOpens(Module target, Map<String, Li
qualifiedExports.getOrDefault(target.getName(), List.of()).forEach(exportService -> exportService.addExportsAndOpens(target));
}

private static void loadExportsServices(Map<String, List<ModuleQualifiedExportsService>> qualifiedExports, ClassLoader classLoader) {
var loader = ServiceLoader.load(ModuleQualifiedExportsService.class, classLoader);
for (var exportsService : loader) {
addExportsService(qualifiedExports, exportsService, exportsService.getClass().getModule().getName());
}
}

private static void addExportsService(
Map<String, List<ModuleQualifiedExportsService>> qualifiedExports,
ModuleQualifiedExportsService exportsService,
Expand Down