Skip to content

Commit

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

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 {
/**
* An internal helper to resolve {@link BuildServices} implementations.
* This class is public only for integrators and should <em>not</em> be used by applications.
*
* @since 4.0
*/
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 +55,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 +68,16 @@ 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.
* With this method, an integrator may manually provide an instance of {@link BuildServices} and
* this class will no longer attempt to look it up using service loader.
*
* @param instance a {@link BuildServices} instance that should be used, must not be {@code null}
*/
public static void setBuildServices(BuildServices instance) {
configuredBuildServices = Objects.requireNonNull(instance, "BuildServices instance must not be null");
}
}

0 comments on commit 0b7c10a

Please sign in to comment.