Skip to content

Commit

Permalink
#237: Support empty string for packArchiveStem (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
xerial authored Jul 7, 2021
1 parent 9c186aa commit 3ba7b15
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 26 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ publishPackArchives

// Publish only tar.gz archive. To publish another type of archive, use publishPackArchive(xxx) instead
//publishPackArchiveTgz

// [Optional] Set a root folder name of archive contents. (defualt is (project-name)-(version). Setting this to an empty string is useful for packaging projects for AWS lambda.
packArchiveStem := ""
```

**src/main/scala/Hello.scala**
Expand Down
15 changes: 8 additions & 7 deletions src/main/scala/xerial/sbt/pack/PackArchive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ trait PackArchive {
createOutputStream: (OutputStream) => ArchiveOutputStream,
createEntry: (File, String, File) => ArchiveEntry
) = Def.task {
val out = streams.value
val targetDir: File = packTargetDir.value
val distDir: File = pack.value // run pack command here
val binDir = distDir / "bin"
val archiveStem = s"${packArchiveStem.value}"
val archiveName = s"${packArchiveName.value}.${archiveSuffix}"
val out = streams.value
val targetDir: File = packTargetDir.value
val distDir: File = pack.value // run pack command here
val binDir = distDir / "bin"
val archiveStem = s"${packArchiveStem.value}"
val archiveBaseDir: String = if (archiveStem.isEmpty) "" else s"${archiveStem}/"
val archiveName = s"${packArchiveName.value}.${archiveSuffix}"
out.log.info("Generating " + rpath(baseDirectory.value, targetDir / archiveName))
val aos = createOutputStream(new BufferedOutputStream(new FileOutputStream(targetDir / archiveName)))
val excludeFiles = packArchiveExcludes.value.toSet
Expand All @@ -35,7 +36,7 @@ trait PackArchive {
.getOrElse(Array.empty)
.filterNot(f => excludeFiles.contains(rpath(distDir, f)))
.foreach { file =>
aos.putArchiveEntry(createEntry(file, archiveStem ++ "/" ++ rpath(distDir, file, "/"), binDir))
aos.putArchiveEntry(createEntry(file, archiveBaseDir ++ rpath(distDir, file, "/"), binDir))
if (file.isDirectory) {
aos.closeArchiveEntry()
addFilesToArchive(file)
Expand Down
50 changes: 31 additions & 19 deletions src/sbt-test/sbt-pack/archive-modules/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,50 @@ import xerial.sbt.pack.PackPlugin._
// publish tar.gz archive to the repository (since sbt-pack-0.3.6)

val commonSettings = Defaults.coreDefaultSettings ++
Seq(
scalaVersion := "2.12.14",
version := "0.1",
crossPaths := false
)
Seq(
scalaVersion := "2.12.14",
version := "0.1",
crossPaths := false
)

lazy val root =
Project(
id = "archive-modules",
base = file(".")
).enablePlugins(PackPlugin)
.settings(commonSettings)
.settings(publishPackArchives)
.aggregate(module1, module2) // dependency of module2 should not be included
.dependsOn(module1)
.settings(commonSettings)
.settings(publishPackArchives)
.aggregate(module1, module2) // dependency of module2 should not be included
.dependsOn(module1)

lazy val module1 = Project(
id = "module1",
base = file("module1")
).enablePlugins(PackPlugin)
.settings(commonSettings)
.settings(publishPackArchives)
.settings(
libraryDependencies += "org.xerial" % "xerial-core" % "3.3.6"
)
.settings(commonSettings)
.settings(publishPackArchives)
.settings(
libraryDependencies += "org.xerial" % "xerial-core" % "3.3.6"
)

lazy val module2 = Project(
id = "module2",
base = file("module2")
).enablePlugins(PackPlugin)
.settings(commonSettings)
.settings(publishPackArchives)
.settings(
libraryDependencies += "org.xerial.snappy" % "snappy-java" % "1.1.1.6"
)
.settings(commonSettings)
.settings(publishPackArchives)
.settings(
libraryDependencies += "org.xerial.snappy" % "snappy-java" % "1.1.1.6"
)

// Empty archive stem test
lazy val module3 = Project(
id = "module3",
base = file("module3")
).enablePlugins(PackPlugin)
.settings(commonSettings)
.settings(publishPackArchives)
.settings(
libraryDependencies += "org.xerial.snappy" % "snappy-java" % "1.1.1.6",
packArchiveStem := ""
)
7 changes: 7 additions & 0 deletions src/sbt-test/sbt-pack/archive-modules/test
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ $ exists module1/target/module1-0.1.zip
$ exists module1/target/pack/bin/module1
$ exists module1/target/pack/lib/xerial-core-3.3.6.jar
$ exec sh ./module1/target/pack/bin/module1
$ exec tar tvfz module1/target/module1-0.1.tar.gz

> 'set packArchiveName := "my-archive"'
> packArchiveTgz
$ exists target/my-archive.tar.gz
$ exec tar tvfz target/my-archive.tar.gz

> module3/packArchiveTgz
$ exists module3/target/module3-0.1.tar.gz
$ exec tar tvfz module3/target/module3-0.1.tar.gz

0 comments on commit 3ba7b15

Please sign in to comment.