Check that lmcoursier is the only ns in lm-coursier-shaded JAR

This commit is contained in:
Alexandre Archambault 2019-08-09 16:18:29 +02:00
parent cd1b9a39ce
commit c0acb02efd
2 changed files with 32 additions and 1 deletions

View File

@ -58,7 +58,13 @@ lazy val `lm-coursier-shaded` = project
"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)
}
}