Skip to content

Commit d1bfc03

Browse files
committed
Support both sbt 0.13 and sbt 1.0.0-M5
1 parent 11963a2 commit d1bfc03

24 files changed

+265
-133
lines changed

.travis.yml

-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,3 @@ script:
55
- sbt scripted
66
jdk:
77
- openjdk7
8-
notifications:
9-
email:
10-

build.sbt

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ versionWithGit
1111
lazy val library =
1212
Project("library", file("gpg-library")).settings(
1313
name := "pgp-library",
14+
// scalaVersion := "2.12.2",
1415
libraryDependencies ++= Seq(bouncyCastlePgp, gigahorseOkhttp,
1516
specs2 % Test, sbtIo % Test),
1617
libraryDependencies ++= {
@@ -28,7 +29,14 @@ lazy val plugin =
2829
settings(
2930
sbtPlugin := true,
3031
name := "sbt-pgp",
31-
libraryDependencies ++= Seq(gigahorseOkhttp, sbtCoreNext.value),
32+
// scalaVersion := "2.12.2",
33+
libraryDependencies += gigahorseOkhttp,
34+
libraryDependencies ++= {
35+
(sbtBinaryVersion in pluginCrossBuild).value match {
36+
case "0.13" => Seq(sbtCoreNext.value)
37+
case _ => Nil
38+
}
39+
},
3240
publishLocal := publishLocal.dependsOn(publishLocal in library).value
3341
).
3442
//settings(websiteSettings:_*).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package sbt
2+
package sbtpgp
3+
4+
import sbt.plugins.CommandLineUIServices
5+
6+
object Compat {
7+
type PublishConfiguration = sbt.PublishConfiguration
8+
val defaultProgress = EvaluateTask.defaultProgress
9+
type InteractionService = sbt.InteractionService
10+
def defaultInteraction: InteractionService = CommandLineUIServices
11+
val interactionService = InteractionServiceKeys.interactionService
12+
13+
def pgpRequires: Plugins = sbt.plugins.IvyPlugin && sbt.plugins.InteractionServicePlugin
14+
15+
def compatSettings: Vector[Def.Setting[_]] = Vector()
16+
17+
def subConfiguration(m: ModuleID, confs: Boolean): ModuleID =
18+
m.copy(configurations = if (confs) m.configurations else None)
19+
20+
def subExplicitArtifacts(m: ModuleID, artifacts: Vector[Artifact]): ModuleID =
21+
m.copy(explicitArtifacts = artifacts)
22+
23+
def subExtension(art: Artifact, ext: String): Artifact =
24+
art.copy(extension = ext)
25+
26+
def subMissingOk(c: UpdateConfiguration, ok: Boolean): UpdateConfiguration =
27+
c.copy(missingOk = ok)
28+
29+
def mkInlineConfiguration(base: ModuleID, deps: Vector[ModuleID],
30+
ivyScala: Option[IvyScala], confs: Vector[Configuration]): InlineConfiguration =
31+
InlineConfiguration(base, ModuleInfo(base.name), deps).copy(ivyScala = ivyScala, configurations = confs)
32+
33+
implicit def log2ProcessLogger(log: Logger): sys.process.ProcessLogger =
34+
new BufferedLogger(new FullLogger(log)) with sys.process.ProcessLogger {
35+
def err(s: => String): Unit = error(s)
36+
def out(s: => String): Unit = info(s)
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package sbt
2+
package sbtpgp
3+
4+
import sbt.{ librarymanagement => lm }
5+
import sbt.internal.{ librarymanagement => ilm }
6+
7+
object Compat {
8+
val IvyActions = ilm.IvyActions
9+
type PublishConfiguration = ilm.PublishConfiguration
10+
type IvySbt = ilm.IvySbt
11+
type IvyScala = lm.IvyScala
12+
type UpdateConfiguration = lm.UpdateConfiguration
13+
type InlineConfiguration = ilm.InlineConfiguration
14+
val InlineConfiguration = ilm.InlineConfiguration
15+
val defaultProgress = EvaluateTask.defaultProgress
16+
type InteractionService = sbt.sbtpgp.InteractionService
17+
18+
def pgpRequires: Plugins = sbt.plugins.IvyPlugin
19+
20+
val interactionService = taskKey[InteractionService]("Service used to ask for user input through the current user interface(s).")
21+
22+
def compatSettings: Vector[Def.Setting[_]] =
23+
Vector(
24+
interactionService := defaultInteraction
25+
)
26+
27+
def subConfiguration(m: ModuleID, confs: Boolean): ModuleID =
28+
m.withConfigurations(
29+
if (confs) m.configurations
30+
else None
31+
)
32+
33+
def subExplicitArtifacts(m: ModuleID, artifacts: Vector[Artifact]): ModuleID =
34+
m.withExplicitArtifacts(artifacts)
35+
36+
def subExtension(art: Artifact, ext: String): Artifact =
37+
art.withExtension(ext)
38+
39+
def subMissingOk(c: UpdateConfiguration, ok: Boolean): UpdateConfiguration =
40+
c.withMissingOk(ok)
41+
42+
def mkInlineConfiguration(base: ModuleID, deps: Vector[ModuleID],
43+
ivyScala: Option[IvyScala], confs: Vector[Configuration]): InlineConfiguration =
44+
InlineConfiguration(false, None, base, ModuleInfo(base.name), deps)
45+
.withIvyScala(ivyScala)
46+
.withConfigurations(confs)
47+
48+
private lazy val commandLineUIServices: InteractionService = new CommandLineUIServices
49+
def defaultInteraction: InteractionService = commandLineUIServices
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package sbt
2+
package sbtpgp
3+
4+
trait InteractionService {
5+
/** Prompts the user for input, optionally with a mask for characters. */
6+
def readLine(prompt: String, mask: Boolean): Option[String]
7+
/** Ask the user to confirm something (yes or no) before continuing. */
8+
def confirm(msg: String): Boolean
9+
}
10+
11+
class CommandLineUIServices extends InteractionService {
12+
def readLine(prompt: String, mask: Boolean): Option[String] =
13+
{
14+
val maskChar = if (mask) Some('*')
15+
else None
16+
SimpleReader.readLine(prompt, maskChar)
17+
}
18+
19+
def confirm(msg: String): Boolean =
20+
{
21+
object Assent {
22+
def unapply(in: String): Boolean = {
23+
(in == "y" || in == "yes")
24+
}
25+
}
26+
SimpleReader.readLine(msg + " (yes/no): ", None) match {
27+
case Some(Assent()) => true
28+
case _ => false
29+
}
30+
}
31+
}

pgp-plugin/src/main/scala/com/jsuereth/pgp/cli/CommonParsers.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ object CommonParsers {
1111

1212
private def hexPublicKeyIds(ctx: PgpStaticContext): Seq[String] =
1313
try {
14-
ctx.publicKeyRing.publicKeys.view map (_.keyID) map ("%x" format (_)) toSeq
14+
(ctx.publicKeyRing.publicKeys.view map (_.keyID) map ("%x" format (_))).toSeq
1515
} catch {
16-
case _ => Seq.empty
16+
case _: Throwable => Seq.empty
1717
}
1818
/** Parser for existing public key ids. */
1919
def existingPublicKeyId(ctx: PgpStaticContext) =
@@ -23,9 +23,9 @@ object CommonParsers {
2323

2424
private def userIds(ctx: PgpStaticContext): Seq[String] =
2525
try {
26-
ctx.publicKeyRing.publicKeys.view flatMap (_.userIDs) toSeq
26+
(ctx.publicKeyRing.publicKeys.view flatMap (_.userIDs)).toSeq
2727
} catch {
28-
case _ => Seq.empty
28+
case _: Throwable => Seq.empty
2929
}
3030

3131
def existingKeyIdOrUser(ctx: PgpStaticContext): Parser[String] =
@@ -42,7 +42,7 @@ object CommonParsers {
4242
val value = token(NotSpace, "<attribute value>")
4343
(name ~ ((Space.? ~ "->" ~ Space.?) ~> value)) map { case k ~ v => k -> v }
4444
}
45-
lazy val message = token(("message" ~ "=" ~ "\"") map { case _ => () }) ~> (any & not('"')).+.string <~ '"'
45+
lazy val message = token(("message" ~ "=" ~ "\"") map { case _ => () }) ~> (any & not('"', "Expected \".")).+.string <~ '"'
4646
// TODO - better base directory
4747
lazy val filename = fileParser(new java.io.File("."))
4848
}

pgp-plugin/src/main/scala/com/jsuereth/pgp/cli/Display.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object Display {
1717
val date = new java.text.SimpleDateFormat("yyyy-MM-dd").format(k.getCreationTime)
1818
val userStrings =
1919
if(k.userIDs.isEmpty) ""
20-
else k.userIDs.map("uid\t \t" +).mkString("","\n","\n")
20+
else k.userIDs.map("uid\t \t" + _).mkString("","\n","\n")
2121
head +"\t"+ strength +"/" + hexkey +"\t"+ date + "\n" + userStrings
2222
}
2323

pgp-plugin/src/main/scala/com/jsuereth/pgp/cli/GeneratePgpKey.scala

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package cli
44
import sbt._
55
import sbt.complete._
66
import sbt.complete.DefaultParsers._
7-
import CommonParsers._
87

98
/** Constructs a new PGP key from user input. */
109
case class GeneratePgpKey() extends PgpCommand {

pgp-plugin/src/main/scala/com/jsuereth/pgp/cli/ListKeys.scala

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package cli
44
import sbt._
55
import sbt.complete._
66
import sbt.complete.DefaultParsers._
7-
import CommonParsers._
87

98
case class ListKeys() extends PgpCommand {
109
def run(ctx: PgpCommandContext): Unit = {

pgp-plugin/src/main/scala/com/jsuereth/pgp/cli/ListSigs.scala

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package cli
44
import sbt._
55
import sbt.complete._
66
import sbt.complete.DefaultParsers._
7-
import CommonParsers._
87

98
/** Lists Signatures on a file. */
109
case class ListSigs() extends PgpCommand {

pgp-plugin/src/main/scala/com/jsuereth/pgp/cli/SignKey.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ case class SignKey(pubKey: String, notation: (String,String)) extends PgpCommand
2121
try {
2222
ctx.secretKeyRing.secretKey.signPublicKey(key, notation, pw)
2323
} catch {
24-
case t =>
24+
case t: Throwable =>
2525
ctx.log.trace(t)
2626
ctx.log.error("Error signing key!")
2727
throw t

pgp-plugin/src/main/scala/com/jsuereth/pgp/cli/commands.scala

-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package com.jsuereth.pgp
22
package cli
33

4-
import sbt._
54
import sbt.complete._
65
import sbt.complete.DefaultParsers._
7-
import CommonParsers._
86

97
/** Represents a PgpCommand */
108
trait PgpCommand {

pgp-plugin/src/main/scala/com/jsuereth/pgp/cli/context.scala

-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ package com.jsuereth.pgp
22
package cli
33

44
import sbt._
5-
import sbt.complete._
6-
import sbt.complete.DefaultParsers._
7-
import CommonParsers._
8-
import org.bouncycastle.openpgp.PGPPublicKeyRing
95

106

117
/** A context for accepting user input. */

pgp-plugin/src/main/scala/com/typesafe/sbt/SbtPgp.scala

+5-11
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ package com.typesafe.sbt
22

33
import com.typesafe.sbt.pgp._
44
import sbt._
5-
import Keys._
6-
import sbt.Project.Initialize
7-
import complete.Parser
8-
import complete.DefaultParsers._
9-
import SbtHelpers._
10-
import PgpKeys._
5+
import sbt.sbtpgp.Compat._
116

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

2015
override def trigger = allRequirements
21-
override def requires = sbt.plugins.InteractionServicePlugin && sbt.plugins.IvyPlugin
22-
16+
override def requires = pgpRequires
17+
2318
// Note - workaround for issues in sbt 0.13.5 autoImport
2419
object autoImportImpl {
2520

2621
val PgpKeys = pgp.PgpKeys
27-
22+
2823
// TODO - Are these ok for style guide? We think so.
2924
def useGpg = PgpKeys.useGpg in Global
3025
def useGpgAgent = PgpKeys.useGpgAgent in Global
@@ -44,6 +39,5 @@ object SbtPgp extends AutoPlugin {
4439
// TODO - Maybe signing settigns should be a different plugin...
4540
override val projectSettings = PgpSettings.projectSettings
4641
override val buildSettings = PgpSettings.globalSettings
47-
48-
42+
override val globalSettings = compatSettings
4943
}

pgp-plugin/src/main/scala/com/typesafe/sbt/pgp/PgpKeys.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package pgp
33

44

55
import sbt._
6-
import sbt.Keys._
76
import com.jsuereth.pgp._
87
import KeyRanks._
8+
import sbt.sbtpgp.Compat._
99

1010
/** SBT Keys for the PGP plugin. */
1111
object PgpKeys {

0 commit comments

Comments
 (0)