Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross build to sbt 1.0.0-M5 #39

Merged
merged 1 commit into from
May 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: scala
jdk: oraclejdk8
scala: 2.10.6
script: project/travis.sh

# Build only master and version tags - http://stackoverflow.com/a/31882307/463761
Expand All @@ -13,6 +12,9 @@ env:
global:
- COURSIER_PROGRESS=0
- secure: PJ5eWT7PR7VUFrZiaZ6HvTOk+Is09fvpmHNkhAz25rlwThV+8dSNRiUcJCs7uYi+MrvY5JpsTzDihKq1pPbyYdQUaQvTkAB1BLY6lixleBi0QGk9YS5KyEYr/eLfopqBalRtCu7tViG8Zo23MXGhu4ZBbdrBIJHBJIqAV/q3H90UPasgOYtBPSf0lor0Hevm+lDz+zxYoPfsLqe02KceAJwl8hvwsFl8sFao7V90xvkzA2uTqw+GbZGXZ/hNBnaAYD5j7oipDLvX8YBtS1lQdfl2ZGIpwy5AEyt39jdc718+C8e5xPiU9713ESSLApge6NgVyfZDGd6qZs7Zg/dy2o5w40VJ8qUMK5QMCQuZQVbeYyvXrBd3Ye8zBMu4QoSBM62VtJrWQ3eK9nyaIg8XkBDVWX3YiMSEUyVd8WbzMjpi4yFphLmqqKTHUliQgGGCc/N2Qh9s+o7slX4Ko29qN+OTZOIxIxdr6YRHpb2N/n1b4pDUqDIpsN+UMDA3SpGmKN9INx+/A3gBDhOXPFV/pYVo4yxp/Vs7TMpXoJCef1dCU6mQpOdCHppOSX2Q5a9Qxd31LXTFRcNVihLK6sTq2K3aHGWhI3/uoXSMzvvaFCQpNX0HAluyazryIWh6xTRqMDHAImBbATpOEamr3xt3K7Qo2AJH+8mlwTx0lB4lweE=
matrix:
- TRAVIS_SBT_VERSION=0.13.x
- TRAVIS_SBT_VERSION=1.0.0-M5

cache:
directories:
Expand Down
13 changes: 9 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ organization := "com.dwijnand"
scmInfo := Some(ScmInfo(url("https://github.com/dwijnand/sbt-dynver"), "scm:git:[email protected]:dwijnand/sbt-dynver.git"))

sbtPlugin := true
scalaVersion := "2.10.6"
scalaVersion := (sbtVersionSeries.value match { case Sbt013 => "2.10.6"; case Sbt1 => "2.12.2" })

maxErrors := 15
triggeredMessage := Watched.clearWhenTriggered
Expand All @@ -24,7 +24,7 @@ scalacOptions += "-Ywarn-numeric-widen"
scalacOptions += "-Ywarn-value-discard"

libraryDependencies += "org.eclipse.jgit" % "org.eclipse.jgit" % "4.4.1.201607150455-r" % Test
libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.13.2" % Test
libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.13.5" % Test

fork in Test := false
logBuffered in Test := false
Expand All @@ -38,13 +38,18 @@ def toSbtPlugin(m: ModuleID) = Def.setting(
Defaults.sbtPluginExtra(m, (sbtBinaryVersion in update).value, (scalaBinaryVersion in update).value)
)
import com.typesafe.tools.mima.core._, ProblemFilters._
mimaPreviousArtifacts := Set(toSbtPlugin("com.dwijnand" % "sbt-dynver" % "1.2.0").value)
mimaPreviousArtifacts := (sbtVersionSeries.value match {
case Sbt013 => Set(toSbtPlugin("com.dwijnand" % "sbt-dynver" % "1.2.0").value)
case Sbt1 => Set.empty
})
mimaBinaryIssueFilters ++= Seq(
exclude[MissingTypesProblem]("sbtdynver.DynVer$"), // dropped synthetic abstract function parent
exclude[MissingTypesProblem]("sbtdynver.GitRef$"), // dropped synthetic abstract function parent
exclude[MissingTypesProblem]("sbtdynver.GitCommitSuffix$"), // dropped synthetic abstract function parent
exclude[MissingTypesProblem]("sbtdynver.GitDirtySuffix$"), // dropped synthetic abstract function parent
exclude[DirectMissingMethodProblem]("sbtdynver.package.timestamp") // dropped package private method
exclude[DirectMissingMethodProblem]("sbtdynver.package.timestamp"), // dropped package private method
exclude[MissingClassProblem]("sbtdynver.NoProcessLogger$"), // sbt1 killed sbt.ProcessLogger so moved to impl
exclude[MissingClassProblem]("sbtdynver.NoProcessLogger") // sbt1 killed sbt.ProcessLogger so moved to impl
)

