/** * Finds a {@code RepositoryResolver} that {@link #canHandle(URI) can handle} the given URI, or * throws an {@code IllegalArgumentException} if no such initializer can be found. * <p> * The lookup method uses the standard JAVA SPI (Service Provider Interface) mechanism, by which * all the {@code META-INF/services/org.locationtech.geogig.repository.RepositoryResolver} files * in the classpath will be scanned for fully qualified names of implementing classes. * * @param repoURI Repository location URI * @return A RepositoryResolver that can handle the supplied URI. * @throws IllegalArgumentException if no repository resolver is found capable of handling the * given URI */ public static RepositoryResolver lookup(URI repoURI) throws IllegalArgumentException { Preconditions.checkNotNull(repoURI, "Repository URI is null"); Iterator<RepositoryResolver> initializers = ServiceLoader.load(RepositoryResolver.class) .iterator(); while (initializers.hasNext()) { RepositoryResolver initializer = initializers.next(); final String resolverClassName = initializer.getClass().getName(); if (!DISABLED_RESOLVERS.contains(resolverClassName) && initializer.canHandle(repoURI)) { return initializer; } } throw new IllegalArgumentException( "No repository initializer found capable of handling this kind of URI: " + repoURI); }
/** * Finds a {@code RepositoryResolver} that {@link #canHandle(URI) can handle} the given URI, or * throws an {@code IllegalArgumentException} if no such initializer can be found. * <p> * The lookup method uses the standard JAVA SPI (Service Provider Interface) mechanism, by which * all the {@code META-INF/services/org.locationtech.geogig.repository.RepositoryResolver} files * in the classpath will be scanned for fully qualified names of implementing classes. * * @param repoURI Repository location URI * @return A RepositoryResolver that can handle the supplied URI. * @throws IllegalArgumentException if no repository resolver is found capable of handling the * given URI */ public static RepositoryResolver lookup(URI repoURI) throws IllegalArgumentException { Preconditions.checkNotNull(repoURI, "Repository URI is null"); List<RepositoryResolver> resolvers = lookupResolvers(); RepositoryResolver resolver = null; for (RepositoryResolver resolverImpl : resolvers) { final String resolverClassName = resolverImpl.getClass().getName(); if (!DISABLED_RESOLVERS.contains(resolverClassName) && resolverImpl.canHandle(repoURI)) { resolver = resolverImpl; break; } } Preconditions.checkArgument(resolver != null, "No repository initializer found capable of handling this kind of URI: %s", repoURI.getScheme()); return resolver; }