Skip to content

Commit

Permalink
fixes directory cache including stale files. fixes sbt#86
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n committed Jul 27, 2013
1 parent e3a464a commit 7794774
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/main/scala/sbtassembly/Plugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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-" =>
Expand All @@ -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
Expand Down
31 changes: 17 additions & 14 deletions src/sbt-test/sbt-assembly/caching/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,36 @@ 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!!)
if (out.trim != "hello") error("unexpected output: " + out)
()
}

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"
Expand Down
7 changes: 6 additions & 1 deletion src/sbt-test/sbt-assembly/caching/src/main/scala/hello.scala
Original file line number Diff line number Diff line change
@@ -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")
}
}
}
11 changes: 11 additions & 0 deletions src/sbt-test/sbt-assembly/caching/test
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7794774

Please sign in to comment.