TaskKey[Unit]("verify") := Def.sequential(test in Test, scripted.toTask(""), mimaReportBinaryIssues).value
Expand Down
3 changes: 2 additions & 1 deletion notes/1.3.0.markdown
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### Improvements

- Introduce `GitRef.isTag` & `GitCommitSuffix.isEmpty` utilities. [#34][] by [@dwijnand][]
- Introduces `GitRef.isTag` & `GitCommitSuffix.isEmpty` utilities. [#34][] by [@dwijnand][]
- Cross builds against sbt 1.0.0-M5

[#34]: https://github.com/dwijnand/sbt-dynver/pull/34
[@dwijnand]: https://github.com/dwijnand
25 changes: 25 additions & 0 deletions project/CrossBuildingPlugin.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sbt._, Keys._

sealed trait SbtVersionSeries
case object Sbt013 extends SbtVersionSeries
case object Sbt1 extends SbtVersionSeries

object CrossBuildingPlugin extends AutoPlugin {
override def requires = plugins.JvmPlugin
override def trigger = allRequirements

object autoImport {
val sbtPartV = settingKey[Option[(Int, Int)]]("")
val sbtVersionSeries = settingKey[SbtVersionSeries]("")
}
import autoImport._

override def globalSettings = Seq(
sbtPartV := CrossVersion partialVersion (sbtVersion in pluginCrossBuild).value,
sbtVersionSeries := (sbtPartV.value match {
case Some((0, 13)) => Sbt013
case Some((1, _)) => Sbt1
case _ => sys error s"Unhandled sbt version ${(sbtVersion in pluginCrossBuild).value}"
})
)
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.13
sbt.version=0.13.16-M1
8 changes: 7 additions & 1 deletion project/travis.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/usr/bin/env bash

if [[ "$TRAVIS_SBT_VERSION" == "0.13.x" ]]; then
SWITCH_SBT_VERSION=""
else
SWITCH_SBT_VERSION="^^$TRAVIS_SBT_VERSION"
fi

[[ "$TRAVIS_PULL_REQUEST" == "false"
&& "$TRAVIS_BRANCH" == "master"
&& "$TRAVIS_SECURE_ENV_VARS" == "true"
Expand All @@ -24,4 +30,4 @@ else
PUBLISH=publishLocal
fi

sbt ++$TRAVIS_SCALA_VERSION verify "$PUBLISH"
sbt "$SWITCH_SBT_VERSION" verify "$PUBLISH"
16 changes: 10 additions & 6 deletions src/main/scala/sbtdynver/DynVerPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ sealed case class DynVer(wd: Option[File]) {
def hasNoTags(): Boolean = getGitDescribeOutput(new Date).hasNoTags

def getGitDescribeOutput(d: Date) = {
val process = Process(s"""git describe --tags --abbrev=8 --match v[0-9]* --always --dirty=+${timestamp(d)}""", wd)
Try(process !! NoProcessLogger).toOption
val process = scala.sys.process.Process(s"""git describe --tags --abbrev=8 --match v[0-9]* --always --dirty=+${timestamp(d)}""", wd)
Try(process !! impl.NoProcessLogger).toOption
.map(_.replaceAll("-([0-9]+)-g([0-9a-f]{8})", "+$1-$2"))
.map(GitDescribeOutput.parse)
}
Expand All @@ -124,8 +124,12 @@ object DynVer extends DynVer(None) with (Option[File] => DynVer)

object `package`

object NoProcessLogger extends ProcessLogger {
def info(s: => String) = ()
def error(s: => String) = ()
def buffer[T](f: => T) = f
package impl {
object NoProcessLogger extends scala.sys.process.ProcessLogger {
def info(s: => String) = ()
def out(s: => String) = ()
def error(s: => String) = ()
def err(s: => String) = ()
def buffer[T](f: => T) = f
}
}
30 changes: 26 additions & 4 deletions src/sbt-test/dynver/custom-version-string-0/build.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import scala.sys.process.stringToProcess

version in ThisBuild ~= (_.replace('+', '-'))
dynver in ThisBuild ~= (_.replace('+', '-'))

def tstamp = Def.setting(sbtdynver.DynVer timestamp dynverCurrentDate.value)
def headSha = Def.task("git rev-parse --short=8 HEAD".!!(streams.value.log).trim)
def headSha = {
implicit def log2log(log: Logger): scala.sys.process.ProcessLogger = sbtLoggerToScalaSysProcessLogger(log)
Def.task("git rev-parse --short=8 HEAD".!!(streams.value.log).trim)
}

def check(a: String, e: String) = assert(a == e, s"Version mismatch: Expected $e, Incoming $a")

Expand All @@ -16,17 +21,34 @@ TaskKey[Unit]("checkOnTagAndCommit") := check(version.value, s"1.0.0-1-${he
TaskKey[Unit]("checkOnTagAndCommitDirty") := check(version.value, s"1.0.0-1-${headSha.value}-${tstamp.value}")

TaskKey[Unit]("gitInitSetup") := {
implicit def log2log(log: Logger): scala.sys.process.ProcessLogger = sbtLoggerToScalaSysProcessLogger(log)
"git init".!!(streams.value.log)
"git config user.email [email protected]".!!(streams.value.log)
"git config user.name dynver".!!(streams.value.log)
}

TaskKey[Unit]("gitAdd") := "git add .".!!(streams.value.log)
TaskKey[Unit]("gitCommit") := "git commit -am1".!!(streams.value.log)
TaskKey[Unit]("gitTag") := "git tag -a v1.0.0 -m1.0.0".!!(streams.value.log)
TaskKey[Unit]("gitAdd") := {
implicit def log2log(log: Logger): scala.sys.process.ProcessLogger = sbtLoggerToScalaSysProcessLogger(log)
"git add .".!!(streams.value.log)
}
TaskKey[Unit]("gitCommit") := {
implicit def log2log(log: Logger): scala.sys.process.ProcessLogger = sbtLoggerToScalaSysProcessLogger(log)
"git commit -am1".!!(streams.value.log)
}
TaskKey[Unit]("gitTag") := {
implicit def log2log(log: Logger): scala.sys.process.ProcessLogger = sbtLoggerToScalaSysProcessLogger(log)
"git tag -a v1.0.0 -m1.0.0".!!(streams.value.log)
}

TaskKey[Unit]("dirty") := {
import java.nio.file._, StandardOpenOption._
import scala.collection.JavaConverters._
Files.write(baseDirectory.value.toPath.resolve("f.txt"), Seq("1").asJava, CREATE, APPEND)
}

def sbtLoggerToScalaSysProcessLogger(log: Logger): scala.sys.process.ProcessLogger =
new scala.sys.process.ProcessLogger {
def buffer[T](f: => T): T = f
def err(s: => String): Unit = log info s
def out(s: => String): Unit = log error s
}
30 changes: 26 additions & 4 deletions src/sbt-test/dynver/custom-version-string/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import scala.sys.process.stringToProcess

def versionFmt(out: sbtdynver.GitDescribeOutput): String =
out.ref.dropV.value + out.commitSuffix.mkString("-", "-", "") + out.dirtySuffix.dropPlus.mkString("-", "")

Expand All @@ -12,7 +14,10 @@ inThisBuild(List(
))

def tstamp = Def.setting(sbtdynver.DynVer timestamp dynverCurrentDate.value)
def headSha = Def.task("git rev-parse --short=8 HEAD".!!(streams.value.log).trim)
def headSha = {
implicit def log2log(log: Logger): scala.sys.process.ProcessLogger = sbtLoggerToScalaSysProcessLogger(log)
Def.task("git rev-parse --short=8 HEAD".!!(streams.value.log).trim)
}

def check(a: String, e: String) = assert(a == e, s"Version mismatch: Expected $e, Incoming $a")

Expand All @@ -26,17 +31,34 @@ TaskKey[Unit]("checkOnTagAndCommit") := check(version.value, s"1.0.0-1-${he
TaskKey[Unit]("checkOnTagAndCommitDirty") := check(version.value, s"1.0.0-1-${headSha.value}-${tstamp.value}")

TaskKey[Unit]("gitInitSetup") := {
implicit def log2log(log: Logger): scala.sys.process.ProcessLogger = sbtLoggerToScalaSysProcessLogger(log)
"git init".!!(streams.value.log)
"git config user.email [email protected]".!!(streams.value.log)
"git config user.name dynver".!!(streams.value.log)
}

TaskKey[Unit]("gitAdd") := "git add .".!!(streams.value.log)
TaskKey[Unit]("gitCommit") := "git commit -am1".!!(streams.value.log)
TaskKey[Unit]("gitTag") := "git tag -a v1.0.0 -m1.0.0".!!(streams.value.log)
TaskKey[Unit]("gitAdd") := {
implicit def log2log(log: Logger): scala.sys.process.ProcessLogger = sbtLoggerToScalaSysProcessLogger(log)
"git add .".!!(streams.value.log)
}
TaskKey[Unit]("gitCommit") := {
implicit def log2log(log: Logger): scala.sys.process.ProcessLogger = sbtLoggerToScalaSysProcessLogger(log)
"git commit -am1".!!(streams.value.log)
}
TaskKey[Unit]("gitTag") := {
implicit def log2log(log: Logger): scala.sys.process.ProcessLogger = sbtLoggerToScalaSysProcessLogger(log)
"git tag -a v1.0.0 -m1.0.0".!!(streams.value.log)
}

TaskKey[Unit]("dirty") := {
import java.nio.file._, StandardOpenOption._
import scala.collection.JavaConverters._
Files.write(baseDirectory.value.toPath.resolve("f.txt"), Seq("1").asJava, CREATE, APPEND)
}

def sbtLoggerToScalaSysProcessLogger(log: Logger): scala.sys.process.ProcessLogger =
new scala.sys.process.ProcessLogger {
def buffer[T](f: => T): T = f
def err(s: => String): Unit = log info s
def out(s: => String): Unit = log error s
}
30 changes: 26 additions & 4 deletions src/sbt-test/dynver/versions/build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import scala.sys.process.stringToProcess

def tstamp = Def.setting(sbtdynver.DynVer timestamp dynverCurrentDate.value)
def headSha = Def.task("git rev-parse --short=8 HEAD".!!(streams.value.log).trim)
def headSha = {
implicit def log2log(log: Logger): scala.sys.process.ProcessLogger = sbtLoggerToScalaSysProcessLogger(log)
Def.task("git rev-parse --short=8 HEAD".!!(streams.value.log).trim)
}

def check(a: String, e: String) = assert(a == e, s"Version mismatch: Expected $e, Incoming $a")

Expand All @@ -13,17 +18,34 @@ TaskKey[Unit]("checkOnTagAndCommit") := check(version.value, s"1.0.0+1-${he
TaskKey[Unit]("checkOnTagAndCommitDirty") := check(version.value, s"1.0.0+1-${headSha.value}+${tstamp.value}")

TaskKey[Unit]("gitInitSetup") := {
implicit def log2log(log: Logger): scala.sys.process.ProcessLogger = sbtLoggerToScalaSysProcessLogger(log)
"git init".!!(streams.value.log)
"git config user.email [email protected]".!!(streams.value.log)
"git config user.name dynver".!!(streams.value.log)
}

TaskKey[Unit]("gitAdd") := "git add .".!!(streams.value.log)
TaskKey[Unit]("gitCommit") := "git commit -am1".!!(streams.value.log)
TaskKey[Unit]("gitTag") := "git tag -a v1.0.0 -m1.0.0".!!(streams.value.log)
TaskKey[Unit]("gitAdd") := {
implicit def log2log(log: Logger): scala.sys.process.ProcessLogger = sbtLoggerToScalaSysProcessLogger(log)
"git add .".!!(streams.value.log)
}
TaskKey[Unit]("gitCommit") := {
implicit def log2log(log: Logger): scala.sys.process.ProcessLogger = sbtLoggerToScalaSysProcessLogger(log)
"git commit -am1".!!(streams.value.log)
}
TaskKey[Unit]("gitTag") := {
implicit def log2log(log: Logger): scala.sys.process.ProcessLogger = sbtLoggerToScalaSysProcessLogger(log)
"git tag -a v1.0.0 -m1.0.0".!!(streams.value.log)
}

TaskKey[Unit]("dirty") := {
import java.nio.file._, StandardOpenOption._
import scala.collection.JavaConverters._
Files.write(baseDirectory.value.toPath.resolve("f.txt"), Seq("1").asJava, CREATE, APPEND)
}

def sbtLoggerToScalaSysProcessLogger(log: Logger): scala.sys.process.ProcessLogger =
new scala.sys.process.ProcessLogger {
def buffer[T](f: => T): T = f
def err(s: => String): Unit = log info s
def out(s: => String): Unit = log error s
}