Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add system properties to bypass ServiceLoader mixin service discovery. #85

Merged
merged 1 commit into from
Apr 1, 2022
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
29 changes: 29 additions & 0 deletions src/main/java/org/spongepowered/asm/service/MixinService.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,21 @@ private MixinService() {
}

private void runBootServices() {
// bypass service loader if the mixin.bootstrapService system property yields the desired IMixinServiceBootstrap implementation directly
String serviceCls = System.getProperty("mixin.bootstrapService");

if (serviceCls != null) {
try {
IMixinServiceBootstrap bootService = (IMixinServiceBootstrap) Class.forName(serviceCls).getConstructor().newInstance();
bootService.bootstrap();
bootedServices.add(bootService.getServiceClassName());

return;
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}

this.bootstrapServiceLoader = ServiceLoader.<IMixinServiceBootstrap>load(IMixinServiceBootstrap.class, this.getClass().getClassLoader());
Iterator<IMixinServiceBootstrap> iter = this.bootstrapServiceLoader.iterator();
while (iter.hasNext()) {
Expand Down Expand Up @@ -200,6 +215,20 @@ private synchronized IMixinService getServiceInstance() {
}

private IMixinService initService() {
// bypass service loader if the mixin.service system property yields the desired IMixinService implementation directly
String serviceCls = System.getProperty("mixin.service"); // FIXME: there is overlap with bootedServices, may just use that directly?

if (serviceCls != null) {
try {
IMixinService service = (IMixinService) Class.forName(serviceCls).getConstructor().newInstance();
if (!service.isValid()) throw new RuntimeException("invalid service "+serviceCls+" configured via system property");

return service;
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}

this.serviceLoader = ServiceLoader.<IMixinService>load(IMixinService.class, this.getClass().getClassLoader());
Iterator<IMixinService> iter = this.serviceLoader.iterator();
List<String> badServices = new ArrayList<String>();
Expand Down