Skip to content

Commit

Permalink
Cross build to sbt 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n committed Oct 5, 2024
1 parent ff7c864 commit b03c2ae
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 76 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ jobs:
- name: Build and test
if: ${{ matrix.jobtype == 1 }}
shell: bash
run: sbt -v clean +test +scripted
run: sbt -v clean test scripted
- name: Scalafmt
if: ${{ matrix.jobtype == 2 }}
shell: bash
run: sbt -v clean scalafmtSbtCheck +scalafmtCheckAll
- name: Scala 3
if: ${{ matrix.jobtype == 3 }}
shell: bash
run: sbt -v '++ 3.3.4!' library/test
run: sbt -v '++ 3.3.4!' library/test scripted
5 changes: 3 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ ThisBuild / Compile / scalacOptions := Seq("-feature", "-deprecation", "-Xlint")
// Because we're both a library and an sbt plugin, we use crossScalaVersions rather than crossSbtVersions for
// cross building. So you can use commands like +scripted.
lazy val scala212 = "2.12.15"
ThisBuild / crossScalaVersions := Seq(scala212)
lazy val scala3 = "3.3.4"
ThisBuild / crossScalaVersions := Seq(scala212, scala3)
ThisBuild / scalaVersion := scala212

ThisBuild / scalafmtOnCompile := true
Expand Down Expand Up @@ -46,7 +47,7 @@ lazy val plugin = (project in file("sbt-pgp"))
scriptedLaunchOpts += s"-Dproject.version=${version.value}",
(pluginCrossBuild / sbtVersion) := {
scalaBinaryVersion.value match {
case "2.12" => "1.2.8"
case "2.12" => "1.5.8"
case _ => "2.0.0-M2"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package sbtpgp
import sbt.{ librarymanagement => lm }
import sbt.internal.{ librarymanagement => ilm }
import Keys._
import com.jsuereth.sbtpgp.PgpKeys._
import com.jsuereth.sbtpgp.gpgExtension

object Compat {
val IvyActions = ilm.IvyActions
Expand All @@ -16,8 +18,6 @@ object Compat {
val UnresolvedWarningConfiguration = lm.UnresolvedWarningConfiguration
val CommandLineUIServices = sbt.CommandLineUIService
type PublishConfiguration = lm.PublishConfiguration
type ConfigRef = lm.ConfigRef
val ConfigRef = lm.ConfigRef

val ivyScala = Keys.scalaModuleInfo

Expand Down Expand Up @@ -59,42 +59,33 @@ object Compat {
): Either[UnresolvedWarning, UpdateReport] =
IvyActions.updateEither(module, configuration, uwconfig, log)

private val signedArtifacts = TaskKey[Map[Artifact, File]](
val signedArtifacts = TaskKey[Map[Artifact, File]](
"signed-artifacts",
"Packages all artifacts for publishing and maps the Artifact definition to the generated file."
)
private val pgpMakeIvy = TaskKey[Option[File]]("pgpMakeIvy", "Generates the Ivy file.")

def publishSignedConfigurationTask = Def.task {
val _ = pgpMakeIvy.value
Classpaths.publishConfig(
publishMavenStyle.value,
deliverPattern(crossTarget.value),
if (isSnapshot.value) "integration" else "release",
ivyConfigurations.value.map(c => ConfigRef(c.name)).toVector,
signedArtifacts.value.toVector,
checksums = (publish / checksums).value.toVector,
resolverName = Classpaths.getPublishTo(publishTo.value).name,
logging = ivyLoggingLevel.value,
overwrite = publishConfiguration.value.overwrite
)
}

def publishLocalSignedConfigurationTask = Def.task {
val _ = deliverLocal.value
Classpaths.publishConfig(
publishMavenStyle.value,
deliverPattern(crossTarget.value),
if (isSnapshot.value) "integration" else "release",
ivyConfigurations.value.map(c => ConfigRef(c.name)).toVector,
signedArtifacts.value.toVector,
(publishLocal / checksums).value.toVector,
resolverName = "local",
logging = ivyLoggingLevel.value,
overwrite = publishConfiguration.value.overwrite
)
}

def deliverPattern(outputPath: File): String =
(outputPath / "[artifact]-[revision](-[classifier]).[ext]").absolutePath

def signingSettings0: Seq[Setting[_]] = Seq(
signedArtifacts := {
val artifacts = packagedArtifacts.value
val r = pgpSigner.value
val skipZ = (pgpSigner / skip).value
val s = streams.value
if (!skipZ) {
artifacts flatMap {
case (art, file) =>
Seq(
art -> file,
subExtension(art, art.extension + gpgExtension) -> r
.sign(file, new File(file.getAbsolutePath + gpgExtension), s)
)
}
} else artifacts
}
)

def toFile(x: File, c: xsbti.FileConverter): File = x
}
100 changes: 100 additions & 0 deletions sbt-pgp/src/main/scala-3/Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package sbt
package sbtpgp

import sbt.{ librarymanagement => lm }
import sbt.internal.{ librarymanagement => ilm }
import Keys._
import com.jsuereth.sbtpgp.PgpKeys._
import com.jsuereth.sbtpgp.gpgExtension

object Compat {
val IvyActions = ilm.IvyActions
type IvySbt = ilm.IvySbt
type IvyScala = lm.ScalaModuleInfo
type UpdateConfiguration = lm.UpdateConfiguration
val defaultProgress = EvaluateTask.defaultProgress()
type UnresolvedWarning = lm.UnresolvedWarning
type UnresolvedWarningConfiguration = lm.UnresolvedWarningConfiguration
val UnresolvedWarningConfiguration = lm.UnresolvedWarningConfiguration
val CommandLineUIServices = sbt.CommandLineUIService
type PublishConfiguration = lm.PublishConfiguration
type ConfigRef = lm.ConfigRef
val ConfigRef = lm.ConfigRef

val ivyScala = Keys.scalaModuleInfo

def pgpRequires: Plugins = sbt.plugins.IvyPlugin

def subConfiguration(m: ModuleID, confs: Boolean): ModuleID =
m.withConfigurations(
if (confs) m.configurations
else None
)

def subExplicitArtifacts(m: ModuleID, artifacts: Vector[Artifact]): ModuleID =
m.withExplicitArtifacts(artifacts)

def subExtension(art: Artifact, ext: String): Artifact =
art.withExtension(ext)

def subMissingOk(c: UpdateConfiguration, ok: Boolean): UpdateConfiguration =
c.withMissingOk(ok)

def mkInlineConfiguration(
base: ModuleID,
deps: Vector[ModuleID],
ivyScala: Option[IvyScala],
confs: Vector[Configuration]
): InlineConfiguration =
ModuleDescriptorConfiguration(base, ModuleInfo(base.name))
.withDependencies(deps)
.withScalaModuleInfo(ivyScala)
.withConfigurations(confs)

def updateEither(
module: IvySbt#Module,
configuration: UpdateConfiguration,
uwconfig: UnresolvedWarningConfiguration,
logicalClock: LogicalClock,
depDir: Option[File],
log: Logger
): Either[UnresolvedWarning, UpdateReport] =
IvyActions.updateEither(module, configuration, uwconfig, log)

val signedArtifacts = taskKey[Map[Artifact, xsbti.HashedVirtualFileRef]](
"Packages all artifacts for publishing and maps the Artifact definition to the generated file."
)

private val pgpMakeIvy = TaskKey[Option[File]]("pgpMakeIvy", "Generates the Ivy file.")

def deliverPattern(outputPath: File): String =
(outputPath / "[artifact]-[revision](-[classifier]).[ext]").absolutePath

def signingSettings0: Seq[Setting[_]] = Seq(
signedArtifacts := {
val artifacts = packagedArtifacts.value
val r = pgpSigner.value
val skipZ = (pgpSigner / skip).value
val s = streams.value
if (!skipZ) {
val c = fileConverter.value
artifacts.flatMap {
case (art, file) =>
val p = c.toPath(file)
val signed = c.toVirtualFile(
r.sign(p.toFile(), new File(p.toFile().getAbsolutePath + gpgExtension), s).toPath()
)
// r.sign(p.toFile(), new File(p.toFile().getAbsolutePath + gpgExtension)
Seq(
art -> file,
subExtension(art, art.extension + gpgExtension) -> signed
)
}
} else artifacts
}
)

def toFile(vf: xsbti.HashedVirtualFileRef, c: xsbti.FileConverter): File = {
c.toPath(vf).toFile()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ case class SendKey(pubKey: String, hkpUrl: String) extends HkpCommand {
val key = pubring findPubKeyRing pubKey getOrElse sys.error("Could not find public key: " + pubKey)
val client = hkpClient
log.info("Sending " + key + " to " + client)
client.pushKeyRing(key, { s: String =>
client.pushKeyRing(key, { (s: String) =>
log.debug(s)
})
}
Expand Down
6 changes: 2 additions & 4 deletions sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/PgpKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.jsuereth.sbtpgp

import sbt._
import com.jsuereth.pgp._
import sbt.sbtpgp.Compat._
import sbt.sbtpgp.Compat, Compat._

/** SBT Keys for the PGP plugin. */
object PgpKeys {
Expand Down Expand Up @@ -46,9 +46,7 @@ object PgpKeys {
val publishSignedConfiguration = taskKey[PublishConfiguration]("Configuration for publishing to a repository.")
val publishLocalSignedConfiguration =
taskKey[PublishConfiguration]("Configuration for publishing to the local repository.")
val signedArtifacts = taskKey[Map[Artifact, File]](
"Packages all artifacts for publishing and maps the Artifact definition to the generated file."
)
val signedArtifacts = Compat.signedArtifacts
val publishSigned = taskKey[Unit]("Publishing all artifacts, but SIGNED using PGP.")
val publishLocalSigned = taskKey[Unit]("Publishing all artifacts to a local repository, but SIGNED using PGP.")
val pgpMakeIvy = taskKey[Option[File]]("Generates the Ivy file.")
Expand Down
56 changes: 37 additions & 19 deletions sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/PgpSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -136,30 +136,48 @@ object PgpSettings {
* artifacts. While this isn't as friendly to other plugins that want to
* use our signed artifacts in normal publish flow, it should be more user friendly.
*/
lazy val signingSettings: Seq[Setting[_]] = Seq(
signedArtifacts := {
val artifacts = packagedArtifacts.value
val r = pgpSigner.value
val skipZ = (pgpSigner / skip).value
val s = streams.value
if (!skipZ) {
artifacts flatMap {
case (art, file) =>
Seq(
art -> file,
subExtension(art, art.extension + gpgExtension) -> r
.sign(file, new File(file.getAbsolutePath + gpgExtension), s)
)
}
} else artifacts
},
lazy val signingSettings: Seq[Setting[_]] = signingSettings0 ++ Seq(
pgpMakeIvy := (Def.taskDyn {
val style = publishMavenStyle.value
if (style) Def.task { (None: Option[File]) } else Def.task { Option(deliver.value) }
}).value,
publishSignedConfiguration := publishSignedConfigurationTask.value,
publishSignedConfiguration := {
val _ = pgpMakeIvy.value
val c = fileConverter.value
Classpaths.publishConfig(
publishMavenStyle.value,
deliverPattern(crossTarget.value),
if (isSnapshot.value) "integration" else "release",
ivyConfigurations.value.map(c => ConfigRef(c.name)).toVector,
PgpKeys.signedArtifacts.value.toVector.map {
case (a, x) =>
a -> toFile(x, c)
},
checksums = (publish / checksums).value.toVector,
resolverName = Classpaths.getPublishTo(publishTo.value).name,
logging = ivyLoggingLevel.value,
overwrite = publishConfiguration.value.overwrite
)
},
publishSigned := publishSignedTask(publishSignedConfiguration, deliver).value,
publishLocalSignedConfiguration := publishLocalSignedConfigurationTask.value,
publishLocalSignedConfiguration := {
val _ = deliverLocal.value
val c = fileConverter.value
Classpaths.publishConfig(
publishMavenStyle.value,
deliverPattern(crossTarget.value),
if (isSnapshot.value) "integration" else "release",
ivyConfigurations.value.map(c => ConfigRef(c.name)).toVector,
PgpKeys.signedArtifacts.value.toVector.map {
case (a, x) =>
a -> toFile(x, c)
},
(publishLocal / checksums).value.toVector,
resolverName = "local",
logging = ivyLoggingLevel.value,
overwrite = publishConfiguration.value.overwrite
)
},
publishLocalSigned := publishSignedTask(publishLocalSignedConfiguration, deliver).value
)

Expand Down
2 changes: 1 addition & 1 deletion sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/SbtPgp.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.jsuereth.sbtpgp

import sbt._
import sbt.{ given, * }
import sbt.sbtpgp.Compat._

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ case class SbtPgpCommandContext(
default = optPassphrase getOrElse inputPassphrase
)(f)
} match {
case Right(u) => u
case Right(u) => u.asInstanceOf[U]
case Left(e) =>
throw new IllegalArgumentException(
s"Wrong passphrase for key ${key.toHexString.toUpperCase} in ${ctx.secretKeyRingFile.getAbsolutePath}: ${e.getMessage}. aborting...",
Expand Down
13 changes: 13 additions & 0 deletions sbt-pgp/src/sbt-test/sbt-pgp/credentials/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,16 @@ scalaVersion := "2.13.2"
name := "test"
organization := "test"
version := "1.0"

TaskKey[Unit]("check") := {
val sbtV = sbtBinaryVersion.value
if (sbtV == "1.0") {
val x = target.value / "scala-2.13" / "test_2.13-1.0.jar.asc"
assert(x.exists())
} else {
import xsbti.VirtualFileRef
val conv = fileConverter.value
val p = conv.toPath(VirtualFileRef.of("${OUT}/jvm/scala-2.13.2/test/test_2.13-1.0.jar.asc"))
assert(p.toFile.exists())
}
}
2 changes: 1 addition & 1 deletion sbt-pgp/src/sbt-test/sbt-pgp/credentials/test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
> show pgpPassphrase
> show pgpSigner
> signedArtifacts
$ exists target/scala-2.13/test_2.13-1.0.jar.asc
> check
33 changes: 22 additions & 11 deletions sbt-pgp/src/sbt-test/sbt-pgp/skip/build.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
lazy val root = (project in file("."))
.settings(
credentials in GlobalScope := Seq(Credentials("", "pgp", "", "test password")),
pgpSecretRing := baseDirectory.value / "secring.pgp",
pgpPublicRing := baseDirectory.value / "pubring.pgp",
scalaVersion := "2.13.2",
name := "test",
organization := "test",
version := "1.0",
skip in publish := true
)
Global / credentials := Seq(Credentials("", "pgp", "", "test password"))

pgpSecretRing := baseDirectory.value / "secring.pgp"
pgpPublicRing := baseDirectory.value / "pubring.pgp"
scalaVersion := "2.13.2"
name := "test"
organization := "test"
version := "1.0"
publish / skip := true

TaskKey[Unit]("check") := {
val sbtV = sbtBinaryVersion.value
if (sbtV == "1.0") {
val x = target.value / "scala-2.13" / "test_2.13-1.0.jar.asc"
assert(!x.exists())
} else {
import xsbti.VirtualFileRef
val conv = fileConverter.value
val p = conv.toPath(VirtualFileRef.of("${OUT}/jvm/scala-2.13.2/test/test_2.13-1.0.jar.asc"))
assert(!p.toFile.exists())
}
}
2 changes: 1 addition & 1 deletion sbt-pgp/src/sbt-test/sbt-pgp/skip/test
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
> publishSigned
-$ exists target/scala-2.13/test_2.13-1.0.jar.asc
> check

0 comments on commit b03c2ae

Please sign in to comment.