Files
sbt/project/PackageSignerPlugin.scala
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

95 lines
3.5 KiB
Scala
Raw Normal View History

import sbt.*
import Keys.*
2026-07-21 01:38:53 +09:00
import sbt.util.CacheImplicits.given
import sbt.internal.librarymanagement.IvyActions
2021-04-24 15:53:08 -04:00
import com.jsuereth.sbtpgp.SbtPgp
2017-05-11 00:11:11 -04:00
import com.typesafe.sbt.packager.universal.{ UniversalPlugin, UniversalDeployPlugin }
import com.typesafe.sbt.packager.debian.{ DebianPlugin, DebianDeployPlugin }
import com.typesafe.sbt.packager.rpm.{ RpmPlugin, RpmDeployPlugin }
2021-04-24 15:53:08 -04:00
import com.jsuereth.sbtpgp.gpgExtension
2017-05-11 00:11:11 -04:00
object PackageSignerPlugin extends sbt.AutoPlugin {
override def trigger = allRequirements
override def requires = SbtPgp && UniversalDeployPlugin && DebianDeployPlugin && RpmDeployPlugin
import com.jsuereth.sbtpgp.PgpKeys.*
import UniversalPlugin.autoImport.*
import DebianPlugin.autoImport.*
import RpmPlugin.autoImport.*
2017-05-11 00:11:11 -04:00
override def projectSettings: Seq[Setting[?]] =
2017-05-11 00:11:11 -04:00
inConfig(Universal)(packageSignerSettings) ++
inConfig(Debian)(packageSignerSettings) ++
inConfig(Rpm)(packageSignerSettings)
2017-05-11 00:11:11 -04:00
def subExtension(art: Artifact, ext: String): Artifact =
art.withExtension(ext)
2017-05-11 00:11:11 -04:00
def packageSignerSettings: Seq[Setting[?]] = Seq(
2026-07-21 01:38:53 +09:00
signedArtifacts := Def.uncached {
2017-05-11 00:11:11 -04:00
val artifacts = packagedArtifacts.value
val r = pgpSigner.value
val skipZ = (pgpSigner / skip).value
2017-05-11 00:11:11 -04:00
val s = streams.value
2026-07-21 01:38:53 +09:00
val converter = fileConverter.value
2017-05-11 00:11:11 -04:00
if (!skipZ) {
2026-07-21 01:38:53 +09:00
artifacts flatMap { case (art, virtualFile) =>
val f = converter.toPath(virtualFile).toFile
Seq(
2026-07-21 01:38:53 +09:00
art -> virtualFile,
subExtension(art, art.extension + gpgExtension) ->
2026-07-21 01:38:53 +09:00
converter.toVirtualFile(r.sign(f, file(f.getAbsolutePath + gpgExtension), s).toPath)
)
2017-05-11 00:11:11 -04:00
}
} else artifacts
2017-05-11 00:11:11 -04:00
},
publishSignedConfiguration := Classpaths.publishConfig(
publishMavenStyle = publishMavenStyle.value,
2026-07-21 01:38:53 +09:00
deliverIvyPattern = fileConverter.value
.toPath((Compile / packageBin / artifactPath).value)
.toFile
.getParent + "/[artifact]-[revision](-[classifier]).[ext]",
status = if (isSnapshot.value) "integration" else "release",
configurations = Vector.empty,
2026-07-21 01:38:53 +09:00
artifacts = signedArtifacts.value.map { (k, v) =>
k -> fileConverter.value.toPath(v).toFile
}.toVector,
checksums = (publish / checksums).value.toVector,
2017-05-11 00:11:11 -04:00
resolverName = Classpaths.getPublishTo(publishTo.value).name,
logging = ivyLoggingLevel.value,
overwrite = isSnapshot.value
),
2017-05-11 00:11:11 -04:00
publishLocalSignedConfiguration := Classpaths.publishConfig(
publishMavenStyle = publishMavenStyle.value,
2026-07-21 01:38:53 +09:00
deliverIvyPattern = fileConverter.value
.toPath((Compile / packageBin / artifactPath).value)
.toFile
.getParent + "/[artifact]-[revision](-[classifier]).[ext]",
status = if (isSnapshot.value) "integration" else "release",
configurations = Vector.empty,
2026-07-21 01:38:53 +09:00
artifacts = signedArtifacts.value.map { (k, v) =>
k -> fileConverter.value.toPath(v).toFile
}.toVector,
checksums = (publish / checksums).value.toVector,
2017-05-11 00:11:11 -04:00
resolverName = "local",
logging = ivyLoggingLevel.value,
overwrite = isSnapshot.value
),
publishSigned := Def.taskDyn {
val config = publishSignedConfiguration.value
val s = streams.value
Def.task {
IvyActions.publish(ivyModule.value, config, s.log)
}
}.value,
publishLocalSigned := Def.taskDyn {
val config = publishLocalSignedConfiguration.value
val s = streams.value
Def.task {
IvyActions.publish(ivyModule.value, config, s.log)
}
}.value
2017-05-11 00:11:11 -04:00
)
}