Skip to content

Commit 58f34ed

Browse files
authored
Revert "Use alternative to ServiceLoader to load Plugin and PropertyRequiresPlugin"
1 parent 290f5e6 commit 58f34ed

File tree

1 file changed

+2
-32
lines changed

1 file changed

+2
-32
lines changed

inject/src/main/java/io/avaje/inject/DBeanScopeBuilder.java

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@
77
import io.avaje.lang.Nullable;
88
import jakarta.inject.Provider;
99

10-
import java.io.*;
1110
import java.lang.reflect.Type;
12-
import java.net.URL;
1311
import java.util.*;
1412
import java.util.function.Consumer;
1513
import java.util.function.Supplier;
16-
import java.util.stream.Collectors;
17-
import java.util.stream.Stream;
1814

1915
import static java.lang.System.Logger.Level.DEBUG;
2016

@@ -191,7 +187,7 @@ private void initClassLoader() {
191187

192188
private void initPropertyPlugin() {
193189
propertyRequiresPlugin =
194-
serviceLoad(PropertyRequiresPlugin.class)
190+
ServiceLoader.load(PropertyRequiresPlugin.class, classLoader)
195191
.findFirst()
196192
.orElse(defaultPropertyPlugin());
197193
}
@@ -218,7 +214,7 @@ public BeanScope build() {
218214
initPropertyPlugin();
219215
}
220216

221-
serviceLoad(Plugin.class).forEach(plugin -> plugin.apply(this));
217+
ServiceLoader.load(Plugin.class, classLoader).forEach(plugin -> plugin.apply(this));
222218
// sort factories by dependsOn
223219
FactoryOrder factoryOrder = new FactoryOrder(parent, includeModules, !suppliedBeans.isEmpty());
224220
if (factoryOrder.isEmpty()) {
@@ -245,32 +241,6 @@ public BeanScope build() {
245241
return builder.build(shutdownHook, start);
246242
}
247243

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-
274244
/**
275245
* Return the type that we map the supplied bean to.
276246
*/

0 commit comments

Comments
 (0)