mirror of https://github.com/sbt/sbt.git
Setup interface project for testing
This commit is contained in:
parent
43a299bc3f
commit
3c68c20030
|
|
@ -0,0 +1,45 @@
|
|||
package xsbt
|
||||
|
||||
import java.io.File
|
||||
import xsbti.Versions
|
||||
|
||||
/** A component manager provides access to the pieces of xsbt that are distributed as components.
|
||||
* There are two types of components. The first type is compiled subproject jars with their dependencies.
|
||||
* The second type is a subproject distributed as a source jar so that it can be compiled against a specific
|
||||
* version of Scala.
|
||||
*
|
||||
* The component manager provides services to install and retrieve components to the local repository.
|
||||
* This is used for source jars so that the compilation need not be repeated for other projects on the same
|
||||
* machine.
|
||||
*/
|
||||
class ComponentManager(baseDirectory: File, log: IvyLogger) extends NotNull
|
||||
{
|
||||
def location(id: String): File = new File(baseDirectory, id)
|
||||
def directory(id: String): File =
|
||||
{
|
||||
val dir = location(id)
|
||||
if(!dir.exists)
|
||||
update(id)
|
||||
dir
|
||||
}
|
||||
private def contents(dir: File): Seq[File] =
|
||||
{
|
||||
val fs = dir.listFiles
|
||||
if(fs == null) Nil else fs
|
||||
}
|
||||
def files(id: String): Iterable[File] =
|
||||
{
|
||||
val fs = contents(directory(id))
|
||||
if(!fs.isEmpty) fs else error("Could not find required component '" + id + "'")
|
||||
}
|
||||
def file(id: String): File =
|
||||
files(id).toList match {
|
||||
case x :: Nil => x
|
||||
case xs => error("Expected single file for component '" + id + "', found: " + xs.mkString(", "))
|
||||
}
|
||||
|
||||
def update(id: String): Unit =
|
||||
IvyActions.basicRetrieveLocal(sbtModuleID("manager"), Seq(sbtModuleID(id)), location(id), log)
|
||||
def sbtModuleID(id: String) = ModuleID("org.scala-tools.sbt", id, Versions.Sbt)
|
||||
def cache(id: String): Unit = IvyActions.basicPublishLocal(sbtModuleID(id), Nil, files(id), log)
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@ import plugins.repository.Resource
|
|||
import plugins.repository.url.URLResource
|
||||
|
||||
/** Subclasses the default Ivy file parser in order to provide access to protected methods.*/
|
||||
private object CustomXmlParser extends XmlModuleDescriptorParser with NotNull
|
||||
private[xsbt] object CustomXmlParser extends XmlModuleDescriptorParser with NotNull
|
||||
{
|
||||
import XmlModuleDescriptorParser.Parser
|
||||
class CustomParser(settings: IvySettings) extends Parser(CustomXmlParser, settings) with NotNull
|
||||
|
|
|
|||
|
|
@ -18,6 +18,30 @@ final class UpdateConfiguration(val retrieveDirectory: File, val outputPattern:
|
|||
|
||||
object IvyActions
|
||||
{
|
||||
def basicPublishLocal(moduleID: ModuleID, dependencies: Iterable[ModuleID], artifactFiles: Iterable[File], log: IvyLogger)
|
||||
{
|
||||
val artifacts = artifactFiles.map(Artifact.defaultArtifact)
|
||||
val (ivy, local) = basicLocalIvy(log)
|
||||
val module = new ivy.Module(ModuleConfiguration(moduleID, dependencies, artifacts))
|
||||
val srcArtifactPatterns = artifactFiles.map(_.getAbsolutePath)
|
||||
publish(module, local.name, srcArtifactPatterns, None, None)
|
||||
}
|
||||
def basicRetrieveLocal(moduleID: ModuleID, dependencies: Iterable[ModuleID], to: File, log: IvyLogger)
|
||||
{
|
||||
val (ivy, local) = basicLocalIvy(log)
|
||||
val module = new ivy.Module(ModuleConfiguration(moduleID, dependencies, Nil))
|
||||
val up = new UpdateConfiguration(to, defaultOutputPattern, false, true)
|
||||
update(module, up)
|
||||
}
|
||||
def defaultOutputPattern = "[artifact]-[revision](-[classifier]).[ext]"
|
||||
private def basicLocalIvy(log: IvyLogger) =
|
||||
{
|
||||
val local = Resolver.defaultLocal
|
||||
val paths = new IvyPaths(new File("."), None)
|
||||
val conf = new IvyConfiguration(paths, Seq(local), log)
|
||||
(new IvySbt(conf), local)
|
||||
}
|
||||
|
||||
/** Clears the Ivy cache, as configured by 'config'. */
|
||||
def cleanCache(ivy: IvySbt) = ivy.withIvy { _.getSettings.getRepositoryCacheManagers.foreach(_.clean()) }
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ final class ModuleConfiguration(val module: ModuleID, val dependencies: Iterable
|
|||
}
|
||||
object ModuleConfiguration
|
||||
{
|
||||
def apply(module: ModuleID, dependencies: Iterable[ModuleID], artifacts: Iterable[Artifact]) =
|
||||
new ModuleConfiguration(module, dependencies, NodeSeq.Empty, Nil, None, None, artifacts, false)
|
||||
def configurations(explicitConfigurations: Iterable[Configuration], defaultConfiguration: Option[Configuration]) =
|
||||
if(explicitConfigurations.isEmpty)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -311,15 +311,22 @@ object Artifact
|
|||
def apply(name: String, url: URL): Artifact =Artifact(name, extract(url, defaultType), extract(url, defaultExtension), None, Nil, Some(url))
|
||||
val defaultExtension = "jar"
|
||||
val defaultType = "jar"
|
||||
private[this] def extract(url: URL, default: String) =
|
||||
private[this] def extract(url: URL, default: String): String = extract(url.toString, default)
|
||||
private[this] def extract(name: String, default: String): String =
|
||||
{
|
||||
val s = url.toString
|
||||
val i = s.lastIndexOf('.')
|
||||
val i = name.lastIndexOf('.')
|
||||
if(i >= 0)
|
||||
s.substring(i+1)
|
||||
name.substring(i+1)
|
||||
else
|
||||
default
|
||||
}
|
||||
def defaultArtifact(file: File) =
|
||||
{
|
||||
val name = file.getName
|
||||
val i = name.lastIndexOf('.')
|
||||
val base = if(i >= 0) name.substring(0, i) else name
|
||||
Artifact(name, extract(name, defaultType), extract(name, defaultExtension), None, Nil, Some(file.toURI.toURL))
|
||||
}
|
||||
}
|
||||
/*
|
||||
object Credentials
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ package xsbt
|
|||
|
||||
import org.apache.ivy.util.{Message, MessageLogger}
|
||||
|
||||
trait IvyLogger
|
||||
trait IvyLogger extends NotNull
|
||||
{
|
||||
def info(msg: => String)
|
||||
def debug(msg: => String)
|
||||
|
|
|
|||
Loading…
Reference in New Issue