forked from softprops/assembly-sbt
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add assemblyUnzipDirectory to AssemblyOption to use a different dir…
…ectory for unzipping jars * Add assemblyCacheDependency task to unzip jar dependencies as a separate task
- Loading branch information
Showing
12 changed files
with
630 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import org.apache.logging.log4j.Level | ||
import org.apache.logging.log4j.core.{LogEvent => Log4JLogEvent, _} | ||
import org.apache.logging.log4j.core.Filter.Result | ||
import org.apache.logging.log4j.core.appender.AbstractAppender | ||
import org.apache.logging.log4j.core.filter.LevelRangeFilter | ||
import org.apache.logging.log4j.core.layout.PatternLayout | ||
|
||
lazy val tempUnzipDir = IO.createTemporaryDirectory | ||
|
||
lazy val root = (project in file(".")). | ||
settings( | ||
version := "0.1", | ||
scalaVersion := "2.11.12", | ||
libraryDependencies += "commons-io" % "commons-io" % "2.4", | ||
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test", | ||
libraryDependencies += "ch.qos.logback" % "logback-classic" % "0.9.29" % "runtime", | ||
assembly / assemblyShadeRules := Seq( | ||
ShadeRule | ||
.rename("org.apache.commons.io.**" -> "shadeio.@1") | ||
.inLibrary("commons-io" % "commons-io" % "2.4") | ||
.inProject | ||
), | ||
assemblyUnzipDirectory := Some(tempUnzipDir), | ||
assemblyCacheUseHardLinks := true, | ||
logLevel := sbt.Level.Info, | ||
logBuffered := false, | ||
assembly / assemblyJarName := "foo.jar", | ||
TaskKey[Unit]("checkunzip") := { | ||
val opt = (assembly / assemblyOption).value | ||
val assemblyDir = opt.assemblyDirectory.get | ||
val assemblyUnzipDir = opt.assemblyUnzipDirectory.get | ||
val preShadePath = "org.apache.commons.io".replace('.', java.io.File.separatorChar) | ||
val postShadePath = "shadeio" | ||
|
||
val sources = PathFinder(assemblyUnzipDir).allPaths pair Path.rebase(assemblyUnzipDir, assemblyDir) | ||
val ioSources = sources.filter{ case (unzip, _) => unzip.getAbsolutePath.contains(preShadePath) && unzip.isFile } | ||
|
||
assert(ioSources.nonEmpty) | ||
sources.map{ _._1 }.foreach{ f => assert(f.exists) } | ||
|
||
ioSources.foreach { case (unzipFile, origOutFile) => | ||
val outputFile = new java.io.File( | ||
origOutFile | ||
.getAbsolutePath | ||
.toString | ||
.replace(preShadePath, postShadePath) | ||
) | ||
|
||
assert(unzipFile.exists) | ||
assert(outputFile.exists) | ||
assert(getHashString(unzipFile) != getHashString(outputFile)) | ||
} | ||
() | ||
}, | ||
TaskKey[Unit]("cleanunzip") := { | ||
IO.delete(tempUnzipDir) | ||
} | ||
) | ||
|
||
def getHashString(file: java.io.File): String = { | ||
import java.security.MessageDigest | ||
MessageDigest | ||
.getInstance("SHA-1") | ||
.digest(IO.readBytes(file)) | ||
.map( b => "%02x".format(b) ) | ||
.mkString | ||
} |
Oops, something went wrong.