package sbt.inc;

import sbt.internal.inc.ZincComponentCompiler$;
import sbt.internal.inc.ZincComponentManager;
import sbt.internal.librarymanagement.IvyConfiguration;
import sbt.librarymanagement.Resolver;
import sbt.librarymanagement.ResolversSyntax;
import scala.None$;
import xsbti.ComponentProvider;
import xsbti.GlobalLock;
import xsbti.Logger;
import xsbti.compile.CompilerBridgeProvider;

import java.io.File;

public final class ZincBridgeProvider {
    /**
     * Returns an ivy resolver to resolve dependencies locally in the default `.ivy2/local`.
     * <p>
     * For those users interested in using Internet resolvers like Maven Central, you can
     * instantiate them via {@link ResolversSyntax#DefaultMavenRepository()} et al.
     *
     * @return A local ivy resolver.
     */
    public static Resolver getLocalResolver() {
        return ZincComponentCompiler$.MODULE$.LocalResolver();
    }

    /**
     * Get the default ivy configuration to retrieve compiler components.
     * <p>
     * This method is useful to invoke {@link ZincBridgeProvider#getProvider(File, GlobalLock, ComponentProvider, IvyConfiguration, Logger)}.
     * <p>
     * In order to know which arguments to pass, reading the
     * <a href="http://ant.apache.org/ivy/history/latest-milestone/concept.html">ivy main concepts</a>
     * may be useful.
     *
     * @param baseDirectory The base directory for ivy.
     * @param ivyHome       The home for ivy.
     * @param resolvers     The resolvers to be used (usually local and Maven).
     *                      See {@link ZincBridgeProvider#getProvider(File, GlobalLock, ComponentProvider, IvyConfiguration, Logger)}
     *                      and {@link ResolversSyntax}.
     * @return A default ivy configuration ready for fetching Zinc compiler components.
     */
    public static IvyConfiguration getDefaultConfiguration(File baseDirectory, File ivyHome, Resolver[] resolvers, Logger logger) {
        return ZincComponentCompiler$.MODULE$.getDefaultConfiguration(baseDirectory, ivyHome, resolvers, logger);
    }

    /**
     * Get a compiler bridge provider that allows the user to fetch Scala and a compiled bridge.
     *
     * @param scalaJarsTarget   The place where the downloaded Scala jars should be placed.
     * @param lock              The lock file used internally by Ivy to synchronize the dependency resolution.
     * @param componentProvider A provider capable of retrieving existing components or installing
     *                          new ones. The component provider manages compiled bridge sources.
     * @param ivyConfiguration  The ivy configuration used internally by the provider.
     * @param logger            The logger.
     * @return A compiler bridge provider capable of fetching scala jars and the compiler bridge.
     */
    public static CompilerBridgeProvider getProvider(File scalaJarsTarget,
                                                     GlobalLock lock,
                                                     ComponentProvider componentProvider,
                                                     IvyConfiguration ivyConfiguration,
                                                     Logger logger) {
        ZincComponentManager manager = new ZincComponentManager(lock, componentProvider, None$.empty(), logger);
        return ZincComponentCompiler$.MODULE$.interfaceProvider(manager, ivyConfiguration, scalaJarsTarget);
    }
}

@@ -410,16 +410,54 @@
 io.File;
+%0Aimport java.util.concurrent.Callable;
 %0A%0Apublic
@@ -2099,32 +2099,1440 @@
 logger);%0A    %7D%0A%0A
+    /**%0A     * Cast a CheckedException as an unchecked one.%0A     *%0A     * @param throwable to cast%0A     * @param %3CT%3E       the type of the Throwable%0A     * @return this method will never return a Throwable instance, it will just throw it.%0A     * @throws T the throwable as an unchecked throwable%0A     */%0A    @SuppressWarnings(%22unchecked%22)%0A    private static %3CT extends Throwable%3E RuntimeException rethrow(Throwable throwable) throws T %7B%0A        throw (T) throwable; // rely on vacuous cast%0A    %7D%0A%0A%0A    /**%0A     * Defines a global lock that does nothing but calling the callable to synchronize%0A     * across threads. The lock file is used to resolve and download dependencies via ivy.%0A     * %3Cp%3E%0A     * This operation is necesary to invoke %7B@link ZincBridgeProvider#getProvider(File, GlobalLock, ComponentProvider, IvyConfiguration, Logger)%7D.%0A     *%0A     * @return A default global lock.%0A     */%0A    public static GlobalLock getDefaultLock() %7B%0A        return new GlobalLock() %7B%0A            @Override%0A            public %3CT%3E T apply(File lockFile, Callable%3CT%3E run) %7B%0A                T value = null;%0A                try %7B%0A                    value = run.call();%0A                %7D catch (Exception e) %7B%0A                    // Rethrow runtime exception because apply does not define throwing Exception%0A                    rethrow(e);%0A                %7D%0A                return value;%0A            %7D%0A        %7D;%0A    %7D%0A%0A
     /**%0A     * G

Add public method to get no-op global lock