-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapt plugincache MergeStrategy to sbt-assembly:2.0.0
Update MergeStrategy code to use temp files to extract the InputStreams Update the sbt assembly plugin to use 2.0.0-RC1 Update the log4j version to 2.17.2 Update version to 2.1.0
- Loading branch information
Showing
2 changed files
with
24 additions
and
21 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
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 |
---|---|---|
@@ -1,29 +1,32 @@ | ||
package sbtassembly | ||
|
||
import java.io.{FileOutputStream, File} | ||
import org.apache.logging.log4j.core.config.plugins.processor.PluginCache | ||
import sbt.IO | ||
import sbt.io.Using | ||
import sbtassembly.Assembly.JarEntry | ||
|
||
import java.io.{BufferedInputStream, FileInputStream, FileOutputStream} | ||
import java.util.UUID | ||
import scala.collection.JavaConverters.asJavaEnumerationConverter | ||
|
||
import org.apache.logging.log4j.core.config.plugins.processor.PluginCache | ||
|
||
object Log4j2MergeStrategy { | ||
val plugincache: MergeStrategy = new MergeStrategy { | ||
val name = "log4j2::plugincache" | ||
def apply(tempDir: File, path: String, files: Seq[File]): Either[String, Seq[(File, String)]] = { | ||
val file = MergeStrategy.createMergeTarget(tempDir, path) | ||
val out = new FileOutputStream(file) | ||
|
||
val aggregator = new PluginCache() | ||
val filesEnum = files.toIterator.map(_.toURI.toURL).asJavaEnumeration | ||
|
||
try { | ||
aggregator.loadCacheFiles(filesEnum) | ||
aggregator.writeCache(out) | ||
Right(Seq(file -> path)) | ||
val plugincache: MergeStrategy = MergeStrategy("log4j2::plugincache", 2) { dependencies => | ||
val DatFileExt = ".dat" | ||
val (datFiles, datURIs) = dependencies.map { dep => | ||
IO.withTemporaryFile(UUID.randomUUID().toString, DatFileExt, true) { datFile => | ||
IO.transfer(dep.stream(), datFile) | ||
datFile -> datFile.toURI.toURL | ||
} | ||
finally { | ||
out.close() | ||
}.unzip | ||
|
||
val stream = IO.withTemporaryFile(UUID.randomUUID().toString, DatFileExt, true) { mergedDatFile => | ||
Using.bufferedOutputStream(new FileOutputStream(mergedDatFile)) { os => | ||
val aggregator = new PluginCache() | ||
aggregator.loadCacheFiles(datURIs.toIterator.asJavaEnumeration) | ||
aggregator.writeCache(os) | ||
() => new BufferedInputStream(new FileInputStream(mergedDatFile)) | ||
} | ||
} | ||
Right(JarEntry(dependencies.head.target, stream) +: Vector.empty) | ||
} | ||
} |