Skip to content

Commit

Permalink
Fixes #175 - Staging does not clear previous files.
Browse files Browse the repository at this point in the history
* Use sync when copying to staging directory
* Add test to make sure incrementally removing files shows up correctly.

NOTE: we may need to feed this through all our staging, e.g. when generating
MSIs or RPMs or DEBs.
  • Loading branch information
jsuereth committed Mar 26, 2014
1 parent 7bbbdbe commit cf97029
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package packager
package universal

import sbt._
import sbt.Keys.cacheDirectory
import Keys._
import Archives._
import sbt.Keys.TaskStreams
Expand Down Expand Up @@ -36,7 +37,7 @@ trait UniversalPlugin extends Plugin {
mappings <<= sourceDirectory map findSources,
dist <<= (packageBin, streams) map printDist,
stagingDirectory <<= target apply (_ / "stage"),
stage <<= (stagingDirectory, mappings) map stageFiles
stage <<= (cacheDirectory, stagingDirectory, mappings) map stageFiles(config.name)
)) ++ Seq(
sourceDirectory in config <<= sourceDirectory apply (_ / config.name),
target in config <<= target apply (_ / config.name)
Expand All @@ -54,9 +55,12 @@ trait UniversalPlugin extends Plugin {
dist
}

private[this] def stageFiles(to: File, mappings: Seq[(File, String)]): Unit = {
val copies = mappings collect { case (f, p) => f -> (to / p) }
IO.copy(copies)
private[this] def stageFiles(config: String)(cacheDirectory: File, to: File, mappings: Seq[(File, String)]): Unit = {
val cache = cacheDirectory / ("packager-mappings-" + config)
val copies = mappings map {
case (file, path) => file -> (to / path)
}
Sync(cache)(copies)
// Now set scripts to executable using Java's lack of understanding of permissions.
// TODO - Config file user-readable permissions....
for {
Expand Down
7 changes: 7 additions & 0 deletions src/sbt-test/universal/clear-stage-dir/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import NativePackagerKeys._

packagerSettings

name := "simple-test"

version := "0.1.0"
1 change: 1 addition & 0 deletions src/sbt-test/universal/clear-stage-dir/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Test configuration to include in zips.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# removable file
9 changes: 9 additions & 0 deletions src/sbt-test/universal/clear-stage-dir/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Stage the distribution and ensure files show up.
> universal:stage
$ exists target/universal/stage/conf/test
$ exists target/universal/stage/conf/test2
$ delete src/universal/conf/test2
> universal:stage
$ exists target/universal/stage/conf/test
$ absent target/universal/stage/conf/test2

0 comments on commit cf97029

Please sign in to comment.