diff --git a/config/build.sbt b/config/build.sbt index 3ba96cdb..45b4932b 100644 --- a/config/build.sbt +++ b/config/build.sbt @@ -30,4 +30,4 @@ parallelExecution in Test := false sources in (Compile, doc) ~= (_.filter(_.getParentFile.getName != "impl")) -JavaVersionCheck.javacVersionCheckSettings +javaVersionPrefix in javaVersionCheck := Some("1.6") diff --git a/project/Build.scala b/project/Build.scala index 83e26ab4..e17e788d 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -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")) diff --git a/project/JavaVersionCheck.scala b/project/JavaVersionCheck.scala deleted file mode 100644 index e614dcfe..00000000 --- a/project/JavaVersionCheck.scala +++ /dev/null @@ -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 - } - ) -} diff --git a/project/plugins.sbt b/project/plugins.sbt index ef03f11a..943763fe 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -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")