Add Java API for Zinc Ivy integration

* Adds a method to fetch the default implementation of the compiler
  provider.
* Adds a method to get a default `IvyConfiguration` from a small number
  of parameters.

The public API is implemented in Java to ensure binary compatibility no
matter what happens to the internal Scala implementations. It also makes
it easier for Java users to use the API and avoid importing MODULE$'s
and Scala generated class files.'
This commit is contained in:
jvican 2017-05-20 01:19:22 +02:00
parent d794ead617
commit c228ce8817
3 changed files with 82 additions and 2 deletions

View File

@ -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.
* <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).
* @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);
}
}

View File

@ -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)
}
}
/**

View File

@ -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] = {