Skip to content

Commit

Permalink
Merge pull request playframework#720 from xuwei-k/sbt-assembly-2
Browse files Browse the repository at this point in the history
Update sbt-assembly to 2.0.0
  • Loading branch information
mkurz authored Oct 20, 2022
2 parents 63a93ae + 5770e36 commit bfb0c55
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
46 changes: 21 additions & 25 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -138,34 +138,30 @@ lazy val shadeAssemblySettings = commonSettings ++ shadedCommonSettings ++ Seq(
sys.error("Cannot find valid scala version!")
}
},
assembly / target := {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((epoch, major)) =>
baseDirectory.value.getParentFile / "target" / s"$epoch.$major"
case _ =>
sys.error("Cannot find valid scala version!")
}
},
)

val ahcMerge: MergeStrategy = new MergeStrategy {
def apply(tempDir: File, path: String, files: Seq[File]): Either[String, Seq[(File, String)]] = {
import scala.collection.JavaConverters._
val file = MergeStrategy.createMergeTarget(tempDir, path)
val lines = java.nio.file.Files.readAllLines(files.head.toPath).asScala
lines.foreach { line =>
// In AsyncHttpClientConfigDefaults.java, the shading renames the resource keys
// so we have to manually tweak the resource file to match.
val shadedline = line.replace("org.asynchttpclient", "play.shaded.ahc.org.asynchttpclient")
IO.append(file, line)
IO.append(file, IO.Newline.getBytes(IO.defaultCharset))
IO.append(file, shadedline)
IO.append(file, IO.Newline.getBytes(IO.defaultCharset))
val ahcMerge: MergeStrategy = CustomMergeStrategy("ahcMerge") { dependencies =>
Right(dependencies.map { f =>
val stream = () => {
val out = new java.io.ByteArrayOutputStream
val reader = new java.io.BufferedReader(new java.io.InputStreamReader(f.stream.apply()))
try {
reader.lines().forEach { line =>
// In AsyncHttpClientConfigDefaults.java, the shading renames the resource keys
// so we have to manually tweak the resource file to match.
val shadedline = line.replace("org.asynchttpclient", "play.shaded.ahc.org.asynchttpclient")
out.write(line.getBytes(IO.defaultCharset))
out.write(IO.Newline.getBytes(IO.defaultCharset))
out.write(shadedline.getBytes(IO.defaultCharset))
out.write(IO.Newline.getBytes(IO.defaultCharset))
}
} finally {
reader.close()
}
new java.io.ByteArrayInputStream(out.toByteArray)
}
Right(Seq(file -> path))
}

override val name: String = "ahcMerge"
JarEntry(target = f.target, stream = stream)
}.toVector)
}

import scala.xml.transform.RewriteRule
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.2.0")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.0.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.1")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.7.0")
Expand Down

0 comments on commit bfb0c55

Please sign in to comment.