Skip to content

Commit

Permalink
Move com.typesafe.sbt.pgp to com.jsuereth.sbtpgp
Browse files Browse the repository at this point in the history
It's odd for the namespace of the plugin to not match the artifact
namespace.
Also, cleans up obvious, low-hanging-fruit deprecation warnings.
  • Loading branch information
Tim Harper authored and eed3si9n committed Sep 15, 2019
1 parent c9053c9 commit a8c3fae
Show file tree
Hide file tree
Showing 38 changed files with 34 additions and 48 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ lazy val library =

// The sbt plugin.
lazy val plugin =
Project("plugin", file("pgp-plugin"))
Project("plugin", file("sbt-pgp"))
.dependsOn(library)
.settings(
sbtPlugin := true,
Expand Down
5 changes: 2 additions & 3 deletions gpg-library/src/main/scala/com/jsuereth/pgp/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ object PGP {
}
java.security.Security.addProvider(newProvider)
} catch {
case t => sys.error("Could not initialize bouncy castle encryption.")
case t: Throwable => sys.error("Could not initialize bouncy castle encryption.")
}

/** This is a helper method used to make sure the above initialization happens. */
def init = ()

def init(): Unit = ()

/** This can load your local PGP keyring. */
def loadPublicKeyRing(file: File) = PublicKeyRing loadFromFile file
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object CommonParsers {

private def hexPublicKeyIds(ctx: PgpStaticContext): Seq[String] =
try {
(ctx.publicKeyRing.publicKeys.view map (_.keyID) map ("%x" format (_))).toSeq
ctx.publicKeyRing.publicKeys.view.map(_.keyID).map("%x" format (_)).toSeq
} catch {
case _: Throwable => Seq.empty
}
Expand All @@ -23,7 +23,7 @@ object CommonParsers {

private def userIds(ctx: PgpStaticContext): Seq[String] =
try {
(ctx.publicKeyRing.publicKeys.view flatMap (_.userIDs)).toSeq
ctx.publicKeyRing.publicKeys.view.flatMap(_.userIDs).toSeq
} catch {
case _: Throwable => Seq.empty
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.typesafe.sbt
package pgp
package com.jsuereth.sbtpgp


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

/** SBT Keys for the PGP plugin. */
object PgpKeys {
// PGP related setup
// PGP related setup
val pgpSigner = taskKey[PgpSigner]("The helper class to run GPG commands.")
val pgpVerifierFactory = taskKey[PgpVerifierFactory]("The helper class to verify public keys from a public key ring.")
val pgpSecretRing = settingKey[File]("The location of the secret key ring. Only needed if using bouncy castle.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package com.typesafe.sbt
package pgp

package com.jsuereth.sbtpgp

import sbt._
import Keys._
Expand Down Expand Up @@ -225,6 +223,7 @@ object PgpSettings {
PgpSignatureCheck.checkSignaturesTask(updatePgpSignatures.value, pgpVerifierFactory.value, streams.value)
}
)

lazy val globalSettings: Seq[Setting[_]] = inScope(Global)(gpgConfigurationSettings ++ nativeConfigurationSettings ++ signVerifyConfigurationSettings)
/** Settings this plugin defines. TODO - require manual setting of these... */
lazy val projectSettings: Seq[Setting[_]] = signingSettings ++ verifySettings ++ Seq(commands += pgpCommand)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package com.typesafe.sbt
package pgp
package com.jsuereth.sbtpgp

import sbt._
import Keys._
Expand Down Expand Up @@ -87,7 +86,7 @@ object PgpSignatureCheck {
}

/** Pretty-prints a report to the logs of all the PGP signature results. */
def prettyPrintSingatureReport(report: SignatureCheckReport, s: TaskStreams): Unit =
def prettyPrintSingatureReport(report: SignatureCheckReport, s: TaskStreams): Unit =
if(report.results.isEmpty) s.log.info("----- No Dependencies for PGP check -----")
else {
import report._
Expand All @@ -108,14 +107,14 @@ object PgpSignatureCheck {
} foreach { x => s.log.info(prettify(x)) }
}
/** Returns the SignatureCheck results for all missing signature artifacts in an update. */
private def missingSignatures(update: UpdateReport, s: TaskStreams): Seq[SignatureCheck] =
private def missingSignatures(update: UpdateReport, s: TaskStreams): Seq[SignatureCheck] =
for {
config <- update.configurations
module <- config.modules
artifact <- module.missingArtifacts
if artifact.extension endsWith gpgExtension
} yield SignatureCheck(module.module, artifact, SignatureCheckResult.MISSING)

/** Returns the SignatureCheck results for all downloaded signature artifacts. */
private def checkArtifactSignatures(update: UpdateReport, pgp: PgpVerifierFactory, s: TaskStreams): Seq[SignatureCheck] = {
pgp.withVerifier(pgp => for {
Expand All @@ -126,5 +125,3 @@ object PgpSignatureCheck {
} yield SignatureCheck(module.module, artifact, pgp.verifySignature(file, s)))
}
}


Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package com.typesafe.sbt
package pgp
package com.jsuereth.sbtpgp

import sbt._
import Keys._
Expand All @@ -8,8 +7,8 @@ import sbt.sbtpgp.Compat._

/** The interface used to sign plugins. */
trait PgpSigner {
/** Signs a given file and writes the output to the signature file specified.
* Returns the signature file, throws on errors.
/** Signs a given file and writes the output to the signature file specified.
* Returns the signature file, throws on errors.
*/
def sign(file: File, signatureFile: File, s: TaskStreams): File
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package com.typesafe.sbt
package pgp
package com.jsuereth.sbtpgp

import scala.util.matching.Regex
import scala.util.control.Exception._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package com.typesafe.sbt
package pgp
package com.jsuereth.sbtpgp

import sbt._
import Def.Initialize
Expand All @@ -12,8 +11,8 @@ object SbtHelpers {
* the value of the switch setting.
*/
def switch[T](switch: SettingKey[Boolean],
iftrue: Initialize[T],
iffalse: Initialize[T]): Initialize[T] =
iftrue: Def.Initialize[T],
iffalse: Def.Initialize[T]): Def.Initialize[T] =
switch.zipWith(iftrue) { (use, first) =>
if(use) Some(first) else None
}.zipWith(iffalse) { (opt, second) => opt getOrElse second }
Expand All @@ -27,9 +26,9 @@ trait Cache[K,V] {
/** This method attempts to use a cached value, if one is found. If
* there is no cached value, the default is used and placed
* back into the cache.
*
*
* Upon any exception, the cache is cleared.
*
*
* TODO - Allow subclasses to handle specific exceptions.
*/
@inline
Expand All @@ -49,7 +48,7 @@ trait Cache[K,V] {
}
}

// TODO - Less ugly/dangerous hack here...
// TODO - Less ugly/dangerous hack here...
// - Expire passwords after N minutes etc.
// - Kill password only on password exceptions.
private[pgp] object PasswordCache extends Cache[String, Array[Char]]
private[sbtpgp] object PasswordCache extends Cache[String, Array[Char]]
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.typesafe.sbt
package com.jsuereth.sbtpgp

import com.typesafe.sbt.pgp._
import sbt._
import sbt.sbtpgp.Compat._

/**
* This class is used to control what we expose to
* This class is used to control what we expose to
* users. It grants access to all our keys in the
* common naming sense of plugins. This is temporary
* until we clean this plugin up for 0.12.0 usage.
Expand All @@ -15,10 +14,8 @@ object SbtPgp extends AutoPlugin {
override def trigger = allRequirements
override def requires = pgpRequires

// Note - workaround for issues in sbt 0.13.5 autoImport
object autoImportImpl {

val PgpKeys = pgp.PgpKeys
object autoImport {
val PgpKeys = com.jsuereth.sbtpgp.PgpKeys

// TODO - Are these ok for style guide? We think so.
def useGpg = PgpKeys.useGpg in Global
Expand All @@ -36,7 +33,6 @@ object SbtPgp extends AutoPlugin {

def signingSettings = PgpSettings.signingSettings
}
val autoImport = autoImportImpl
// TODO - Maybe signing settigns should be a different plugin...
override val projectSettings = PgpSettings.projectSettings
override val globalSettings = PgpSettings.globalSettings
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package com.typesafe.sbt
package pgp
package com.jsuereth.sbtpgp

import sbt._
import sbt.Keys.TaskStreams
Expand Down Expand Up @@ -55,4 +54,4 @@ case class SbtPgpCommandContext(
def log = s.log
// TODO - Is this the right thing to do?
def output[A](msg: => A): Unit = println(msg)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.typesafe.sbt
package com.jsuereth

package object pgp {
package object sbtpgp {
/** Default extension for PGP signatures. */
val gpgExtension = ".asc"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import com.typesafe.sbt.pgp.{SbtPgpCommandContext, PgpKeys}
import com.jsuereth.sbt.pgp.{SbtPgpCommandContext, PgpKeys}

pgpSecretRing := baseDirectory.value / "secring.pgp"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit a8c3fae

Please sign in to comment.