Add public method to get default component provider

Expose default component provider through a static method in
`ZincCompilerBridge`. This method is necessary to invoke the bridge.

Removes the previous global lock and component provider implementations
in `BridgeProviderSpecification`.
This commit is contained in:
jvican 2017-05-20 02:26:05 +02:00
parent 6d012abaf9
commit 4d0f06a2ee
3 changed files with 41 additions and 21 deletions

View File

@ -48,7 +48,7 @@ public final class ZincBridgeProvider {
}
/**
* Defines a global lock that does nothing but calling the callable to synchronize
* Returns a global lock that does nothing but calling the callable to synchronize
* across threads. The lock file is used to resolve and download dependencies via ivy.
* <p>
* This operation is necesary to invoke {@link ZincBridgeProvider#getProvider(File, GlobalLock, ComponentProvider, IvyConfiguration, Logger)}.
@ -59,6 +59,21 @@ public final class ZincBridgeProvider {
return ZincComponentCompiler$.MODULE$.getDefaultLock();
}
/**
* Returns a default component provider that retrieves and installs component managers
* (like the compiled bridge sources) under a given target directory.
* <p>
* This is the most simplistic implementation of a component provider. If you need more
* advanced feature, like management of component via proxies (for companies) or access to
* other servers, you need to implement your own component provider.
*
* @param componentsRoot The directory in which components will be installed and retrieved.
* @return A default component provider.
*/
public static ComponentProvider getDefaultComponentProvider(File componentsRoot) {
return ZincComponentCompiler$.MODULE$.getDefaultComponentProvider(componentsRoot);
}
/**
* Get a compiler bridge provider that allows the user to fetch Scala and a compiled bridge.
*

View File

@ -20,7 +20,7 @@ import sbt.internal.util.FullLogger
import sbt.librarymanagement._
import sbt.librarymanagement.syntax._
import sbt.util.{ InterfaceUtil, Logger }
import xsbti.GlobalLock
import xsbti.{ ComponentProvider, GlobalLock }
import xsbti.compile.CompilerBridgeProvider
private[sbt] object ZincComponentCompiler {
@ -151,6 +151,27 @@ private[sbt] object ZincComponentCompiler {
override def apply[T](file: File, callable: Callable[T]): T = callable.call()
}
/** Defines a default component provider that manages the component in a given directory. */
private final class DefaultComponentProvider(targetDir: File) extends ComponentProvider {
import sbt.io.syntax._
private val LockFile = targetDir / "lock"
override def lockFile(): File = LockFile
override def componentLocation(id: String): File = targetDir / id
override def component(componentID: String): Array[File] =
IO.listFiles(targetDir / componentID)
override def defineComponent(componentID: String, files: Array[File]): Unit =
files.foreach(f => IO.copyFile(f, targetDir / componentID / f.getName))
override def addToComponent(componentID: String, files: Array[File]): Boolean = {
defineComponent(componentID, files)
true
}
}
def getDefaultComponentProvider(targetDir: File): ComponentProvider = {
require(targetDir.isDirectory)
new DefaultComponentProvider(targetDir)
}
def getDefaultConfiguration(baseDirectory: File,
ivyHome: File,
resolvers0: Array[Resolver],

View File

@ -30,8 +30,10 @@ abstract class BridgeProviderSpecification extends BaseIvySpecification {
}
def getZincProvider(targetDir: File, log: Logger): CompilerBridgeProvider = {
val lock = ZincComponentCompiler.getDefaultLock
val secondaryCache = Some(secondaryCacheDirectory)
val manager = new ZincComponentManager(lock, compProvider(targetDir), secondaryCache, log)
val componentProvider = ZincComponentCompiler.getDefaultComponentProvider(targetDir)
val manager = new ZincComponentManager(lock, componentProvider, secondaryCache, log)
ZincComponentCompiler.interfaceProvider(manager, ivyConfiguration, currentManaged)
}
@ -50,22 +52,4 @@ abstract class BridgeProviderSpecification extends BaseIvySpecification {
val provider = getZincProvider(targetDir, logger)
provider.getScalaInstance(scalaVersion, logger)
}
private val lock: GlobalLock = new GlobalLock {
override def apply[T](file: File, callable: Callable[T]): T = callable.call()
}
private def compProvider(targetDir: File): ComponentProvider = new ComponentProvider {
override def lockFile(): File = targetDir / "lock"
override def componentLocation(id: String): File =
throw new UnsupportedOperationException
override def component(componentID: String): Array[File] =
IO.listFiles(targetDir / componentID)
override def defineComponent(componentID: String, files: Array[File]): Unit =
files.foreach(f => IO.copyFile(f, targetDir / componentID / f.getName))
override def addToComponent(componentID: String, files: Array[File]): Boolean = {
defineComponent(componentID, files)
true
}
}
}