diff --git a/internal/zinc-ivy-integration/src/main/java/sbt/inc/ZincBridgeProvider.java b/internal/zinc-ivy-integration/src/main/java/sbt/inc/ZincBridgeProvider.java new file mode 100644 index 000000000..60a9920e8 --- /dev/null +++ b/internal/zinc-ivy-integration/src/main/java/sbt/inc/ZincBridgeProvider.java @@ -0,0 +1,53 @@ +package sbt.inc; + +import sbt.internal.inc.ZincComponentCompiler$; +import sbt.internal.inc.ZincComponentManager; +import sbt.internal.librarymanagement.IvyConfiguration; +import sbt.librarymanagement.Resolver; +import scala.None$; +import xsbti.ComponentProvider; +import xsbti.GlobalLock; +import xsbti.Logger; +import xsbti.compile.CompilerBridgeProvider; + +import java.io.File; + +public final class ZincBridgeProvider { + /** + * Get the default ivy configuration to retrieve compiler components. + *

+ * This method is useful to invoke {@link ZincBridgeProvider#getProvider(File, GlobalLock, ComponentProvider, IvyConfiguration, Logger)}. + *

+ * In order to know which arguments to pass, reading the + * ivy main concepts + * 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). + * @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); + } +} diff --git a/internal/zinc-ivy-integration/src/main/scala/sbt/internal/inc/ZincComponentCompiler.scala b/internal/zinc-ivy-integration/src/main/scala/sbt/internal/inc/ZincComponentCompiler.scala index 00dd2519b..20f91b5ba 100644 --- a/internal/zinc-ivy-integration/src/main/scala/sbt/internal/inc/ZincComponentCompiler.scala +++ b/internal/zinc-ivy-integration/src/main/scala/sbt/internal/inc/ZincComponentCompiler.scala @@ -137,6 +137,31 @@ private[sbt] object ZincComponentCompiler { scalaJarsTarget: File): CompilerBridgeProvider = new ZincCompilerBridgeProvider(manager, ivyConfiguration, scalaJarsTarget) + def getDefaultConfiguration(baseDirectory: File, + ivyHome: File, + resolvers0: Array[Resolver], + log: xsbti.Logger): IvyConfiguration = { + import sbt.io.syntax._ + val empty = Vector.empty + val checksums = empty + val otherResolvers = empty + val resolvers = resolvers0.toVector + val updateOptions = UpdateOptions() + val paths = IvyPaths(baseDirectory, Some(ivyHome)) + val resolutionCache = Some(ivyHome / "resolution-cache") + val chainResolver = ChainedResolver("zinc-chain", resolvers) + val moduleConfs = Vector(ModuleConfiguration("*", chainResolver)) + new InlineIvyConfiguration(paths, + resolvers, + otherResolvers, + moduleConfs, + false, + None, + checksums, + resolutionCache, + updateOptions, + log) + } } /** diff --git a/internal/zinc-ivy-integration/src/main/scala/sbt/internal/inc/ZincComponentManager.scala b/internal/zinc-ivy-integration/src/main/scala/sbt/internal/inc/ZincComponentManager.scala index 5af4baa6e..0db0011a3 100644 --- a/internal/zinc-ivy-integration/src/main/scala/sbt/internal/inc/ZincComponentManager.scala +++ b/internal/zinc-ivy-integration/src/main/scala/sbt/internal/inc/ZincComponentManager.scala @@ -11,7 +11,8 @@ package inc import java.io.File import java.util.concurrent.Callable -import sbt.util.Logger + +import sbt.internal.util.FullLogger import sbt.io.IO /** @@ -26,7 +27,8 @@ import sbt.io.IO class ZincComponentManager(globalLock: xsbti.GlobalLock, provider: xsbti.ComponentProvider, secondaryCacheDir: Option[File], - val log: Logger) { + log0: xsbti.Logger) { + val log = new FullLogger(log0) /** Get all of the files for component 'id', throwing an exception if no files exist for the component. */ def files(id: String)(ifMissing: IfMissing): Iterable[File] = {