From f38d6aa7f44226afd6ff98084096123f5f880c7c Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Fri, 17 Jun 2011 18:03:59 -0400 Subject: [PATCH] reintegrate dependency-management/provided,provided-multi tests --- .../provided-multi/changes/P.scala | 25 +++++------- .../provided-multi/project/build.properties | 2 - .../dependency-management/provided-multi/test | 16 ++------ .../provided/project/TestProject.scala | 34 +++++++++++++++++ .../provided/project/build.properties | 2 - .../project/build/src/TestProject.scala | 32 ---------------- .../dependency-management/provided/test | 38 ++++++------------- 7 files changed, 59 insertions(+), 90 deletions(-) delete mode 100644 sbt/src/sbt-test/dependency-management/provided-multi/project/build.properties create mode 100644 sbt/src/sbt-test/dependency-management/provided/project/TestProject.scala delete mode 100644 sbt/src/sbt-test/dependency-management/provided/project/build.properties delete mode 100644 sbt/src/sbt-test/dependency-management/provided/project/build/src/TestProject.scala diff --git a/sbt/src/sbt-test/dependency-management/provided-multi/changes/P.scala b/sbt/src/sbt-test/dependency-management/provided-multi/changes/P.scala index 37834dded..524eea86e 100644 --- a/sbt/src/sbt-test/dependency-management/provided-multi/changes/P.scala +++ b/sbt/src/sbt-test/dependency-management/provided-multi/changes/P.scala @@ -1,19 +1,14 @@ import sbt._ - -class P(info: ProjectInfo) extends ParentProject(info) +import Keys._ +object P extends Build { - val a = project("a", "A", new A(_)) - val b = project("b", "B", new B(_), a) + val declared = SettingKey[Boolean]("declared") + lazy val a = Project("A", file("a")) settings( + libraryDependencies += "org.scala-tools.sbinary" %% "sbinary" % "0.4.0" % "provided" + ) - def aLibrary = "org.scala-tools.sbinary" %% "sbinary" % "0.3" % "provided" - - class A(info: ProjectInfo) extends DefaultProject(info) - { - val a = aLibrary - } - class B(info: ProjectInfo) extends DefaultWebProject(info) - { - override def libraryDependencies = - if("declare.lib".asFile.exists) Set(aLibrary) else Set() - } + lazy val b = Project("B", file("b")) dependsOn(a) settings( + libraryDependencies <<= declared(d => if(d) Seq("org.scala-tools.sbinary" %% "sbinary" % "0.4.0" % "provided") else Nil), + declared <<= baseDirectory(_ / "declare.lib" exists) + ) } \ No newline at end of file diff --git a/sbt/src/sbt-test/dependency-management/provided-multi/project/build.properties b/sbt/src/sbt-test/dependency-management/provided-multi/project/build.properties deleted file mode 100644 index 1960ba3b0..000000000 --- a/sbt/src/sbt-test/dependency-management/provided-multi/project/build.properties +++ /dev/null @@ -1,2 +0,0 @@ -project.name=Multi Project Provided -project.version=1.0 \ No newline at end of file diff --git a/sbt/src/sbt-test/dependency-management/provided-multi/test b/sbt/src/sbt-test/dependency-management/provided-multi/test index 9019dbd82..17c17ebd2 100644 --- a/sbt/src/sbt-test/dependency-management/provided-multi/test +++ b/sbt/src/sbt-test/dependency-management/provided-multi/test @@ -1,21 +1,11 @@ -> set build.scala.versions 2.7.7 -$ copy-file changes/P.scala project/build/P.scala +$ copy-file changes/P.scala project/P.scala $ copy-file changes/A.scala a/src/main/scala/A.scala $ copy-file changes/B.scala b/src/main/scala/B.scala > reload -> project A --> compile -> update -> compile - -> project B --> compile -> update --> compile +> A/compile +-> B/compile $ touch b/declare.lib > reload --> compile -> update > compile \ No newline at end of file diff --git a/sbt/src/sbt-test/dependency-management/provided/project/TestProject.scala b/sbt/src/sbt-test/dependency-management/provided/project/TestProject.scala new file mode 100644 index 000000000..f95381ee8 --- /dev/null +++ b/sbt/src/sbt-test/dependency-management/provided/project/TestProject.scala @@ -0,0 +1,34 @@ +import sbt._ +import Keys._ +import complete.DefaultParsers._ + +object TestProject extends Build +{ + val provided = SettingKey[Boolean]("provided") + val check = InputKey[Unit]("check") + + lazy val root = Project("root", file(".")) settings( + provided <<= baseDirectory(_ / "useProvided" exists), + configuration <<= provided(p => if(p) Provided else Compile), + libraryDependencies <+= configuration(c => "javax.servlet" % "servlet-api" % "2.5" % c.name), + managedClasspath in Provided <<= (classpathTypes, update) map { (cpts, report) => Classpaths.managedJars(Provided, cpts, report) }, + check <<= InputTask(_ => Space ~> token(Compile.name.id | Runtime.name | Provided.name | Test.name) ~ token(Space ~> Bool)) { result => + (result, managedClasspath in Provided, fullClasspath in Runtime, fullClasspath in Compile, fullClasspath in Test) map { case ((conf, expected), p, r, c, t) => + val cp = if(conf == Compile.name) c else if(conf == Runtime.name) r else if(conf == Provided.name) p else if(conf == Test.name) t else error("Invalid config: " + conf) + checkServletAPI(cp.files, expected, conf) + } + } + ) + + private def checkServletAPI(paths: Seq[File], shouldBeIncluded: Boolean, label: String) = + { + val servletAPI = paths.find(_.getName contains "servlet-api") + if(shouldBeIncluded) + { + if(servletAPI.isEmpty) + error("Servlet API should have been included in " + label + ".") + } + else + servletAPI.foreach(s => error(s + " incorrectly included in " + label + ".")) + } +} \ No newline at end of file diff --git a/sbt/src/sbt-test/dependency-management/provided/project/build.properties b/sbt/src/sbt-test/dependency-management/provided/project/build.properties deleted file mode 100644 index 59a846bd8..000000000 --- a/sbt/src/sbt-test/dependency-management/provided/project/build.properties +++ /dev/null @@ -1,2 +0,0 @@ -project.version=2.0 -project.name=Test \ No newline at end of file diff --git a/sbt/src/sbt-test/dependency-management/provided/project/build/src/TestProject.scala b/sbt/src/sbt-test/dependency-management/provided/project/build/src/TestProject.scala deleted file mode 100644 index 244050208..000000000 --- a/sbt/src/sbt-test/dependency-management/provided/project/build/src/TestProject.scala +++ /dev/null @@ -1,32 +0,0 @@ -import sbt._ - -class TestProject(info: ProjectInfo) extends DefaultWebProject(info) -{ - override def useMavenConfigurations = true - private val provided = "useProvided".asFile.exists - private val configuration = if(provided) Configurations.Provided else Configurations.Compile - val j = "javax.servlet" % "servlet-api" % "2.5" % (configuration.name + "->default") - - lazy val checkPublic = check(publicClasspath, !provided) - lazy val checkRun = check(runClasspath, true) - lazy val checkCompile = check(compileClasspath, true) - lazy val checkProvided = check(fullClasspath(Configurations.Provided), provided) - - private def check(classpath: PathFinder, shouldBeIncluded: Boolean) = - task { checkServletAPI(shouldBeIncluded, "classpath")(classpath.get) } - - lazy val checkWar = task { Control.thread(FileUtilities.unzip(warPath, outputPath / "exploded", log))(checkServletAPI(!provided, "war")) } - private def checkServletAPI(shouldBeIncluded: Boolean, label: String)(paths: Iterable[Path]) = - { - val servletAPI = paths.find(_.asFile.getName.contains("servlet-api")) - if(shouldBeIncluded) - { - if(servletAPI.isEmpty) - Some("Servlet API should have been included in " + label + ".") - else - None - } - else - servletAPI.map(_ + " incorrectly included in " + label + ".") - } -} \ No newline at end of file diff --git a/sbt/src/sbt-test/dependency-management/provided/test b/sbt/src/sbt-test/dependency-management/provided/test index 628240b5e..68021063f 100644 --- a/sbt/src/sbt-test/dependency-management/provided/test +++ b/sbt/src/sbt-test/dependency-management/provided/test @@ -1,30 +1,16 @@ +> show update + +# verify that the classpaths are correct for when a dependency is in the compile configuration +> check runtime true +> check compile true +> check provided false +> check test true + # verify that the classpaths are correct for when a dependency is in the provided configuration $ touch useProvided > reload -> update - -> check-run -> check-compile -> check-provided -> check-public - -> package -> check-war - -# verify that the classpaths are correct for when a dependency is in the compile configuration -$ delete useProvided -> reload - -> update - -> check-run -> check-compile -> check-provided -> check-public - -# prepare-webapp is last modified based, so we need to force it to do work -$ delete target - -> package -> check-war \ No newline at end of file +> check runtime false +> check compile true +> check test true +> check provided true