2009-08-16 20:29:08 +02:00
|
|
|
/* sbt -- Simple Build Tool
|
2010-02-08 05:45:19 +01:00
|
|
|
* Copyright 2008, 2009, 2010 Mark Harrah
|
2009-08-16 20:29:08 +02:00
|
|
|
*/
|
2010-01-16 01:05:23 +01:00
|
|
|
package sbt
|
2009-08-16 20:29:08 +02:00
|
|
|
|
|
|
|
|
import java.io.File
|
2010-04-24 03:20:07 +02:00
|
|
|
import scala.xml.{Node, NodeSeq}
|
2009-08-16 20:29:08 +02:00
|
|
|
|
|
|
|
|
final class IvyPaths(val baseDirectory: File, val cacheDirectory: Option[File]) extends NotNull
|
2010-01-30 02:31:07 +01:00
|
|
|
{
|
|
|
|
|
def withBase(newBaseDirectory: File) = new IvyPaths(newBaseDirectory, cacheDirectory)
|
|
|
|
|
}
|
2010-01-16 01:05:23 +01:00
|
|
|
sealed trait IvyConfiguration extends NotNull
|
|
|
|
|
{
|
2010-01-30 02:31:07 +01:00
|
|
|
type This <: IvyConfiguration
|
2010-01-29 01:31:04 +01:00
|
|
|
def lock: Option[xsbti.GlobalLock]
|
2010-01-16 01:05:23 +01:00
|
|
|
def baseDirectory: File
|
|
|
|
|
def log: IvyLogger
|
2010-01-30 02:31:07 +01:00
|
|
|
def withBase(newBaseDirectory: File): This
|
2010-01-16 01:05:23 +01:00
|
|
|
}
|
2010-03-04 06:07:12 +01:00
|
|
|
final class InlineIvyConfiguration(val paths: IvyPaths, val resolvers: Seq[Resolver], val otherResolvers: Seq[Resolver],
|
2010-01-29 01:31:04 +01:00
|
|
|
val moduleConfigurations: Seq[ModuleConfiguration], val lock: Option[xsbti.GlobalLock], val log: IvyLogger) extends IvyConfiguration
|
2010-01-16 01:05:23 +01:00
|
|
|
{
|
2010-01-30 02:31:07 +01:00
|
|
|
type This = InlineIvyConfiguration
|
2010-01-16 01:05:23 +01:00
|
|
|
def baseDirectory = paths.baseDirectory
|
2010-03-04 06:07:12 +01:00
|
|
|
def withBase(newBase: File) = new InlineIvyConfiguration(paths.withBase(newBase), resolvers, otherResolvers, moduleConfigurations, lock, log)
|
2010-01-16 01:05:23 +01:00
|
|
|
}
|
2010-01-29 01:31:04 +01:00
|
|
|
final class ExternalIvyConfiguration(val baseDirectory: File, val file: File, val lock: Option[xsbti.GlobalLock], val log: IvyLogger) extends IvyConfiguration
|
2010-01-30 02:31:07 +01:00
|
|
|
{
|
|
|
|
|
type This = ExternalIvyConfiguration
|
|
|
|
|
def withBase(newBase: File) = new ExternalIvyConfiguration(newBase, file, lock, log)
|
|
|
|
|
}
|
2010-01-16 01:05:23 +01:00
|
|
|
|
|
|
|
|
object IvyConfiguration
|
|
|
|
|
{
|
|
|
|
|
/** Called to configure Ivy when inline resolvers are not specified.
|
|
|
|
|
* This will configure Ivy with an 'ivy-settings.xml' file if there is one or else use default resolvers.*/
|
2010-01-29 01:31:04 +01:00
|
|
|
def apply(paths: IvyPaths, lock: Option[xsbti.GlobalLock], log: IvyLogger): IvyConfiguration =
|
2010-01-16 01:05:23 +01:00
|
|
|
{
|
|
|
|
|
log.debug("Autodetecting configuration.")
|
|
|
|
|
val defaultIvyConfigFile = IvySbt.defaultIvyConfiguration(paths.baseDirectory)
|
|
|
|
|
if(defaultIvyConfigFile.canRead)
|
2010-01-29 01:31:04 +01:00
|
|
|
new ExternalIvyConfiguration(paths.baseDirectory, defaultIvyConfigFile, lock, log)
|
2010-01-16 01:05:23 +01:00
|
|
|
else
|
2010-03-04 06:07:12 +01:00
|
|
|
new InlineIvyConfiguration(paths, Resolver.withDefaultResolvers(Nil), Nil, Nil, lock, log)
|
2010-01-16 01:05:23 +01:00
|
|
|
}
|
|
|
|
|
}
|
2009-08-16 20:29:08 +02:00
|
|
|
|
2009-09-27 20:39:26 +02:00
|
|
|
sealed trait ModuleSettings extends NotNull
|
2009-08-16 20:29:08 +02:00
|
|
|
{
|
2009-09-09 05:13:30 +02:00
|
|
|
def validate: Boolean
|
|
|
|
|
def ivyScala: Option[IvyScala]
|
2010-01-16 01:05:23 +01:00
|
|
|
def noScala: ModuleSettings
|
2009-08-16 20:29:08 +02:00
|
|
|
}
|
2009-09-27 20:39:26 +02:00
|
|
|
final class IvyFileConfiguration(val file: File, val ivyScala: Option[IvyScala], val validate: Boolean) extends ModuleSettings
|
2010-01-16 01:05:23 +01:00
|
|
|
{
|
|
|
|
|
def noScala = new IvyFileConfiguration(file, None, validate)
|
|
|
|
|
}
|
2009-09-27 20:39:26 +02:00
|
|
|
final class PomConfiguration(val file: File, val ivyScala: Option[IvyScala], val validate: Boolean) extends ModuleSettings
|
2010-01-16 01:05:23 +01:00
|
|
|
{
|
|
|
|
|
def noScala = new PomConfiguration(file, None, validate)
|
|
|
|
|
}
|
2009-09-09 05:13:30 +02:00
|
|
|
final class InlineConfiguration(val module: ModuleID, val dependencies: Iterable[ModuleID], val ivyXML: NodeSeq,
|
|
|
|
|
val configurations: Iterable[Configuration], val defaultConfiguration: Option[Configuration], val ivyScala: Option[IvyScala],
|
2010-01-16 01:05:23 +01:00
|
|
|
val validate: Boolean) extends ModuleSettings
|
|
|
|
|
{
|
|
|
|
|
def withConfigurations(configurations: Iterable[Configuration]) =
|
2010-03-28 20:19:43 +02:00
|
|
|
new InlineConfiguration(module, dependencies, ivyXML, configurations, defaultConfiguration, ivyScala, validate)
|
2010-01-16 01:05:23 +01:00
|
|
|
def noScala = new InlineConfiguration(module, dependencies, ivyXML, configurations, defaultConfiguration, None, validate)
|
|
|
|
|
}
|
2009-09-27 20:39:26 +02:00
|
|
|
final class EmptyConfiguration(val module: ModuleID, val ivyScala: Option[IvyScala], val validate: Boolean) extends ModuleSettings
|
2010-01-16 01:05:23 +01:00
|
|
|
{
|
|
|
|
|
def noScala = new EmptyConfiguration(module, None, validate)
|
|
|
|
|
}
|
2009-09-09 05:13:30 +02:00
|
|
|
object InlineConfiguration
|
2009-08-16 20:29:08 +02:00
|
|
|
{
|
2010-01-16 01:05:23 +01:00
|
|
|
def apply(module: ModuleID, dependencies: Iterable[ModuleID]) =
|
|
|
|
|
new InlineConfiguration(module, dependencies, NodeSeq.Empty, Nil, None, None, false)
|
2009-08-16 20:29:08 +02:00
|
|
|
def configurations(explicitConfigurations: Iterable[Configuration], defaultConfiguration: Option[Configuration]) =
|
|
|
|
|
if(explicitConfigurations.isEmpty)
|
|
|
|
|
{
|
|
|
|
|
defaultConfiguration match
|
|
|
|
|
{
|
|
|
|
|
case Some(Configurations.DefaultIvyConfiguration) => Configurations.Default :: Nil
|
|
|
|
|
case Some(Configurations.DefaultMavenConfiguration) => Configurations.defaultMavenConfigurations
|
|
|
|
|
case _ => Nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
explicitConfigurations
|
2009-09-09 05:13:30 +02:00
|
|
|
}
|
2009-09-27 20:39:26 +02:00
|
|
|
object ModuleSettings
|
2009-09-09 05:13:30 +02:00
|
|
|
{
|
|
|
|
|
def apply(ivyScala: Option[IvyScala], validate: Boolean, module: => ModuleID)(baseDirectory: File, log: IvyLogger) =
|
|
|
|
|
{
|
|
|
|
|
log.debug("Autodetecting dependencies.")
|
|
|
|
|
val defaultPOMFile = IvySbt.defaultPOM(baseDirectory)
|
|
|
|
|
if(defaultPOMFile.canRead)
|
|
|
|
|
new PomConfiguration(defaultPOMFile, ivyScala, validate)
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
val defaultIvy = IvySbt.defaultIvyFile(baseDirectory)
|
|
|
|
|
if(defaultIvy.canRead)
|
|
|
|
|
new IvyFileConfiguration(defaultIvy, ivyScala, validate)
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
log.warn("No dependency configuration found, using defaults.")
|
|
|
|
|
new EmptyConfiguration(module, ivyScala, validate)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-16 20:29:08 +02:00
|
|
|
}
|