From 3e29126cbfdba4ebb11798fcfac0e23fa017e144 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Fri, 15 Apr 2011 18:25:54 -0400 Subject: [PATCH] support checksum generation and checking, enable by default --- ivy/Ivy.scala | 2 ++ ivy/IvyCache.scala | 2 +- ivy/IvyConfigurations.scala | 10 +++++----- launch/Update.scala | 1 + main/Defaults.scala | 7 ++++--- main/Keys.scala | 1 + main/actions/CacheIvy.scala | 2 +- 7 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ivy/Ivy.scala b/ivy/Ivy.scala index 261706f20..1614d7cd2 100644 --- a/ivy/Ivy.scala +++ b/ivy/Ivy.scala @@ -64,6 +64,7 @@ final class IvySbt(val configuration: IvyConfiguration) { case e: ExternalIvyConfiguration => is.load(e.file) case i: InlineIvyConfiguration => + is.setVariable("ivy.checksums", i.checksums mkString ",") i.paths.ivyHome foreach settings.setDefaultIvyUserDir IvySbt.configureCache(is, i.localOnly) IvySbt.setResolvers(is, i.resolvers, i.otherResolvers, i.localOnly, configuration.log) @@ -182,6 +183,7 @@ private object IvySbt val DefaultIvyConfigFilename = "ivysettings.xml" val DefaultIvyFilename = "ivy.xml" val DefaultMavenFilename = "pom.xml" + val DefaultChecksums = Seq("sha1", "md5") def defaultIvyFile(project: File) = new File(project, DefaultIvyFilename) def defaultIvyConfiguration(project: File) = new File(project, DefaultIvyConfigFilename) diff --git a/ivy/IvyCache.scala b/ivy/IvyCache.scala index c46d0fce7..d7c524a84 100644 --- a/ivy/IvyCache.scala +++ b/ivy/IvyCache.scala @@ -86,7 +86,7 @@ object IvyCache { val local = Resolver.defaultLocal val paths = new IvyPaths(new File("."), None) - val conf = new InlineIvyConfiguration(paths, Seq(local), Nil, Nil, false, lock, log) + val conf = new InlineIvyConfiguration(paths, Seq(local), Nil, Nil, false, lock, IvySbt.DefaultChecksums, log) (new IvySbt(conf), local) } /** Creates a default jar artifact based on the given ID.*/ diff --git a/ivy/IvyConfigurations.scala b/ivy/IvyConfigurations.scala index cc8bbd46f..8906018f8 100644 --- a/ivy/IvyConfigurations.scala +++ b/ivy/IvyConfigurations.scala @@ -20,12 +20,12 @@ sealed trait IvyConfiguration } final class InlineIvyConfiguration(val paths: IvyPaths, val resolvers: Seq[Resolver], val otherResolvers: Seq[Resolver], val moduleConfigurations: Seq[ModuleConfiguration], val localOnly: Boolean, val lock: Option[xsbti.GlobalLock], - val log: Logger) extends IvyConfiguration + val checksums: Seq[String], val log: Logger) extends IvyConfiguration { type This = InlineIvyConfiguration def baseDirectory = paths.baseDirectory - 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) + 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 { @@ -37,14 +37,14 @@ 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.*/ - def apply(paths: IvyPaths, lock: Option[xsbti.GlobalLock], localOnly: Boolean, log: Logger): IvyConfiguration = + def apply(paths: IvyPaths, lock: Option[xsbti.GlobalLock], localOnly: Boolean, checksums: Seq[String], log: Logger): IvyConfiguration = { log.debug("Autodetecting configuration.") val defaultIvyConfigFile = IvySbt.defaultIvyConfiguration(paths.baseDirectory) if(defaultIvyConfigFile.canRead) new ExternalIvyConfiguration(paths.baseDirectory, defaultIvyConfigFile, lock, log) else - new InlineIvyConfiguration(paths, Resolver.withDefaultResolvers(Nil), Nil, Nil, localOnly, lock, log) + new InlineIvyConfiguration(paths, Resolver.withDefaultResolvers(Nil), Nil, Nil, localOnly, lock, checksums, log) } } diff --git a/launch/Update.scala b/launch/Update.scala index 6a44c56c9..9f6cb97ad 100644 --- a/launch/Update.scala +++ b/launch/Update.scala @@ -46,6 +46,7 @@ final class Update(config: UpdateConfiguration) val settings = new IvySettings ivyHome foreach settings.setDefaultIvyUserDir addResolvers(settings) + settings.setVariable("ivy.checksums", "sha1,md5") settings.setDefaultConflictManager(settings.getConflictManager(ConflictManagerName)) settings.setBaseDir(bootDirectory) settings.setVariable("scala", scalaVersion) diff --git a/main/Defaults.scala b/main/Defaults.scala index 96c5a80d8..2f686d26f 100644 --- a/main/Defaults.scala +++ b/main/Defaults.scala @@ -63,7 +63,8 @@ object Defaults settings <<= buildStructure map ( _.data ), artifactClassifier :== None, artifactClassifier in packageSrc :== Some(SourceClassifier), - artifactClassifier in packageDoc :== Some(DocClassifier) + artifactClassifier in packageDoc :== Some(DocClassifier), + checksums :== IvySbt.DefaultChecksums )) def projectCore: Seq[Setting[_]] = Seq( name <<= thisProject(_.id), @@ -524,9 +525,9 @@ object Classpaths retrievePattern in GlobalScope :== "[type]/[organisation]/[module]/[artifact](-[revision])(-[classifier]).[ext]", updateConfiguration <<= (retrieveConfiguration, ivyLoggingLevel)((conf,level) => new UpdateConfiguration(conf, false, level) ), retrieveConfiguration <<= (managedDirectory, retrievePattern, retrieveManaged) { (libm, pattern, enabled) => if(enabled) Some(new RetrieveConfiguration(libm, pattern)) else None }, - ivyConfiguration <<= (fullResolvers, ivyPaths, otherResolvers, moduleConfigurations, offline, appConfiguration, streams) map { (rs, paths, other, moduleConfs, off, app, s) => + ivyConfiguration <<= (fullResolvers, ivyPaths, otherResolvers, moduleConfigurations, offline, checksums, appConfiguration, streams) map { (rs, paths, other, moduleConfs, off, check, app, s) => val lock = app.provider.scalaProvider.launcher.globalLock - new InlineIvyConfiguration(paths, rs, other, moduleConfs, off, Some(lock), s.log) + new InlineIvyConfiguration(paths, rs, other, moduleConfs, off, Some(lock), check, s.log) }, ivyConfigurations <<= (autoCompilerPlugins, thisProject) { (auto, project) => project.configurations ++ (if(auto) CompilerPlugin :: Nil else Nil) diff --git a/main/Keys.scala b/main/Keys.scala index 7f3935108..11e945c75 100644 --- a/main/Keys.scala +++ b/main/Keys.scala @@ -210,6 +210,7 @@ object Keys val classpathTypes = SettingKey[Set[String]]("classpath-types") val publishArtifact = SettingKey[Boolean]("publish-artifact") val packagedArtifact = TaskKey[(Artifact, File)]("packaged-artifact") + val checksums = SettingKey[Seq[String]]("checksums") val sbtResolver = SettingKey[Resolver]("sbt-resolver") val sbtDependency = SettingKey[ModuleID]("sbt-dependency") diff --git a/main/actions/CacheIvy.scala b/main/actions/CacheIvy.scala index 133149913..7eb06c3fe 100644 --- a/main/actions/CacheIvy.scala +++ b/main/actions/CacheIvy.scala @@ -88,7 +88,7 @@ object CacheIvy } object L5 { - implicit def inlineIvyToHL = (i: InlineIvyConfiguration) => i.paths :+: i.resolvers :+: i.otherResolvers :+: i.moduleConfigurations :+: i.localOnly :+: HNil + implicit def inlineIvyToHL = (i: InlineIvyConfiguration) => i.paths :+: i.resolvers :+: i.otherResolvers :+: i.moduleConfigurations :+: i.localOnly :+: i.checksums :+: HNil } import L5._