Replace JavaVersionCheck with sbt-javaversioncheck.

This commit is contained in:
Dale Wijnand 2015-01-27 00:26:31 +00:00
parent ad63b52073
commit 65ff5f9f2c
4 changed files with 7 additions and 64 deletions

View File

@ -30,4 +30,4 @@ parallelExecution in Test := false
sources in (Compile, doc) ~= (_.filter(_.getParentFile.getName != "impl"))
JavaVersionCheck.javacVersionCheckSettings
javaVersionPrefix in javaVersionCheck := Some("1.6")

View File

@ -1,6 +1,7 @@
import sbt._
import Keys._
import com.typesafe.sbt.osgi.SbtOsgi.{ OsgiKeys, osgiSettings }
import com.typesafe.sbt.JavaVersionCheckPlugin.autoImport._
object ConfigBuild extends Build {
val unpublished = Seq(
@ -26,8 +27,10 @@ object ConfigBuild extends Build {
override val settings = super.settings ++ Seq(isSnapshot <<= isSnapshot or version(_ endsWith "-SNAPSHOT"))
lazy val commonSettings: Seq[Setting[_]] = unpublished ++ Seq(javaVersionPrefix in javaVersionCheck := None)
lazy val rootSettings: Seq[Setting[_]] =
unpublished ++
commonSettings ++
Seq(aggregate in doc := false,
doc := (doc in (configLib, Compile)).value,
aggregate in packageDoc := false,
@ -52,7 +55,7 @@ object ConfigBuild extends Build {
publishLocal := sys.error("use publishLocalSigned instead of plain publishLocal")
)) dependsOn testLib % "test->test"
def project(id: String, base: File) = Project(id, base, settings = unpublished)
def project(id: String, base: File) = Project(id, base, settings = commonSettings)
lazy val testLib = project("config-test-lib", file("test-lib"))

View File

@ -1,61 +0,0 @@
import sbt._
object JavaVersionCheck {
val javacVersionPrefix = taskKey[Option[String]]("java version prefix required by javacVersionCheck")
val javacVersionCheck = taskKey[String]("checks the Java version vs. javacVersionPrefix, returns actual version")
def javacVersionCheckSettings: Seq[Setting[_]] = Seq(
javacVersionPrefix := Some("1.6"),
javacVersionCheck := {
val realLog = Keys.streams.value.log
val javac = (Keys.compileInputs in Keys.compile in Compile).value.compilers.javac
val captureVersionLog = new sbt.Logger() {
var captured: Option[String] = None
def log(level: sbt.Level.Value,message: => String): Unit = {
val m = message
if (level == Level.Warn && m.startsWith("javac ")) {
captured = Some(m.substring("javac ".length).trim)
} else {
realLog.log(level, m)
}
}
def success(message: => String): Unit = realLog.success(message)
def trace(t: => Throwable): Unit = realLog.trace(t)
}
javac(sources=Nil, classpath=Nil, outputDirectory=file("."), options=Seq("-version"))(captureVersionLog)
val version = captureVersionLog.captured match {
case Some(v) => v
case None =>
throw new Exception("Failed to get or parse the output of javac -version")
}
javacVersionPrefix.value match {
case Some(prefix) =>
if (!version.startsWith(prefix)) {
throw new Exception(s"javac version ${version} may not be used to publish, it has to start with ${prefix} due to javacVersionPrefix setting")
}
case None =>
}
version
},
// we hook onto deliverConfiguration to run the version check as early as possible,
// before we actually do anything. But we don't want to require the version check
// just for compile.
Keys.deliverConfiguration := {
val log = Keys.streams.value.log
val javacVersion = javacVersionCheck.value
log.info("Will publish locally with javac version " + javacVersion)
Keys.deliverConfiguration.value
},
Keys.deliverLocalConfiguration := {
val log = Keys.streams.value.log
val javacVersion = javacVersionCheck.value
log.info("Will publish locally with javac version " + javacVersion)
Keys.deliverLocalConfiguration.value
}
)
}

View File

@ -5,3 +5,4 @@ addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.6.0")
resolvers += "jgit-repo" at "http://download.eclipse.org/jgit/maven"
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.6.2")
addSbtPlugin("com.typesafe.sbt" % "sbt-javaversioncheck" % "0.1.0")