Skip to content

Commit

Permalink
add BuildServicesResolver.setBuildServices()
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladicek committed May 24, 2022
1 parent 85c41eb commit 92aa067
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

import java.util.Collections;
import java.util.Comparator;
import java.util.Objects;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.TreeSet;

final class BuildServicesResolver {
public final class BuildServicesResolver {
private static final Object lock = new Object();
private static volatile Set<BuildServices> discoveredBuildServices;
private static volatile BuildServices configuredBuildServices;
Expand Down Expand Up @@ -48,7 +49,7 @@ private static void discoverFactories() {
BuildServices.class, BuildServicesResolver.class.getClassLoader());

if (!loader.iterator().hasNext()) {
throw new IllegalStateException("Unable to locate AnnotationBuilderFactory implementation");
throw new IllegalStateException("Unable to locate BuildServices implementation");
}

try {
Expand All @@ -61,4 +62,12 @@ private static void discoverFactories() {

BuildServicesResolver.discoveredBuildServices = Collections.unmodifiableSet(factories);
}

/**
* This method should <em>not</em> be used by applications. It is only exposed for integrators
* with complex classloading architectures, where service loader lookup doesn't work out of the box.
*/
public static void setBuildServices(BuildServices instance) {
configuredBuildServices = Objects.requireNonNull(instance, "BuildServices instance must not be null");
}
}

0 comments on commit 92aa067

Please sign in to comment.