Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #175 - Staging does not clear previous files. #202

Merged
merged 1 commit into from
Mar 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this interfere with something else?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's possible if someone used the same cache for the same config...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be a problem, when it is a problem

val copies = mappings map {
case (file, path) => file -> (to / path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the variable names 👍

}
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