Skip to content

Commit

Permalink
Support both sbt 0.13 and sbt 1.0.0-M5
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n committed May 1, 2017
1 parent 11963a2 commit d1bfc03
Show file tree
Hide file tree
Showing 24 changed files with 265 additions and 133 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@ script:
- sbt scripted
jdk:
- openjdk7
notifications:
email:
- joshua.suereth@gmail.com
10 changes: 9 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ versionWithGit
lazy val library =
Project("library", file("gpg-library")).settings(
name := "pgp-library",
// scalaVersion := "2.12.2",
libraryDependencies ++= Seq(bouncyCastlePgp, gigahorseOkhttp,
specs2 % Test, sbtIo % Test),
libraryDependencies ++= {
Expand All @@ -28,7 +29,14 @@ lazy val plugin =
settings(
sbtPlugin := true,
name := "sbt-pgp",
libraryDependencies ++= Seq(gigahorseOkhttp, sbtCoreNext.value),
// scalaVersion := "2.12.2",
libraryDependencies += gigahorseOkhttp,
libraryDependencies ++= {
(sbtBinaryVersion in pluginCrossBuild).value match {
case "0.13" => Seq(sbtCoreNext.value)
case _ => Nil
}
},
publishLocal := publishLocal.dependsOn(publishLocal in library).value
).
//settings(websiteSettings:_*).
Expand Down
38 changes: 38 additions & 0 deletions pgp-plugin/src/main/scala-sbt-0.13/Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package sbt
package sbtpgp

import sbt.plugins.CommandLineUIServices

object Compat {
type PublishConfiguration = sbt.PublishConfiguration
val defaultProgress = EvaluateTask.defaultProgress
type InteractionService = sbt.InteractionService
def defaultInteraction: InteractionService = CommandLineUIServices
val interactionService = InteractionServiceKeys.interactionService

def pgpRequires: Plugins = sbt.plugins.IvyPlugin && sbt.plugins.InteractionServicePlugin

def compatSettings: Vector[Def.Setting[_]] = Vector()

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

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

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

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

def mkInlineConfiguration(base: ModuleID, deps: Vector[ModuleID],
ivyScala: Option[IvyScala], confs: Vector[Configuration]): InlineConfiguration =
InlineConfiguration(base, ModuleInfo(base.name), deps).copy(ivyScala = ivyScala, configurations = confs)

implicit def log2ProcessLogger(log: Logger): sys.process.ProcessLogger =
new BufferedLogger(new FullLogger(log)) with sys.process.ProcessLogger {
def err(s: => String): Unit = error(s)
def out(s: => String): Unit = info(s)
}
}
50 changes: 50 additions & 0 deletions pgp-plugin/src/main/scala-sbt-1.0.0-M5/Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package sbt
package sbtpgp

import sbt.{ librarymanagement => lm }
import sbt.internal.{ librarymanagement => ilm }

object Compat {
val IvyActions = ilm.IvyActions
type PublishConfiguration = ilm.PublishConfiguration
type IvySbt = ilm.IvySbt
type IvyScala = lm.IvyScala
type UpdateConfiguration = lm.UpdateConfiguration
type InlineConfiguration = ilm.InlineConfiguration
val InlineConfiguration = ilm.InlineConfiguration
val defaultProgress = EvaluateTask.defaultProgress
type InteractionService = sbt.sbtpgp.InteractionService

def pgpRequires: Plugins = sbt.plugins.IvyPlugin

val interactionService = taskKey[InteractionService]("Service used to ask for user input through the current user interface(s).")

def compatSettings: Vector[Def.Setting[_]] =
Vector(
interactionService := defaultInteraction
)

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 =
InlineConfiguration(false, None, base, ModuleInfo(base.name), deps)
.withIvyScala(ivyScala)
.withConfigurations(confs)

private lazy val commandLineUIServices: InteractionService = new CommandLineUIServices
def defaultInteraction: InteractionService = commandLineUIServices
}
31 changes: 31 additions & 0 deletions pgp-plugin/src/main/scala-sbt-1.0.0-M5/InteractionService.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package sbt
package sbtpgp

trait InteractionService {
/** Prompts the user for input, optionally with a mask for characters. */
def readLine(prompt: String, mask: Boolean): Option[String]
/** Ask the user to confirm something (yes or no) before continuing. */
def confirm(msg: String): Boolean
}

class CommandLineUIServices extends InteractionService {
def readLine(prompt: String, mask: Boolean): Option[String] =
{
val maskChar = if (mask) Some('*')
else None
SimpleReader.readLine(prompt, maskChar)
}

def confirm(msg: String): Boolean =
{
object Assent {
def unapply(in: String): Boolean = {
(in == "y" || in == "yes")
}
}
SimpleReader.readLine(msg + " (yes/no): ", None) match {
case Some(Assent()) => true
case _ => false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ 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 _ => Seq.empty
case _: Throwable => Seq.empty
}
/** Parser for existing public key ids. */
def existingPublicKeyId(ctx: PgpStaticContext) =
Expand All @@ -23,9 +23,9 @@ 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 _ => Seq.empty
case _: Throwable => Seq.empty
}

def existingKeyIdOrUser(ctx: PgpStaticContext): Parser[String] =
Expand All @@ -42,7 +42,7 @@ object CommonParsers {
val value = token(NotSpace, "<attribute value>")
(name ~ ((Space.? ~ "->" ~ Space.?) ~> value)) map { case k ~ v => k -> v }
}
lazy val message = token(("message" ~ "=" ~ "\"") map { case _ => () }) ~> (any & not('"')).+.string <~ '"'
lazy val message = token(("message" ~ "=" ~ "\"") map { case _ => () }) ~> (any & not('"', "Expected \".")).+.string <~ '"'
// TODO - better base directory
lazy val filename = fileParser(new java.io.File("."))
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object Display {
val date = new java.text.SimpleDateFormat("yyyy-MM-dd").format(k.getCreationTime)
val userStrings =
if(k.userIDs.isEmpty) ""
else k.userIDs.map("uid\t \t" +).mkString("","\n","\n")
else k.userIDs.map("uid\t \t" + _).mkString("","\n","\n")
head +"\t"+ strength +"/" + hexkey +"\t"+ date + "\n" + userStrings
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package cli
import sbt._
import sbt.complete._
import sbt.complete.DefaultParsers._
import CommonParsers._

/** Constructs a new PGP key from user input. */
case class GeneratePgpKey() extends PgpCommand {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package cli
import sbt._
import sbt.complete._
import sbt.complete.DefaultParsers._
import CommonParsers._

case class ListKeys() extends PgpCommand {
def run(ctx: PgpCommandContext): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package cli
import sbt._
import sbt.complete._
import sbt.complete.DefaultParsers._
import CommonParsers._

/** Lists Signatures on a file. */
case class ListSigs() extends PgpCommand {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ case class SignKey(pubKey: String, notation: (String,String)) extends PgpCommand
try {
ctx.secretKeyRing.secretKey.signPublicKey(key, notation, pw)
} catch {
case t =>
case t: Throwable =>
ctx.log.trace(t)
ctx.log.error("Error signing key!")
throw t
Expand Down
2 changes: 0 additions & 2 deletions pgp-plugin/src/main/scala/com/jsuereth/pgp/cli/commands.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.jsuereth.pgp
package cli

import sbt._
import sbt.complete._
import sbt.complete.DefaultParsers._
import CommonParsers._

/** Represents a PgpCommand */
trait PgpCommand {
Expand Down
4 changes: 0 additions & 4 deletions pgp-plugin/src/main/scala/com/jsuereth/pgp/cli/context.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package com.jsuereth.pgp
package cli

import sbt._
import sbt.complete._
import sbt.complete.DefaultParsers._
import CommonParsers._
import org.bouncycastle.openpgp.PGPPublicKeyRing


/** A context for accepting user input. */
Expand Down
16 changes: 5 additions & 11 deletions pgp-plugin/src/main/scala/com/typesafe/sbt/SbtPgp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ package com.typesafe.sbt

import com.typesafe.sbt.pgp._
import sbt._
import Keys._
import sbt.Project.Initialize
import complete.Parser
import complete.DefaultParsers._
import SbtHelpers._
import PgpKeys._
import sbt.sbtpgp.Compat._

/**
* This class is used to control what we expose to
Expand All @@ -18,13 +13,13 @@ import PgpKeys._
object SbtPgp extends AutoPlugin {

override def trigger = allRequirements
override def requires = sbt.plugins.InteractionServicePlugin && sbt.plugins.IvyPlugin
override def requires = pgpRequires

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

val PgpKeys = pgp.PgpKeys

// TODO - Are these ok for style guide? We think so.
def useGpg = PgpKeys.useGpg in Global
def useGpgAgent = PgpKeys.useGpgAgent in Global
Expand All @@ -44,6 +39,5 @@ object SbtPgp extends AutoPlugin {
// TODO - Maybe signing settigns should be a different plugin...
override val projectSettings = PgpSettings.projectSettings
override val buildSettings = PgpSettings.globalSettings


override val globalSettings = compatSettings
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package pgp


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

/** SBT Keys for the PGP plugin. */
object PgpKeys {
Expand Down
Loading

0 comments on commit d1bfc03

Please sign in to comment.