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
|
|
|
|
2011-04-14 01:01:22 +02:00
|
|
|
final class IvyPaths(val baseDirectory: File, val ivyHome: Option[File])
|
2010-01-30 02:31:07 +01:00
|
|
|
{
|
2011-04-14 01:01:22 +02:00
|
|
|
def withBase(newBaseDirectory: File) = new IvyPaths(newBaseDirectory, ivyHome)
|
2010-01-30 02:31:07 +01:00
|
|
|
}
|
2010-10-26 23:59:24 +02:00
|
|
|
sealed trait IvyConfiguration
|
2010-01-16 01:05:23 +01:00
|
|
|
{
|
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
|
2010-09-04 14:19:58 +02:00
|
|
|
def log: Logger
|
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-05-03 01:15:01 +02:00
|
|
|
val moduleConfigurations: Seq[ModuleConfiguration], val localOnly: Boolean, val lock: Option[xsbti.GlobalLock],
|
2010-09-04 14:19:58 +02:00
|
|
|
val log: Logger) 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-05-03 01:15:01 +02:00
|
|
|
def withBase(newBase: File) = new InlineIvyConfiguration(paths.withBase(newBase), resolvers, otherResolvers, moduleConfigurations, localOnly, lock, log)
|
|
|
|
|
def changeResolvers(newResolvers: Seq[Resolver]) = new InlineIvyConfiguration(paths, newResolvers, otherResolvers, moduleConfigurations, localOnly, lock, log)
|
2010-01-16 01:05:23 +01:00
|
|
|
}
|
2010-09-04 14:19:58 +02:00
|
|
|
final class ExternalIvyConfiguration(val baseDirectory: File, val file: File, val lock: Option[xsbti.GlobalLock], val log: Logger) 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-09-04 14:19:58 +02:00
|
|
|
def apply(paths: IvyPaths, lock: Option[xsbti.GlobalLock], localOnly: Boolean, log: Logger): 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-05-03 01:15:01 +02:00
|
|
|
new InlineIvyConfiguration(paths, Resolver.withDefaultResolvers(Nil), Nil, Nil, localOnly, lock, log)
|
2010-01-16 01:05:23 +01:00
|
|
|
}
|
|
|
|
|
}
|
2009-08-16 20:29:08 +02:00
|
|
|
|
2010-10-26 23:59:24 +02:00
|
|
|
sealed trait ModuleSettings
|
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
|
|
|
}
|
2011-02-15 00:57:10 +01:00
|
|
|
final case class IvyFileConfiguration(file: File, ivyScala: Option[IvyScala], validate: Boolean) extends ModuleSettings
|
2010-01-16 01:05:23 +01:00
|
|
|
{
|
2011-02-15 00:57:10 +01:00
|
|
|
def noScala = copy(ivyScala = None)
|
2010-01-16 01:05:23 +01:00
|
|
|
}
|
2011-02-15 00:57:10 +01:00
|
|
|
final case class PomConfiguration(file: File, ivyScala: Option[IvyScala], validate: Boolean) extends ModuleSettings
|
2010-01-16 01:05:23 +01:00
|
|
|
{
|
2011-02-15 00:57:10 +01:00
|
|
|
def noScala = copy(ivyScala = None)
|
2010-01-16 01:05:23 +01:00
|
|
|
}
|
2011-02-15 00:57:10 +01:00
|
|
|
final case class InlineConfiguration(module: ModuleID, dependencies: Seq[ModuleID], ivyXML: NodeSeq,
|
|
|
|
|
configurations: Seq[Configuration], defaultConfiguration: Option[Configuration], ivyScala: Option[IvyScala],
|
|
|
|
|
validate: Boolean) extends ModuleSettings
|
2010-01-16 01:05:23 +01:00
|
|
|
{
|
2011-02-15 00:57:10 +01:00
|
|
|
def withConfigurations(configurations: Seq[Configuration]) = copy(configurations = configurations)
|
|
|
|
|
def noScala = copy(ivyScala = None)
|
2010-01-16 01:05:23 +01:00
|
|
|
}
|
2011-02-15 00:57:10 +01:00
|
|
|
final case class EmptyConfiguration(module: ModuleID, ivyScala: Option[IvyScala], validate: Boolean) extends ModuleSettings
|
2010-01-16 01:05:23 +01:00
|
|
|
{
|
2011-02-15 00:57:10 +01:00
|
|
|
def noScala = copy(ivyScala = None)
|
2010-01-16 01:05:23 +01:00
|
|
|
}
|
2009-09-09 05:13:30 +02:00
|
|
|
object InlineConfiguration
|
2009-08-16 20:29:08 +02:00
|
|
|
{
|
2010-10-26 23:59:24 +02:00
|
|
|
def apply(module: ModuleID, dependencies: Seq[ModuleID]) =
|
2010-01-16 01:05:23 +01:00
|
|
|
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
|
|
|
{
|
2010-09-04 14:19:58 +02:00
|
|
|
def apply(ivyScala: Option[IvyScala], validate: Boolean, module: => ModuleID)(baseDirectory: File, log: Logger) =
|
2009-09-09 05:13:30 +02:00
|
|
|
{
|
|
|
|
|
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
|
|
|
}
|