7
7
import io .avaje .lang .Nullable ;
8
8
import jakarta .inject .Provider ;
9
9
10
- import java .io .*;
11
10
import java .lang .reflect .Type ;
12
- import java .net .URL ;
13
11
import java .util .*;
14
12
import java .util .function .Consumer ;
15
13
import java .util .function .Supplier ;
16
- import java .util .stream .Collectors ;
17
- import java .util .stream .Stream ;
18
14
19
15
import static java .lang .System .Logger .Level .DEBUG ;
20
16
@@ -191,7 +187,7 @@ private void initClassLoader() {
191
187
192
188
private void initPropertyPlugin () {
193
189
propertyRequiresPlugin =
194
- serviceLoad (PropertyRequiresPlugin .class )
190
+ ServiceLoader . load (PropertyRequiresPlugin .class , classLoader )
195
191
.findFirst ()
196
192
.orElse (defaultPropertyPlugin ());
197
193
}
@@ -218,7 +214,7 @@ public BeanScope build() {
218
214
initPropertyPlugin ();
219
215
}
220
216
221
- serviceLoad (Plugin .class ).forEach (plugin -> plugin .apply (this ));
217
+ ServiceLoader . load (Plugin .class , classLoader ).forEach (plugin -> plugin .apply (this ));
222
218
// sort factories by dependsOn
223
219
FactoryOrder factoryOrder = new FactoryOrder (parent , includeModules , !suppliedBeans .isEmpty ());
224
220
if (factoryOrder .isEmpty ()) {
@@ -245,32 +241,6 @@ public BeanScope build() {
245
241
return builder .build (shutdownHook , start );
246
242
}
247
243
248
- private <P > Stream <P > serviceLoad (Class <P > pluginClass ) {
249
- return classLoader
250
- .resources ("META-INF/services/" + pluginClass .getCanonicalName ())
251
- .flatMap (this ::resourceLines )
252
- .map (this ::serviceInstance );
253
- }
254
-
255
- @ SuppressWarnings ("unchecked" )
256
- private <P > P serviceInstance (String className ) {
257
- try {
258
- final var clazz = classLoader .loadClass (className );
259
- return (P ) clazz .getDeclaredConstructor ().newInstance ();
260
- } catch (Throwable e ) {
261
- throw new RuntimeException (e );
262
- }
263
- }
264
-
265
- private Stream <String > resourceLines (URL url ) {
266
- try (InputStream is = url .openStream ()) {
267
- final var reader = new LineNumberReader (new InputStreamReader (is ));
268
- return reader .lines ().collect (Collectors .toList ()).stream ();
269
- } catch (IOException e ) {
270
- throw new UncheckedIOException (e );
271
- }
272
- }
273
-
274
244
/**
275
245
* Return the type that we map the supplied bean to.
276
246
*/
0 commit comments