33
33
import org .elasticsearch .plugins .spi .SPIClassIterator ;
34
34
35
35
import java .io .IOException ;
36
- import java .io .UncheckedIOException ;
37
36
import java .lang .ModuleLayer .Controller ;
38
37
import java .lang .module .Configuration ;
39
38
import java .lang .module .ModuleFinder ;
@@ -99,6 +98,17 @@ record LoadedPlugin(PluginDescriptor descriptor, Plugin instance, ClassLoader lo
99
98
private static final Logger logger = LogManager .getLogger (PluginsService .class );
100
99
private static final DeprecationLogger deprecationLogger = DeprecationLogger .getLogger (PluginsService .class );
101
100
101
+ private static final Map <String , List <ModuleQualifiedExportsService >> exportsServices ;
102
+
103
+ static {
104
+ Map <String , List <ModuleQualifiedExportsService >> qualifiedExports = new HashMap <>();
105
+ var loader = ServiceLoader .load (ModuleQualifiedExportsService .class , PluginsService .class .getClassLoader ());
106
+ for (var exportsService : loader ) {
107
+ addExportsService (qualifiedExports , exportsService , exportsService .getClass ().getModule ().getName ());
108
+ }
109
+ exportsServices = Map .copyOf (qualifiedExports );
110
+ }
111
+
102
112
private final Settings settings ;
103
113
private final Path configPath ;
104
114
@@ -123,8 +133,7 @@ public PluginsService(Settings settings, Path configPath, Path modulesDirectory,
123
133
this .settings = settings ;
124
134
this .configPath = configPath ;
125
135
126
- Map <String , List <ModuleQualifiedExportsService >> qualifiedExports = new HashMap <>();
127
- loadExportsServices (qualifiedExports , PluginsService .class .getClassLoader ());
136
+ Map <String , List <ModuleQualifiedExportsService >> qualifiedExports = new HashMap <>(exportsServices );
128
137
addServerExportsService (qualifiedExports );
129
138
130
139
Set <PluginBundle > seenBundles = new LinkedHashSet <>();
@@ -202,12 +211,21 @@ static void checkMandatoryPlugins(Set<String> existingPlugins, Set<String> manda
202
211
}
203
212
}
204
213
214
+ private static final Set <String > officialPlugins ;
215
+
216
+ static {
217
+ try (var stream = PluginsService .class .getResourceAsStream ("/plugins.txt" )) {
218
+ officialPlugins = Streams .readAllLines (stream ).stream ().map (String ::trim ).collect (Collectors .toUnmodifiableSet ());
219
+ } catch (final IOException e ) {
220
+ throw new AssertionError (e );
221
+ }
222
+ }
223
+
205
224
private static List <PluginRuntimeInfo > getRuntimeInfos (
206
225
PluginIntrospector inspector ,
207
226
List <PluginDescriptor > pluginDescriptors ,
208
227
Map <String , LoadedPlugin > plugins
209
228
) {
210
- var officialPlugins = getOfficialPlugins ();
211
229
List <PluginRuntimeInfo > runtimeInfos = new ArrayList <>();
212
230
for (PluginDescriptor descriptor : pluginDescriptors ) {
213
231
LoadedPlugin plugin = plugins .get (descriptor .getName ());
@@ -223,14 +241,6 @@ private static List<PluginRuntimeInfo> getRuntimeInfos(
223
241
return runtimeInfos ;
224
242
}
225
243
226
- private static Set <String > getOfficialPlugins () {
227
- try (var stream = PluginsService .class .getResourceAsStream ("/plugins.txt" )) {
228
- return Streams .readAllLines (stream ).stream ().map (String ::trim ).collect (Sets .toUnmodifiableSortedSet ());
229
- } catch (final IOException e ) {
230
- throw new UncheckedIOException (e );
231
- }
232
- }
233
-
234
244
/**
235
245
* Map a function over all plugins
236
246
* @param function a function that takes a plugin and returns a result
@@ -788,13 +798,6 @@ private static void exposeQualifiedExportsAndOpens(Module target, Map<String, Li
788
798
qualifiedExports .getOrDefault (target .getName (), List .of ()).forEach (exportService -> exportService .addExportsAndOpens (target ));
789
799
}
790
800
791
- private static void loadExportsServices (Map <String , List <ModuleQualifiedExportsService >> qualifiedExports , ClassLoader classLoader ) {
792
- var loader = ServiceLoader .load (ModuleQualifiedExportsService .class , classLoader );
793
- for (var exportsService : loader ) {
794
- addExportsService (qualifiedExports , exportsService , exportsService .getClass ().getModule ().getName ());
795
- }
796
- }
797
-
798
801
private static void addExportsService (
799
802
Map <String , List <ModuleQualifiedExportsService >> qualifiedExports ,
800
803
ModuleQualifiedExportsService exportsService ,
0 commit comments