diff --git a/src/main/scala/sbtassembly/Plugin.scala b/src/main/scala/sbtassembly/Plugin.scala index 51b970d3..5b62831a 100644 --- a/src/main/scala/sbtassembly/Plugin.scala +++ b/src/main/scala/sbtassembly/Plugin.scala @@ -249,7 +249,6 @@ object Plugin extends sbt.Plugin { val (libs, dirs) = classpath.map(_.data).sorted.partition(ClasspathUtilities.isArchive) val depLibs = dependencies.map(_.data).sorted.partition(ClasspathUtilities.isArchive)._1 val excludedJars = ej map {_.data} - log.info(libs.toString) val libsFiltered = libs flatMap { case jar if excludedJars contains jar.asFile => None case jar if jar.asFile.getName startsWith "scala-" => @@ -270,6 +269,9 @@ object Plugin extends sbt.Plugin { val hash = sha1name(dir) IO.write(tempDir / (hash + "_dir.dir"), dir.getCanonicalPath, IO.utf8, false) val dest = tempDir / (hash + "_dir") + if (dest.exists) { + IO.delete(dest) + } dest.mkdir() IO.copyDirectory(dir, dest) dest diff --git a/src/sbt-test/sbt-assembly/caching/build.sbt b/src/sbt-test/sbt-assembly/caching/build.sbt index 3c720b4f..7f1c8498 100644 --- a/src/sbt-test/sbt-assembly/caching/build.sbt +++ b/src/sbt-test/sbt-assembly/caching/build.sbt @@ -14,26 +14,22 @@ libraryDependencies += "ch.qos.logback" % "logback-classic" % "0.9.29" % "runtim assemblyCacheUnzip in assembly := true -assemblyCacheOutput in assembly := false +assemblyCacheOutput in assembly := true -unmanagedJars in Compile <++= baseDirectory map { base => - (base / "lib" / "compile" ** "*.jar").classpath -} - -unmanagedJars in Runtime <++= baseDirectory map { base => - (base / "lib" / "runtime" ** "*.jar").classpath -} +jarName in assembly := "foo.jar" -unmanagedJars in Test <++= baseDirectory map { base => - (base / "lib" / "test" ** "*.jar").classpath +TaskKey[Seq[File]]("genresource") <<= (unmanagedResourceDirectories in Compile) map { (dirs) => + val file = dirs.head / "foo.txt" + IO.write(file, "bye") + Seq(file) } -excludedJars in assembly <<= (fullClasspath in assembly) map { cp => - cp filter {_.data.getName == "compile-0.1.0.jar"} +TaskKey[Seq[File]]("genresource2") <<= (unmanagedResourceDirectories in Compile) map { (dirs) => + val file = dirs.head / "bar.txt" + IO.write(file, "bye") + Seq(file) } -jarName in assembly := "foo.jar" - TaskKey[Unit]("check") <<= (crossTarget) map { (crossTarget) => val process = sbt.Process("java", Seq("-jar", (crossTarget / "foo.jar").toString)) val out = (process!!) @@ -41,6 +37,13 @@ TaskKey[Unit]("check") <<= (crossTarget) map { (crossTarget) => () } +TaskKey[Unit]("checkfoo") <<= (crossTarget) map { (crossTarget) => + val process = sbt.Process("java", Seq("-jar", (crossTarget / "foo.jar").toString)) + val out = (process!!) + if (out.trim != "foo.txt") error("unexpected output: " + out) + () +} + TaskKey[Unit]("checkhash") <<= (crossTarget, streams) map { (crossTarget, s) => import java.security.MessageDigest val jarHash = crossTarget / "jarHash.txt" diff --git a/src/sbt-test/sbt-assembly/caching/src/main/scala/hello.scala b/src/sbt-test/sbt-assembly/caching/src/main/scala/hello.scala index 9decd677..5b2bde64 100644 --- a/src/sbt-test/sbt-assembly/caching/src/main/scala/hello.scala +++ b/src/sbt-test/sbt-assembly/caching/src/main/scala/hello.scala @@ -1,3 +1,8 @@ object Main { - def main(args: Array[String]) { println("hello") } + def main(args: Array[String]) { + Option(getClass().getResource("foo.txt")) match { + case Some(_) => println("foo.txt") + case _ => println("hello") + } + } } diff --git a/src/sbt-test/sbt-assembly/caching/test b/src/sbt-test/sbt-assembly/caching/test index 267ccfe0..365fa4bf 100644 --- a/src/sbt-test/sbt-assembly/caching/test +++ b/src/sbt-test/sbt-assembly/caching/test @@ -18,3 +18,14 @@ $ newer target/scala-2.9.1/foo.jar target/scala-2.9.1/jarHash.txt # on disk > checkhash $ newer target/scala-2.9.1/jarHash.txt target/scala-2.9.1/foo.jar + +# generate file +> genresource +> assembly +> checkfoo + +# delete the generated file +$ delete src/main/resources/foo.txt +> genresource2 +> assembly +> check