Merge pull request #118 from alexarchambault/shaded-jar-check

Check that lmcoursier is the only remaining namespace in lm-coursier-shaded JAR
This commit is contained in:
Alexandre Archambault 2019-08-12 08:39:37 +02:00 committed by GitHub
commit 7bc0078cb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 2 deletions

View File

@ -51,14 +51,22 @@ lazy val `lm-coursier-shaded` = project
shadeNamespaces ++= Set(
"coursier",
"shapeless",
"argonaut"
"argonaut",
"org.fusesource",
"org.jline"
),
libraryDependencies ++= Seq(
"io.get-coursier" %% "coursier" % coursierVersion0 % "shaded",
"org.scala-lang.modules" %% "scala-xml" % "1.2.0", // depending on that one so that it doesn't get shaded
"org.scala-sbt" %% "librarymanagement-ivy" % "1.2.4",
"org.scalatest" %% "scalatest" % "3.0.8" % Test
)
),
packageBin.in(Shading) := {
val jar = packageBin.in(Shading).value
// ignoreFiles is there temporarily, until https://github.com/coursier/coursier/pull/1317 is merged
Check.onlyNamespace("lmcoursier", jar, ignoreFiles = Set("coursier.properties"))
jar
}
)
lazy val `sbt-coursier-shared` = project

25
project/Check.scala Normal file
View File

@ -0,0 +1,25 @@
import java.io.File
import java.util.zip.ZipFile
import scala.collection.JavaConverters._
object Check {
def onlyNamespace(ns: String, jar: File, ignoreFiles: Set[String] = Set.empty): Unit = {
val zf = new ZipFile(jar)
val unrecognized = zf.entries()
.asScala
.map(_.getName)
.filter { n =>
!n.startsWith("META-INF/") && !n.startsWith(ns + "/") &&
n != "reflect.properties" && // scala-reflect adds that
!ignoreFiles(n)
}
.toVector
.sorted
for (u <- unrecognized)
System.err.println(s"Unrecognized: $u")
assert(unrecognized.isEmpty)
}
}