Skip to content
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
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ jobs:
java: 11
distribution: temurin
jobtype: sbt-1
- os: windows-latest
java: 17
distribution: temurin
jobtype: sbt-2
env:
# define Java options for both official sbt and sbt-extras
JAVA_OPTS: -Xms2048M -Xmx2048M -Xss6M -XX:ReservedCodeCacheSize=256M -Dfile.encoding=UTF-8
Expand Down
13 changes: 8 additions & 5 deletions src/main/scala/sbtassembly/Assembly.scala
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,12 @@ object Assembly {
classByParentDir
.flatMap { case (parentDir, file) =>
val originalTarget = parentDir.relativize(file).toString
classShader(originalTarget, () => new BufferedInputStream(new FileInputStream(file.toFile())))
val sanitizedTarget =
if (originalTarget.contains('\\')) originalTarget.replace('\\', '/')
else originalTarget
classShader(sanitizedTarget, () => new BufferedInputStream(new FileInputStream(file.toFile())))
.map { case (shadedName, stream) =>
Project(targetJarName, originalTarget, shadedName, stream)
Project(targetJarName, sanitizedTarget, shadedName, stream)
}
}
}
Expand All @@ -285,7 +288,8 @@ object Assembly {
log
)
val (jarFiles, jarFileEntries) = timed(Level.Debug, "Collect and shade dependency entries") {
filteredJars.par.map { jar =>
val (externalJars, projectJars) = filteredJars.partition(externalDeps.contains)
(projectJars ++ externalJars).par.map { jar =>
val module = jar.metadata
.get(moduleIDStr)
.map(parseModuleIDStrAttribute)
Expand Down Expand Up @@ -705,8 +709,7 @@ object PathList {
private val sysFileSep = "/"

def unapplySeq(path: String): Option[Seq[String]] = {
val sanitizedPath = if (path.contains('\\')) path.replace('\\', '/') else path
val split = sanitizedPath.split(sysFileSep)
val split = path.split(sysFileSep)
if (split.isEmpty) Option.empty
else Option(split.toList)
}
Expand Down
10 changes: 7 additions & 3 deletions src/sbt-test/merging/merging/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ assemblyMergeStrategy := {
oldStrategy(x)
}
name := "foo"
exportJars := true

lazy val testmerge = (project in file("."))
.settings(
assembly / assemblyJarName := "foo.jar",
TaskKey[Unit]("check") := {
val s = streams.value
val projectAsJar = exportJars.value
val renameSuffix = if (projectAsJar) "foo-0.1" else "foo"
s.log.info(s"Checking with exportJars=$projectAsJar")
IO.withTemporaryDirectory { dir =>
IO.unzip(crossTarget.value / "foo.jar", dir)
mustContain(dir / "a", Seq("1", "2", "1", "3"))
Expand All @@ -27,9 +30,9 @@ lazy val testmerge = (project in file("."))
mustContain(dir / "d", Seq("1", "2", "3"))
mustContain(dir / "e", Seq("1"))
mustNotExist(dir / "f")
mustContain(dir / "README_foo-0.1", Seq("resources"))
mustContain(dir / s"README_$renameSuffix", Seq("resources"))
mustContain(dir / "README_1", Seq("1"))
mustContain(dir / "LICENSE_foo-0.1", Seq("resources"))
mustContain(dir / s"LICENSE_$renameSuffix", Seq("resources"))
mustContain(dir / "LICENSE" / "a", Seq("1"))
// 80f5a06 -- don't rename License.class
mustExist(dir / "com" / "example" / "License.class")
Expand All @@ -41,6 +44,7 @@ lazy val testmerge = (project in file("."))
mustExist(dir / "com" / "example" / "license" / "PublicDomain.class")
mustExist(dir / "NOTICE" / "README_3.txt")
mustExist(dir / "NOTICE" / "LICENSE_3.txt")
mustContain(dir / "META-INF" / "services" / "srv", Seq("local", "jar1", "jar2"))
}
})

Expand Down
Binary file modified src/sbt-test/merging/merging/lib/1.jar
Binary file not shown.
Binary file modified src/sbt-test/merging/merging/lib/2.jar
Binary file not shown.
Binary file modified src/sbt-test/merging/merging/lib/3.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jar1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jar2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
local
9 changes: 7 additions & 2 deletions src/sbt-test/merging/merging/test
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# check if the file gets created
> clean
> set ThisBuild / exportJars := false
> assembly
$ exists target/**/foo.jar
> check

# check if it says hello
> clean
> set ThisBuild / exportJars := true
> assembly
$ exists target/**/foo.jar
> check