Skip to content

Commit

Permalink
Update commons-compress to 1.26.0 (#478)
Browse files Browse the repository at this point in the history
* Update commons-compress to 1.26.0

* Fix

* Add commons-codec

---------

Co-authored-by: Taro L. Saito <[email protected]>
  • Loading branch information
xerial-bot and xerial authored Feb 28, 2024
1 parent 6c26272 commit 91bddb8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
6 changes: 4 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ testFrameworks += new TestFramework("wvlet.airspec.Framework")

libraryDependencies ++= Seq(
"org.wvlet.airframe" %% "airspec" % "24.2.3" % Test,
"org.apache.commons" % "commons-compress" % "1.24.0",
"org.tukaani" % "xz" % "1.9"
"org.apache.commons" % "commons-compress" % "1.26.0",
// commons-codec is necessary for commons-compress
"commons-codec" % "commons-codec" % "1.16.1",
"org.tukaani" % "xz" % "1.9"
)
42 changes: 22 additions & 20 deletions src/main/scala/xerial/sbt/pack/PackArchive.scala
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package xerial.sbt.pack

import java.io._

import org.apache.commons.compress.archivers._
import org.apache.commons.compress.archivers.tar._
import org.apache.commons.compress.archivers.zip._
import java.io.*
import org.apache.commons.compress.archivers.*
import org.apache.commons.compress.archivers.tar.*
import org.apache.commons.compress.archivers.zip.*
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream
import org.apache.commons.compress.utils.IOUtils
import sbt.Keys._
import sbt._
import org.apache.commons.io.IOUtils
import sbt.Keys.*
import sbt.*

trait PackArchive {

import PackPlugin.autoImport._

private def createArchive(
private def createArchive[EntryType <: ArchiveEntry](
archiveSuffix: String,
createOutputStream: (OutputStream) => ArchiveOutputStream,
createEntry: (File, String, File) => ArchiveEntry
createOutputStream: (OutputStream) => ArchiveOutputStream[EntryType],
createEntry: (File, String, File) => EntryType
) = Def.task {
val out = streams.value
val targetDir: File = packTargetDir.value
Expand Down Expand Up @@ -56,21 +55,22 @@ trait PackArchive {
targetDir / archiveName
}

private def createTarEntry(file: File, fileName: String, binDir: File) = {
private def createTarEntry(file: File, fileName: String, binDir: File): TarArchiveEntry = {
val archiveEntry = new TarArchiveEntry(file, fileName)
if (file.getAbsolutePath startsWith binDir.getAbsolutePath)
if (file.getAbsolutePath startsWith binDir.getAbsolutePath) {
archiveEntry.setMode(Integer.parseInt("0755", 8))
}
archiveEntry
}

private def createTarArchiveOutputStream(os: OutputStream) = {
private def createTarArchiveOutputStream(os: OutputStream): TarArchiveOutputStream = {
val tos = new TarArchiveOutputStream(os)
tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX)
tos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX)
tos
}

private def createZipEntry(file: File, fileName: String, binDir: File) = {
private def createZipEntry(file: File, fileName: String, binDir: File): ZipArchiveEntry = {
val archiveEntry = new ZipArchiveEntry(file, fileName)
if (file.getAbsolutePath.startsWith(binDir.getAbsolutePath)) {
archiveEntry.setUnixMode(Integer.parseInt("0755", 8))
Expand All @@ -88,28 +88,30 @@ trait PackArchive {
packArchiveTxzArtifact := Artifact(packArchivePrefix.value, "arch", "tar.xz"),
packArchiveZipArtifact := Artifact(packArchivePrefix.value, "arch", "zip"),
Def.derive(
packArchiveTgz := createArchive(
packArchiveTgz := createArchive[TarArchiveEntry](
"tar.gz",
(fos) => createTarArchiveOutputStream(new GzipCompressorOutputStream(fos)),
createTarEntry
).value
),
Def.derive(
packArchiveTbz := createArchive(
packArchiveTbz := createArchive[TarArchiveEntry](
"tar.bz2",
(fos) => createTarArchiveOutputStream(new BZip2CompressorOutputStream(fos)),
createTarEntry
).value
),
Def.derive(
packArchiveTxz := createArchive(
packArchiveTxz := createArchive[TarArchiveEntry](
"tar.xz",
(fos) => createTarArchiveOutputStream(new XZCompressorOutputStream(fos)),
createTarEntry
).value
),
Def.derive(packArchiveZip := createArchive("zip", new ZipArchiveOutputStream(_), createZipEntry).value),
Def.derive(packArchive := Seq(packArchiveTgz.value, packArchiveZip.value))
Def.derive(
packArchiveZip := createArchive[ZipArchiveEntry]("zip", new ZipArchiveOutputStream(_), createZipEntry).value
),
Def.derive(packArchive := Seq(packArchiveTgz.value, packArchiveZip.value))
)

def publishPackArchiveTgz: SettingsDefinition =
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/xerial/sbt/pack/PackPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ object PackPlugin extends AutoPlugin with PackArchive {
packGenerateMakefile := true,
packMainDiscovered := Def.taskDyn {
val mainClasses =
getFromSelectedProjects(thisProjectRef.value, discoveredMainClasses in Compile, state.value, packExclude.value)
getFromSelectedProjects(thisProjectRef.value, Compile / discoveredMainClasses, state.value, packExclude.value)
Def.task {
mainClasses.value.flatMap(_._1.map(mainClass => hyphenize(mainClass.split('.').last) -> mainClass).toMap).toMap
}
}.value,
packAllUnmanagedJars := Def.taskDyn {
val allUnmanagedJars =
getFromSelectedProjects(thisProjectRef.value, unmanagedJars in Runtime, state.value, packExclude.value)
getFromSelectedProjects(thisProjectRef.value, Runtime / unmanagedJars, state.value, packExclude.value)
Def.task { allUnmanagedJars.value }
}.value,
Def.derive(
Expand Down Expand Up @@ -513,7 +513,7 @@ object PackPlugin extends AutoPlugin with PackArchive {
(currentProject +: (children flatMap transitiveDependencies)) filterNot (isExcluded)
}
val projects: Seq[ProjectRef] = transitiveDependencies(contextProject).distinct
projects.map(p => (Def.task { ((targetTask in p).value, p) }) evaluate structure.data).join
projects.map(p => (Def.task { ((p / targetTask).value, p) }) evaluate structure.data).join
}

private val humanReadableTimestampFormatter = new DateTimeFormatterBuilder()
Expand Down

0 comments on commit 91bddb8

Please sign in to comment.