From e02dc987abd3e297d22b7f631eaf4a90768f75d6 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sat, 5 Oct 2024 02:18:07 -0400 Subject: [PATCH 1/2] Cross build to sbt 2.x --- .github/workflows/ci.yml | 4 +- build.sbt | 5 +- sbt-pgp/src/main/scala-2.12/Compat.scala | 68 ++++++++++++ sbt-pgp/src/main/scala-3/Compat.scala | 73 +++++++++++++ sbt-pgp/src/main/scala-sbt-1.0/Compat.scala | 100 ------------------ .../com/jsuereth/pgp/cli/hkpcommands.scala | 2 +- .../scala/com/jsuereth/sbtpgp/PgpKeys.scala | 6 +- .../com/jsuereth/sbtpgp/PgpSettings.scala | 59 +++++++---- .../jsuereth/sbtpgp/PgpSignatureCheck.scala | 15 ++- .../scala/com/jsuereth/sbtpgp/SbtPgp.scala | 2 +- .../sbtpgp/SbtPgpCommandContext.scala | 4 +- .../sbt-test/sbt-pgp/credentials/build.sbt | 13 +++ sbt-pgp/src/sbt-test/sbt-pgp/credentials/test | 2 +- sbt-pgp/src/sbt-test/sbt-pgp/skip/build.sbt | 33 ++++-- sbt-pgp/src/sbt-test/sbt-pgp/skip/test | 2 +- 15 files changed, 242 insertions(+), 146 deletions(-) create mode 100644 sbt-pgp/src/main/scala-2.12/Compat.scala create mode 100644 sbt-pgp/src/main/scala-3/Compat.scala delete mode 100644 sbt-pgp/src/main/scala-sbt-1.0/Compat.scala diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e45e55e..6387fdf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,7 +48,7 @@ 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 @@ -56,4 +56,4 @@ jobs: - 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 diff --git a/build.sbt b/build.sbt index 59489e3..5ab500f 100644 --- a/build.sbt +++ b/build.sbt @@ -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 @@ -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" } } diff --git a/sbt-pgp/src/main/scala-2.12/Compat.scala b/sbt-pgp/src/main/scala-2.12/Compat.scala new file mode 100644 index 0000000..9065ca5 --- /dev/null +++ b/sbt-pgp/src/main/scala-2.12/Compat.scala @@ -0,0 +1,68 @@ +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 + type UnresolvedWarning = lm.UnresolvedWarning + type UnresolvedWarningConfiguration = lm.UnresolvedWarningConfiguration + val UnresolvedWarningConfiguration = lm.UnresolvedWarningConfiguration + + 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) + + // This hack to access private[sbt] + 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, File]]( + "signed-artifacts", + "Packages all artifacts for publishing and maps the Artifact definition to the generated file." + ) + + 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, + art.withExtension(art.extension + gpgExtension) -> r + .sign(file, new File(file.getAbsolutePath + gpgExtension), s) + ) + } + } else artifacts + } + ) + + def toFile(x: File, c: xsbti.FileConverter): File = x +} diff --git a/sbt-pgp/src/main/scala-3/Compat.scala b/sbt-pgp/src/main/scala-3/Compat.scala new file mode 100644 index 0000000..7246768 --- /dev/null +++ b/sbt-pgp/src/main/scala-3/Compat.scala @@ -0,0 +1,73 @@ +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 + type UnresolvedWarning = lm.UnresolvedWarning + type UnresolvedWarningConfiguration = lm.UnresolvedWarningConfiguration + val UnresolvedWarningConfiguration = lm.UnresolvedWarningConfiguration + + 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) + + // This hack to access private[sbt] + 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." + ) + + 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, + art.withExtension(art.extension + gpgExtension) -> signed + ) + } + } else artifacts + } + ) + + def toFile(vf: xsbti.HashedVirtualFileRef, c: xsbti.FileConverter): File = + c.toPath(vf).toFile() +} diff --git a/sbt-pgp/src/main/scala-sbt-1.0/Compat.scala b/sbt-pgp/src/main/scala-sbt-1.0/Compat.scala deleted file mode 100644 index e93db97..0000000 --- a/sbt-pgp/src/main/scala-sbt-1.0/Compat.scala +++ /dev/null @@ -1,100 +0,0 @@ -package sbt -package sbtpgp - -import sbt.{ librarymanagement => lm } -import sbt.internal.{ librarymanagement => ilm } -import Keys._ - -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) - - private 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 -} diff --git a/sbt-pgp/src/main/scala/com/jsuereth/pgp/cli/hkpcommands.scala b/sbt-pgp/src/main/scala/com/jsuereth/pgp/cli/hkpcommands.scala index 26baf6a..706480a 100644 --- a/sbt-pgp/src/main/scala/com/jsuereth/pgp/cli/hkpcommands.scala +++ b/sbt-pgp/src/main/scala/com/jsuereth/pgp/cli/hkpcommands.scala @@ -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) }) } diff --git a/sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/PgpKeys.scala b/sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/PgpKeys.scala index 1b2854d..37e5092 100644 --- a/sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/PgpKeys.scala +++ b/sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/PgpKeys.scala @@ -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 { @@ -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.") diff --git a/sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/PgpSettings.scala b/sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/PgpSettings.scala index 674178a..0dc1f22 100644 --- a/sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/PgpSettings.scala +++ b/sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/PgpSettings.scala @@ -16,6 +16,9 @@ object PgpSettings { /** Settings this plugin defines. TODO - require manual setting of these... */ lazy val projectSettings: Seq[Setting[_]] = signingSettings ++ verifySettings + def deliverPattern(outputPath: File): String = + (outputPath / "[artifact]-[revision](-[classifier]).[ext]").absolutePath + /** Configuration for GPG command line */ lazy val gpgConfigurationSettings: Seq[Setting[_]] = Seq( useGpg := { @@ -136,30 +139,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 ) diff --git a/sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/PgpSignatureCheck.scala b/sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/PgpSignatureCheck.scala index e1854ec..d734927 100644 --- a/sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/PgpSignatureCheck.scala +++ b/sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/PgpSignatureCheck.scala @@ -57,7 +57,7 @@ object PgpSignatureCheck { def signatureArtifacts(m: ModuleID): Option[ModuleID] = { // TODO - Some kind of filtering // TODO - We *can't* assume everything is a jar - def signatureFor(artifact: Artifact) = Seq(artifact, subExtension(artifact, artifact.extension + gpgExtension)) + def signatureFor(artifact: Artifact) = Seq(artifact, artifact.withExtension(artifact.extension + gpgExtension)) // Assume no explicit artifact = "jar" artifact. if (m.explicitArtifacts.isEmpty) Some( @@ -76,7 +76,7 @@ object PgpSignatureCheck { val module = new ivySbt.Module( mkInlineConfiguration(base, deps, ivyScala, confs.toVector) ) - val upConf = subMissingOk(c, true) + val upConf = c.withMissingOk(true) updateEither(module, upConf, UnresolvedWarningConfiguration(), LogicalClock.unknown, None, log) match { case Right(r) => r @@ -84,6 +84,17 @@ object PgpSignatureCheck { } } + 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 checkSignaturesTask(update: UpdateReport, pgp: PgpVerifierFactory, s: TaskStreams): SignatureCheckReport = { val report = SignatureCheckReport(checkArtifactSignatures(update, pgp, s) ++ missingSignatures(update, s)) // TODO - Print results in different task, or provide a report as well. diff --git a/sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/SbtPgp.scala b/sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/SbtPgp.scala index fb7573b..0adcbb6 100644 --- a/sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/SbtPgp.scala +++ b/sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/SbtPgp.scala @@ -1,6 +1,6 @@ package com.jsuereth.sbtpgp -import sbt._ +import sbt.{ given, * } import sbt.sbtpgp.Compat._ /** diff --git a/sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/SbtPgpCommandContext.scala b/sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/SbtPgpCommandContext.scala index 0ba5451..76ce3d6 100644 --- a/sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/SbtPgpCommandContext.scala +++ b/sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/SbtPgpCommandContext.scala @@ -18,7 +18,7 @@ case class SbtPgpCommandContext( // For binary compatibility def this(ctx: cli.PgpStaticContext, optPassphrase: Option[Array[Char]], s: TaskStreams) = - this(ctx, CommandLineUIServices, optPassphrase, s) + this(ctx, CommandLineUIService, optPassphrase, s) def readInput(msg: String): String = System.out.synchronized { interaction.readLine(msg, mask = false) getOrElse sys.error("Failed to grab input") @@ -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...", diff --git a/sbt-pgp/src/sbt-test/sbt-pgp/credentials/build.sbt b/sbt-pgp/src/sbt-test/sbt-pgp/credentials/build.sbt index a802780..4e57c45 100644 --- a/sbt-pgp/src/sbt-test/sbt-pgp/credentials/build.sbt +++ b/sbt-pgp/src/sbt-test/sbt-pgp/credentials/build.sbt @@ -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()) + } +} diff --git a/sbt-pgp/src/sbt-test/sbt-pgp/credentials/test b/sbt-pgp/src/sbt-test/sbt-pgp/credentials/test index 298a0f1..9d3fb51 100644 --- a/sbt-pgp/src/sbt-test/sbt-pgp/credentials/test +++ b/sbt-pgp/src/sbt-test/sbt-pgp/credentials/test @@ -1,4 +1,4 @@ > show pgpPassphrase > show pgpSigner > signedArtifacts -$ exists target/scala-2.13/test_2.13-1.0.jar.asc +> check diff --git a/sbt-pgp/src/sbt-test/sbt-pgp/skip/build.sbt b/sbt-pgp/src/sbt-test/sbt-pgp/skip/build.sbt index b915047..1b935e5 100644 --- a/sbt-pgp/src/sbt-test/sbt-pgp/skip/build.sbt +++ b/sbt-pgp/src/sbt-test/sbt-pgp/skip/build.sbt @@ -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()) + } +} diff --git a/sbt-pgp/src/sbt-test/sbt-pgp/skip/test b/sbt-pgp/src/sbt-test/sbt-pgp/skip/test index ac32625..4d1f402 100644 --- a/sbt-pgp/src/sbt-test/sbt-pgp/skip/test +++ b/sbt-pgp/src/sbt-test/sbt-pgp/skip/test @@ -1,2 +1,2 @@ > publishSigned --$ exists target/scala-2.13/test_2.13-1.0.jar.asc +> check From 7c0d086d125fe7764fce3faeb94c4c9c34ddfa0a Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sat, 5 Oct 2024 02:44:12 -0400 Subject: [PATCH 2/2] Conditional --- sbt-pgp/src/main/scala-2.12/Compat.scala | 12 ++++++------ sbt-pgp/src/main/scala-3/Compat.scala | 13 ++++++------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/sbt-pgp/src/main/scala-2.12/Compat.scala b/sbt-pgp/src/main/scala-2.12/Compat.scala index 9065ca5..0c3916e 100644 --- a/sbt-pgp/src/main/scala-2.12/Compat.scala +++ b/sbt-pgp/src/main/scala-2.12/Compat.scala @@ -46,12 +46,12 @@ object Compat { ) def signingSettings0: Seq[Setting[_]] = Seq( + // conditional signedArtifacts := { - val artifacts = packagedArtifacts.value - val r = pgpSigner.value - val skipZ = (pgpSigner / skip).value - val s = streams.value - if (!skipZ) { + if (!(pgpSigner / skip).value) { + val artifacts = packagedArtifacts.value + val r = pgpSigner.value + val s = streams.value artifacts flatMap { case (art, file) => Seq( @@ -60,7 +60,7 @@ object Compat { .sign(file, new File(file.getAbsolutePath + gpgExtension), s) ) } - } else artifacts + } else packagedArtifacts.value } ) diff --git a/sbt-pgp/src/main/scala-3/Compat.scala b/sbt-pgp/src/main/scala-3/Compat.scala index 7246768..f472786 100644 --- a/sbt-pgp/src/main/scala-3/Compat.scala +++ b/sbt-pgp/src/main/scala-3/Compat.scala @@ -45,12 +45,12 @@ object Compat { ) def signingSettings0: Seq[Setting[_]] = Seq( + // conditional signedArtifacts := { - val artifacts = packagedArtifacts.value - val r = pgpSigner.value - val skipZ = (pgpSigner / skip).value - val s = streams.value - if (!skipZ) { + if (!(pgpSigner / skip).value) { + val artifacts = packagedArtifacts.value + val r = pgpSigner.value + val s = streams.value val c = fileConverter.value artifacts.flatMap { case (art, file) => @@ -58,13 +58,12 @@ object Compat { 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, art.withExtension(art.extension + gpgExtension) -> signed ) } - } else artifacts + } else packagedArtifacts.value } )