Skip to content
This repository has been archived by the owner on Mar 11, 2020. It is now read-only.

Commit

Permalink
Minimum Viable Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
rossabaker committed Feb 22, 2017
1 parent fe0cfa5 commit 3878679
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 0 deletions.
47 changes: 47 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
organization := "io.verizon.build"

name := "sbt-scalaz"

scalacOptions ++= Seq("-deprecation", "-feature")

sbtPlugin := true

ScriptedPlugin.scriptedSettings

scriptedLaunchOpts ++= Seq(
"-Xmx1024M",
"-Dplugin.version=" + version.value,
"-Dscripted=true")

scriptedBufferLog := false

fork := true

licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0.html"))

homepage := Some(url("https://github.com/verizon/sbt-scalaz"))

scmInfo := Some(ScmInfo(url("https://github.com/verizon/sbt-scalaz"),
"git@github.com:verizon/sbt-scalaz.git"))

// To sync with Maven central, you need to supply the following information:
pomExtra in Global := {
<developers>
<developer>
<id>rossabaker</id>
<name>Ross A. Baker</name>
<url>http://rossabaker.com/</url>
</developer>
</developers>
}

sonatypeProfileName := "io.verizon"

pomPostProcess := { identity }

addCommandAlias("validate", ";test;scripted")

addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")

addCommandAlias("validate", ";test;scripted")
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.13
3 changes: 3 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
libraryDependencies += "org.scala-sbt" % "scripted-plugin" % sbtVersion.value

addSbtPlugin("io.verizon.build" % "sbt-rig" % "1.3.27")
57 changes: 57 additions & 0 deletions src/main/scala/ScalazPlugin.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package verizon.build

import sbt._, Keys._

object ScalazPlugin extends AutoPlugin {
object autoImport {
val scalazVersion = settingKey[String]("scalaz version")

val scalazVersionRewriter = settingKey[(String, String) => String]("adjust the version based on a scalaz version")
}

import autoImport._

override def trigger = allRequirements

override lazy val projectSettings = Seq(
scalazVersion := sys.env.get("SCALAZ_VERSION").getOrElse("7.2.7"),
scalazVersionRewriter := scalazBinaryVersionInQualifier,
version := scalazVersionRewriter.value(version.value, scalazVersion.value)
)

val scalazBinaryVersionInQualifier = { (version: String, scalazVersion: String) =>
version match {
case VersionNumber(numbers, tags, extras) =>
val qualifier = scalazVersion match {
case VersionNumber(Seq(zMajor, zMinor, _*), _, _) =>
s"scalaz-$zMajor.$zMinor"
case _ =>
s"scalaz-$scalazVersion"
}
numbers.mkString(".") + (qualifier +: tags).mkString("-", "-", "") + extras.mkString("")
case _ =>
// Can't determine scalaz binary compatibility. *shrug*
s"${version}-scalaz-${scalazVersion}"
}
}

/**
* This convention is prevalent in the community (scalaz-stream,
* http4s < 0.16, argonaut-6.1), but not recommended as it breaks
* semantic versioning.
*/
val scalazSevenTwoSuffixA = { (version: String, scalazVersion: String) =>
VersionNumber(scalazVersion).numbers match {
case Seq(7, 2, _*) =>
version match {
case VersionNumber(numbers, tags, extras) =>
numbers.mkString(".") + "a" + (tags match {
case Seq() => ""
case ts => ts.mkString("-", "-", "")
}) + extras.mkString("")
}
case _ =>
version
}
}
}
9 changes: 9 additions & 0 deletions src/sbt-test/sbt-scalaz/crozz-built/project.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import verizon.build.ScalazPlugin

version in ThisBuild := "0.1.0"

TaskKey[Unit]("check") := {
val expectedVersion = "0.1.0-scalaz-7.2"
if (version.value != expectedVersion)
sys.error(s"""Expected version "${expectedVersion}", got "${version.value}""")
}
7 changes: 7 additions & 0 deletions src/sbt-test/sbt-scalaz/crozz-built/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
val pluginVersion = System.getProperty("plugin.version")
if(pluginVersion == null)
throw new RuntimeException("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
else addSbtPlugin("io.verizon.build" % "sbt-scalaz" % pluginVersion)
}
2 changes: 2 additions & 0 deletions src/sbt-test/sbt-scalaz/crozz-built/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> check

30 changes: 30 additions & 0 deletions src/test/scala/ScalazPluginSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package verizon.build

import org.scalatest.{FlatSpec, Matchers}
import ScalazPlugin._

class ScalazPluginSpec extends FlatSpec with Matchers {
behavior of "scalazBinaryVersionInQualifier"

it should "put the scalaz binary version after the version" in {
scalazBinaryVersionInQualifier("0.1.0", "7.2.7") should be ("0.1.0-scalaz-7.2")
}

it should "put the scalaz binary version before SNAPSHOT" in {
scalazBinaryVersionInQualifier("0.1.0-SNAPSHOT", "7.2.7") should be ("0.1.0-scalaz-7.2-SNAPSHOT")
}

behavior of "scalazSevenTwoSuffixA"

it should "not mark scalaz-7.1" in {
scalazSevenTwoSuffixA("0.1.0", "7.1.11") should be ("0.1.0")
}

it should "put the 'a' suffix after the version" in {
scalazSevenTwoSuffixA("0.1.0", "7.2.7") should be ("0.1.0a")
}

it should "put the 'a' suffix before SNAPSHOT" in {
scalazSevenTwoSuffixA("0.1.0-SNAPSHOT", "7.2.7") should be ("0.1.0a-SNAPSHOT")
}
}
1 change: 1 addition & 0 deletions version.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version in ThisBuild := "0.1.0-SNAPSHOT"

0 comments on commit 3878679

Please sign in to comment.