mirror of https://github.com/sbt/sbt.git
Add support for loading Ivy settings from a URL
This commit is contained in:
parent
3f7fd80755
commit
ba2e42287b
|
|
@ -65,7 +65,7 @@ final class IvySbt(val configuration: IvyConfiguration)
|
|||
CustomPomParser.registerDefault
|
||||
configuration match
|
||||
{
|
||||
case e: ExternalIvyConfiguration => is.load(e.file)
|
||||
case e: ExternalIvyConfiguration => is.load(e.url)
|
||||
case i: InlineIvyConfiguration =>
|
||||
is.setVariable("ivy.checksums", i.checksums mkString ",")
|
||||
i.paths.ivyHome foreach is.setDefaultIvyUserDir
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
package sbt
|
||||
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
import scala.xml.NodeSeq
|
||||
|
||||
final class IvyPaths(val baseDirectory: File, val ivyHome: Option[File])
|
||||
|
|
@ -27,10 +28,14 @@ final class InlineIvyConfiguration(val paths: IvyPaths, val resolvers: Seq[Resol
|
|||
def withBase(newBase: File) = new InlineIvyConfiguration(paths.withBase(newBase), resolvers, otherResolvers, moduleConfigurations, localOnly, lock, checksums, log)
|
||||
def changeResolvers(newResolvers: Seq[Resolver]) = new InlineIvyConfiguration(paths, newResolvers, otherResolvers, moduleConfigurations, localOnly, lock, checksums, log)
|
||||
}
|
||||
final class ExternalIvyConfiguration(val baseDirectory: File, val file: File, val lock: Option[xsbti.GlobalLock], val log: Logger) extends IvyConfiguration
|
||||
final class ExternalIvyConfiguration(val baseDirectory: File, val url: URL, val lock: Option[xsbti.GlobalLock], val log: Logger) extends IvyConfiguration
|
||||
{
|
||||
type This = ExternalIvyConfiguration
|
||||
def withBase(newBase: File) = new ExternalIvyConfiguration(newBase, file, lock, log)
|
||||
def withBase(newBase: File) = new ExternalIvyConfiguration(newBase, url, lock, log)
|
||||
}
|
||||
object ExternalIvyConfiguration
|
||||
{
|
||||
def apply(baseDirectory: File, file: File, lock: Option[xsbti.GlobalLock], log: Logger) = new ExternalIvyConfiguration(baseDirectory, file.toURI.toURL, lock, log)
|
||||
}
|
||||
|
||||
object IvyConfiguration
|
||||
|
|
@ -42,7 +47,7 @@ object IvyConfiguration
|
|||
log.debug("Autodetecting configuration.")
|
||||
val defaultIvyConfigFile = IvySbt.defaultIvyConfiguration(paths.baseDirectory)
|
||||
if(defaultIvyConfigFile.canRead)
|
||||
new ExternalIvyConfiguration(paths.baseDirectory, defaultIvyConfigFile, lock, log)
|
||||
ExternalIvyConfiguration(paths.baseDirectory, defaultIvyConfigFile, lock, log)
|
||||
else
|
||||
new InlineIvyConfiguration(paths, Resolver.withDefaultResolvers(Nil), Nil, Nil, localOnly, lock, checksums, log)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1252,10 +1252,13 @@ trait BuildExtra extends BuildCommon
|
|||
def seq(settings: Setting[_]*): SettingsDefinition = new Project.SettingList(settings)
|
||||
|
||||
def externalIvySettings(file: Initialize[File] = baseDirectory / "ivysettings.xml"): Setting[Task[IvyConfiguration]] =
|
||||
externalIvySettingsUrl(file(_.toURI.toURL))
|
||||
def externalIvySettings(url: URL): Setting[Task[IvyConfiguration]] = externalIvySettingsUrl(new Project.Value(() => url))
|
||||
private def externalIvySettingsUrl(url: Initialize[URL]): Setting[Task[IvyConfiguration]] =
|
||||
{
|
||||
val other = (baseDirectory, appConfiguration, streams).identityMap
|
||||
ivyConfiguration <<= (file zipWith other) { case (f, otherTask) =>
|
||||
otherTask map { case (base, app, s) => new ExternalIvyConfiguration(base, f, Some(lock(app)), s.log) }
|
||||
ivyConfiguration <<= (url zipWith other) { case (u, otherTask) =>
|
||||
otherTask map { case (base, app, s) => new ExternalIvyConfiguration(base, u, Some(lock(app)), s.log) }
|
||||
}
|
||||
}
|
||||
def externalIvyFile(file: Initialize[File] = baseDirectory / "ivy.xml", iScala: Initialize[Option[IvyScala]] = ivyScala): Setting[Task[ModuleSettings]] =
|
||||
|
|
|
|||
|
|
@ -186,7 +186,11 @@ object CacheIvy
|
|||
implicit def fileConfToHL = (f: FileConfiguration) => f.isLocal :+: f.isTransactional :+: HNil
|
||||
|
||||
implicit def externalIvyConfigurationToHL = (e: ExternalIvyConfiguration) =>
|
||||
exists(e.baseDirectory) :+: hash(e.file) :+: HNil
|
||||
exists(e.baseDirectory) :+:
|
||||
(e.url match {
|
||||
case u: URL if u.getProtocol == "file" => Hash(u)
|
||||
case u: URL => Hash(u.toURI.normalize.toString)
|
||||
}) :+: HNil
|
||||
}
|
||||
import L1._
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
package sbt
|
||||
|
||||
import java.io.{ByteArrayInputStream, File, InputStream}
|
||||
import java.net.URL
|
||||
|
||||
object Hash
|
||||
{
|
||||
|
|
@ -42,6 +43,8 @@ object Hash
|
|||
def apply(as: Array[Byte]): Array[Byte] = apply(new ByteArrayInputStream(as))
|
||||
/** Calculates the SHA-1 hash of the given file.*/
|
||||
def apply(file: File): Array[Byte] = Using.fileInputStream(file)(apply)
|
||||
/** Calculates the SHA-1 hash of the given resource.*/
|
||||
def apply(url: URL): Array[Byte] = Using.urlInputStream(url)(apply)
|
||||
/** Calculates the SHA-1 hash of the given stream, closing it when finished.*/
|
||||
def apply(stream: InputStream): Array[Byte] =
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue