From be3ea741bc31b06653d40e47f350c409bfb3ae8a Mon Sep 17 00:00:00 2001 From: Eugene Vigdorchik Date: Tue, 7 Feb 2012 20:14:45 +0400 Subject: [PATCH] Mirror ivy \'force\' attribute in sbt. --- ivy/Ivy.scala | 2 +- ivy/IvyInterface.scala | 3 ++- main/actions/CacheIvy.scala | 6 +++--- .../force/project/TestProject.scala | 21 +++++++++++++++++++ .../sbt-test/dependency-management/force/test | 1 + 5 files changed, 28 insertions(+), 5 deletions(-) create mode 100755 sbt/src/sbt-test/dependency-management/force/project/TestProject.scala create mode 100755 sbt/src/sbt-test/dependency-management/force/test diff --git a/ivy/Ivy.scala b/ivy/Ivy.scala index 400490086..a9a5cf8f8 100644 --- a/ivy/Ivy.scala +++ b/ivy/Ivy.scala @@ -404,7 +404,7 @@ private object IvySbt { for(dependency <- dependencies) { - val dependencyDescriptor = new DefaultDependencyDescriptor(moduleID, toID(dependency), false, dependency.isChanging, dependency.isTransitive) + val dependencyDescriptor = new DefaultDependencyDescriptor(moduleID, toID(dependency), dependency.isForce, dependency.isChanging, dependency.isTransitive) dependency.configurations match { case None => // The configuration for this dependency was not explicitly specified, so use the default diff --git a/ivy/IvyInterface.scala b/ivy/IvyInterface.scala index d5ffc4d6a..e7d5115d3 100644 --- a/ivy/IvyInterface.scala +++ b/ivy/IvyInterface.scala @@ -9,7 +9,7 @@ import scala.xml.NodeSeq import org.apache.ivy.plugins.resolver.{DependencyResolver, IBiblioResolver} import org.apache.ivy.util.url.CredentialsStore -final case class ModuleID(organization: String, name: String, revision: String, configurations: Option[String] = None, isChanging: Boolean = false, isTransitive: Boolean = true, explicitArtifacts: Seq[Artifact] = Nil, exclusions: Seq[ExclusionRule] = Nil, extraAttributes: Map[String,String] = Map.empty, crossVersion: CrossVersion = CrossVersion.Disabled) +final case class ModuleID(organization: String, name: String, revision: String, configurations: Option[String] = None, isChanging: Boolean = false, isTransitive: Boolean = true, isForce: Boolean = false, explicitArtifacts: Seq[Artifact] = Nil, exclusions: Seq[ExclusionRule] = Nil, extraAttributes: Map[String,String] = Map.empty, crossVersion: CrossVersion = CrossVersion.Disabled) { override def toString = organization + ":" + name + ":" + revision + @@ -28,6 +28,7 @@ final case class ModuleID(organization: String, name: String, revision: String, def notTransitive() = intransitive() def intransitive() = copy(isTransitive = false) def changing() = copy(isChanging = true) + def force() = copy(isForce = true) def from(url: String) = artifacts(Artifact(name, new URL(url))) def classifier(c: String) = artifacts(Artifact(name, c)) def artifacts(newArtifacts: Artifact*) = copy(explicitArtifacts = newArtifacts ++ this.explicitArtifacts) diff --git a/main/actions/CacheIvy.scala b/main/actions/CacheIvy.scala index 3a5c74b89..468969cb2 100644 --- a/main/actions/CacheIvy.scala +++ b/main/actions/CacheIvy.scala @@ -92,9 +92,9 @@ object CacheIvy private[this] val crossToInt = (c: CrossVersion) => c match { case Disabled => 0; case b: Binary => BinaryValue; case f: Full => FullValue } implicit def moduleIDFormat(implicit sf: Format[String], af: Format[Artifact], bf: Format[Boolean], ef: Format[ExclusionRule]): Format[ModuleID] = - wrap[ModuleID, ((String,String,String,Option[String]),(Boolean,Boolean,Seq[Artifact],Seq[ExclusionRule],Map[String,String],CrossVersion))]( - m => ((m.organization,m.name,m.revision,m.configurations), (m.isChanging, m.isTransitive, m.explicitArtifacts, m.exclusions, m.extraAttributes, m.crossVersion)), - { case ((o,n,r,cs),(ch,t,as,excl,x,cv)) => ModuleID(o,n,r,cs,ch,t,as,excl,x,cv) } + wrap[ModuleID, ((String,String,String,Option[String]),(Boolean,Boolean,Boolean,Seq[Artifact],Seq[ExclusionRule],Map[String,String],CrossVersion))]( + m => ((m.organization,m.name,m.revision,m.configurations), (m.isChanging, m.isTransitive, m.isForce, m.explicitArtifacts, m.exclusions, m.extraAttributes, m.crossVersion)), + { case ((o,n,r,cs),(ch,t,f,as,excl,x,cv)) => ModuleID(o,n,r,cs,ch,t,f,as,excl,x,cv) } ) implicit def configurationFormat(implicit sf: Format[String]): Format[Configuration] = diff --git a/sbt/src/sbt-test/dependency-management/force/project/TestProject.scala b/sbt/src/sbt-test/dependency-management/force/project/TestProject.scala new file mode 100755 index 000000000..4ddd2ad25 --- /dev/null +++ b/sbt/src/sbt-test/dependency-management/force/project/TestProject.scala @@ -0,0 +1,21 @@ +import sbt._ +import Keys._ + +object TestProject extends Build +{ + lazy val root = Project("root", file(".")) settings( + ivyPaths <<= (baseDirectory, target)( (dir, t) => new IvyPaths(dir, Some(t / "ivy-cache"))), + libraryDependencies ++= Seq("log4j" % "log4j" % "1.2.14" force(), + "log4j" % "log4j" % "1.2.13"), + TaskKey[Unit]("check-forced") <<= check() + ) + + def check() = + (dependencyClasspath in Compile) map { jars => + val log4j = jars map (_.data) collect { + case f if f.getName contains "log4j" => f.getName + } + if (log4j.size != 1 || !log4j.head.contains("1.2.14")) + error("Did not download the correct jar.") + } +} diff --git a/sbt/src/sbt-test/dependency-management/force/test b/sbt/src/sbt-test/dependency-management/force/test new file mode 100755 index 000000000..02c335291 --- /dev/null +++ b/sbt/src/sbt-test/dependency-management/force/test @@ -0,0 +1 @@ +> check-forced \ No newline at end of file