From 0b33c195efa861d2ec83de284dbab4a56fda15e6 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Wed, 3 May 2017 15:52:36 +0100 Subject: [PATCH] Upgrade the build to sbt 1.0.0-M5 Some plugins remain commented out, for now. sbt-doge is no longer needed because a variant of it has been folded into sbt 1. For some reason scripted requires src/doc jars of sbt, so switch back to using `publishAll` rather than `publishLocalBinAll`. :( Also, the sys.prop change in scripted is to force log4j2 to not use a thread context classloader, and avoid the following: ERROR StatusLogger Unable to create custom ContextSelector. Falling back to default. java.lang.ClassCastException: Cannot cast org.apache.logging.log4j.core.async.AsyncLoggerContextSelector to org.apache.logging.log4j.core.selector.ContextSelector at java.lang.Class.cast(Class.java:3369) at org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOf(LoaderUtil.java:201) at org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOfProperty(LoaderUtil.java:226) at org.apache.logging.log4j.core.impl.Log4jContextFactory.createContextSelector(Log4jContextFactory.java:97) at org.apache.logging.log4j.core.impl.Log4jContextFactory.(Log4jContextFactory.java:58) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at java.lang.Class.newInstance(Class.java:442) at org.apache.logging.log4j.LogManager.(LogManager.java:94) at org.apache.logging.log4j.spi.ThreadContextMapFactory.createThreadContextMap(ThreadContextMapFactory.java:73) at org.apache.logging.log4j.ThreadContext.init(ThreadContext.java:223) at org.apache.logging.log4j.ThreadContext.(ThreadContext.java:202) at org.apache.logging.log4j.core.impl.ContextDataInjectorFactory.createDefaultInjector(ContextDataInjectorFactory.java:83) at org.apache.logging.log4j.core.impl.ContextDataInjectorFactory.createInjector(ContextDataInjectorFactory.java:67) at org.apache.logging.log4j.core.lookup.ContextMapLookup.(ContextMapLookup.java:34) at org.apache.logging.log4j.core.lookup.Interpolator.(Interpolator.java:117) at org.apache.logging.log4j.core.config.AbstractConfiguration.(AbstractConfiguration.java:125) at org.apache.logging.log4j.core.config.DefaultConfiguration.(DefaultConfiguration.java:46) at org.apache.logging.log4j.core.layout.PatternLayout$Builder.build(PatternLayout.java:650) at org.apache.logging.log4j.core.layout.PatternLayout.createDefaultLayout(PatternLayout.java:487) at sbt.internal.util.ConsoleAppender.(ConsoleAppender.scala:245) at sbt.internal.util.ConsoleAppender$.apply(ConsoleAppender.scala:196) at sbt.internal.util.ConsoleLogger.(ConsoleAppender.scala:42) at sbt.internal.util.ConsoleLogger$.apply(ConsoleAppender.scala:34) at sbt.test.ScriptedRunner.run(ScriptedTests.scala:221) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at Scripted$.doScripted(Scripted.scala:125) at $0483e89d182e9d240274$.$anonfun$scriptedTask$5(build.sbt:301) --- .travis.yml | 3 ++- build.sbt | 10 ++++++---- project/AutomateScalafmtPlugin.scala | 10 +++++----- project/Docs.scala | 6 ++++++ project/NightlyPlugin.scala | 3 +-- project/PublishBinPlugin.scala | 2 ++ project/Release.scala | 4 ++-- project/SbtLauncherPlugin.scala | 3 ++- project/Scripted.scala | 2 ++ project/SiteMap.scala | 1 + project/Sxr.scala | 6 +++++- project/Transform.scala | 1 + project/Util.scala | 8 +++++--- project/build.properties | 2 +- project/plugins.sbt | 15 +++++++-------- .../src/main/scala/sbt/test/ScriptedTests.scala | 7 ++++++- 16 files changed, 54 insertions(+), 29 deletions(-) diff --git a/.travis.yml b/.travis.yml index 984384aff..4ff6cce3a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,8 @@ matrix: env: matrix: - - SBT_CMD=";mimaReportBinaryIssues;test:compile;scalafmtCheck;safeUnitTests;otherUnitTests" + - SBT_CMD=";test:compile;scalafmtCheck;safeUnitTests;otherUnitTests" + # - SBT_CMD="mimaReportBinaryIssues" - SBT_CMD="scripted actions/*" - SBT_CMD="scripted apiinfo/* compiler-project/* ivy-deps-management/*" - SBT_CMD="scripted dependency-management/*1of4" diff --git a/build.sbt b/build.sbt index 913d31f78..20ee54543 100644 --- a/build.sbt +++ b/build.sbt @@ -44,16 +44,17 @@ def commonSettings: Seq[Setting[_]] = concurrentRestrictions in Global += Util.testExclusiveRestriction, testOptions += Tests.Argument(TestFrameworks.ScalaCheck, "-w", "1"), javacOptions in compile ++= Seq("-target", "6", "-source", "6", "-Xlint", "-Xlint:-serial"), - incOptions := incOptions.value.withNameHashing(true), crossScalaVersions := Seq(baseScalaVersion), bintrayPackage := (bintrayPackage in ThisBuild).value, bintrayRepository := (bintrayRepository in ThisBuild).value, publishArtifact in Test := false, + /* mimaPreviousArtifacts := Set.empty, // Set(organization.value % moduleName.value % "1.0.0"), mimaBinaryIssueFilters ++= { import com.typesafe.tools.mima.core._, ProblemFilters._ Seq() }, + */ fork in compile := true, fork in run := true ) flatMap (_.settings) @@ -69,9 +70,9 @@ def testedBaseSettings: Seq[Setting[_]] = baseSettings ++ testDependencies lazy val sbtRoot: Project = (project in file(".")) - .enablePlugins(ScriptedPlugin, SiteScaladocPlugin, GhpagesPlugin) + .enablePlugins(ScriptedPlugin) // , SiteScaladocPlugin, GhpagesPlugin) .configs(Sxr.sxrConf) - .aggregate(nonRoots: _*) + .aggregateSeq(nonRoots) .settings( buildLevelSettings, minimalSettings, @@ -294,7 +295,8 @@ lazy val sbtProj = (project in file("sbt")) def scriptedTask: Def.Initialize[InputTask[Unit]] = Def.inputTask { val result = scriptedSource(dir => (s: State) => Scripted.scriptedParser(dir)).parsed - publishLocalBinAll.value + // publishLocalBinAll.value // TODO: Restore scripted needing only binary jars. + publishAll.value // These two projects need to be visible in a repo even if the default // local repository is hidden, so we publish them to an alternate location and add // that alternate repo to the running scripted test (in Scripted.scriptedpreScripted). diff --git a/project/AutomateScalafmtPlugin.scala b/project/AutomateScalafmtPlugin.scala index 82243e7c1..5d8f8718f 100644 --- a/project/AutomateScalafmtPlugin.scala +++ b/project/AutomateScalafmtPlugin.scala @@ -1,8 +1,8 @@ -import org.scalafmt.bootstrap.ScalafmtBootstrap +import org.scalafmt.cli.Cli import org.scalafmt.sbt.ScalafmtPlugin import sbt._ import sbt.Keys._ -import sbt.inc.Analysis +import sbt.internal.inc.Analysis // Taken from https://github.com/akka/alpakka/blob/master/project/AutomateScalafmtPlugin.scala object AutomateScalafmtPlugin extends AutoPlugin { @@ -18,7 +18,7 @@ object AutomateScalafmtPlugin extends AutoPlugin { }, sourceDirectories.in(scalafmtInc) := Seq(scalaSource.value), scalafmtInc := { - val cache = streams.value.cacheDirectory / "scalafmt" + val cache = streams.value.cacheStoreFactory / "scalafmt" val include = includeFilter.in(scalafmtInc).value val exclude = excludeFilter.in(scalafmtInc).value val sources = @@ -39,14 +39,14 @@ object AutomateScalafmtPlugin extends AutoPlugin { handler(files) files } - FileFunction.cached(cache)(FilesInfo.hash, FilesInfo.exists)(update(handler, msg))( + FileFunction.cached(cache, FilesInfo.hash, FilesInfo.exists)(update(handler, msg))( sources ) } def formattingHandler(files: Set[File]) = if (files.nonEmpty) { val filesArg = files.map(_.getAbsolutePath).mkString(",") - ScalafmtBootstrap.main(List("--quiet", "-i", "-f", filesArg)) + Cli.main(Array("--quiet", "-i", "-f", filesArg)) } format(formattingHandler, "Formatting") format(_ => (), "Reformatted") // Recalculate the cache diff --git a/project/Docs.scala b/project/Docs.scala index 11410185a..8d2a1baae 100644 --- a/project/Docs.scala +++ b/project/Docs.scala @@ -1,12 +1,17 @@ import sbt._, Keys._ +/* import StatusPlugin.autoImport._ import com.typesafe.sbt.site.SitePlugin.autoImport._ import com.typesafe.sbt.site.SiteScaladocPlugin.autoImport._ import com.typesafe.sbt.sbtghpages.GhpagesPlugin.autoImport._ import com.typesafe.sbt.SbtGit, SbtGit.{ git, GitKeys } import Sxr.{ sxr, sxrConf } +*/ object Docs { + def settings: Seq[Setting[_]] = Nil + + /* val siteExcludes = Set(".buildinfo", "objects.inv") def siteInclude(f: File) = !siteExcludes.contains(f.getName) @@ -47,4 +52,5 @@ object Docs { IO.copy(toCopy) repo } + */ } diff --git a/project/NightlyPlugin.scala b/project/NightlyPlugin.scala index 956427222..893410d0b 100644 --- a/project/NightlyPlugin.scala +++ b/project/NightlyPlugin.scala @@ -17,12 +17,11 @@ object NightlyPlugin extends AutoPlugin { import autoImport._ override def buildSettings: Seq[Setting[_]] = Seq( - // Avoid 2.12.x nightlies // Avoid 2.9.x precompiled // Avoid 2.8.x precompiled includeTestDependencies := { val v = scalaVersion.value - v.startsWith("2.10.") || v.startsWith("2.11.") + v.startsWith("2.10.") || v.startsWith("2.11.") || v.startsWith("2.12.") } ) diff --git a/project/PublishBinPlugin.scala b/project/PublishBinPlugin.scala index 8db2b0bdb..dade05395 100644 --- a/project/PublishBinPlugin.scala +++ b/project/PublishBinPlugin.scala @@ -1,5 +1,7 @@ import sbt._, Keys._ +import sbt.internal.librarymanagement.PublishConfiguration + /** This local plugin provides ways of publishing just the binary jar. */ object PublishBinPlugin extends AutoPlugin { override def requires = plugins.JvmPlugin diff --git a/project/Release.scala b/project/Release.scala index a0ecf29c1..74accb3a0 100644 --- a/project/Release.scala +++ b/project/Release.scala @@ -1,6 +1,6 @@ import sbt._ import Keys._ -import com.typesafe.sbt.JavaVersionCheckPlugin.autoImport._ +//import com.typesafe.sbt.JavaVersionCheckPlugin.autoImport._ import _root_.bintray.BintrayPlugin.autoImport._ import _root_.bintray.InternalBintrayKeys._ @@ -26,6 +26,6 @@ object Release { ) def javaVersionCheckSettings = Seq( - javaVersionPrefix in javaVersionCheck := Some("1.8") + //javaVersionPrefix in javaVersionCheck := Some("1.8") ) } diff --git a/project/SbtLauncherPlugin.scala b/project/SbtLauncherPlugin.scala index 789cc1cdb..4fca80392 100644 --- a/project/SbtLauncherPlugin.scala +++ b/project/SbtLauncherPlugin.scala @@ -1,3 +1,4 @@ +import sbt.io.Path._ import sbt._ import Keys._ @@ -41,7 +42,7 @@ object SbtLauncherPlugin extends AutoPlugin { IO.unzip(jar, dir) IO.copy(overrides.map({ case (n, f) => (f, dir / n) }), overwrite = true) // TODO - is the ok for creating a jar? - IO.zip((dir.*** --- dir) pair relativeTo(dir), target) + IO.zip((dir.allPaths --- dir) pair relativeTo(dir), target) } target } diff --git a/project/Scripted.scala b/project/Scripted.scala index 96473f4a9..33e23936e 100644 --- a/project/Scripted.scala +++ b/project/Scripted.scala @@ -1,6 +1,8 @@ import sbt._ import Keys._ import Def.Initialize +import sbt.internal.inc.ScalaInstance +import sbt.internal.inc.classpath import scala.language.reflectiveCalls diff --git a/project/SiteMap.scala b/project/SiteMap.scala index 9ab86c31d..ed1f5239e 100644 --- a/project/SiteMap.scala +++ b/project/SiteMap.scala @@ -1,3 +1,4 @@ +import sbt.io.Path._ import sbt._ object SiteMap { diff --git a/project/Sxr.scala b/project/Sxr.scala index 04ac22119..32ae16e0c 100644 --- a/project/Sxr.scala +++ b/project/Sxr.scala @@ -2,6 +2,10 @@ import sbt._ import Keys._ import Scope.ThisScope +import sbt.librarymanagement.syntax._ + +import sbt.internal.inc.RawCompiler + object Sxr { val sxrConf = config("sxr").hide val sxr = TaskKey[File]("sxr") @@ -31,7 +35,7 @@ object Sxr { IO.delete(out) IO.createDirectory(out) val comp = - new compiler.RawCompiler(scalaInstance.value, classpathOptions.value, streams.value.log) + new RawCompiler(scalaInstance.value, classpathOptions.value, streams.value.log) comp(in.toSeq.sorted, fullClasspath.value.files, out, scalacOptions.value) Set(outputDir) } diff --git a/project/Transform.scala b/project/Transform.scala index 4e855d7d3..20a47347e 100644 --- a/project/Transform.scala +++ b/project/Transform.scala @@ -1,3 +1,4 @@ +import sbt.io.Path._ import sbt._ import Keys._ diff --git a/project/Util.scala b/project/Util.scala index 4df5f9f4b..5f8d13bd1 100644 --- a/project/Util.scala +++ b/project/Util.scala @@ -2,6 +2,8 @@ import scala.util.control.NonFatal import sbt._ import Keys._ +import sbt.internal.inc.Analysis + object Util { val ExclusiveTest: Tags.Tag = Tags.Tag("exclusive-test") @@ -86,17 +88,17 @@ object Util { IO.createDirectory(out) val args = "xsbti.api" :: out.getAbsolutePath :: defs.map(_.getAbsolutePath).toList val mainClass = main getOrElse "No main class defined for datatype generator" - toError(run.run(mainClass, cp.files, args, s.log)) + run.run(mainClass, cp.files, args, s.log).failed foreach (e => sys error e.getMessage) (out ** "*.java").get } - def lastCompilationTime(analysis: sbt.inc.Analysis): Long = { + def lastCompilationTime(analysis: Analysis): Long = { val lastCompilation = analysis.compilations.allCompilations.lastOption lastCompilation.map(_.startTime) getOrElse 0L } def generateVersionFile(version: String, dir: File, s: TaskStreams, - analysis: sbt.inc.Analysis): Seq[File] = { + analysis: Analysis): Seq[File] = { import java.util.{ Date, TimeZone } val formatter = new java.text.SimpleDateFormat("yyyyMMdd'T'HHmmss") formatter.setTimeZone(TimeZone.getTimeZone("GMT")) diff --git a/project/build.properties b/project/build.properties index 27e88aa11..4a8f6a6c4 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.13 +sbt.version=1.0.0-M5 diff --git a/project/plugins.sbt b/project/plugins.sbt index 8d51f7bb3..53033e12b 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,12 +1,11 @@ -scalaVersion := "2.10.6" +scalaVersion := "2.12.2" scalacOptions ++= Seq("-feature", "-language:postfixOps") -addSbtPlugin("com.eed3si9n" % "sbt-doge" % "0.1.5") -addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.1.14") -addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.0") -addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.9.2") -addSbtPlugin("com.typesafe.sbt" % "sbt-javaversioncheck" % "0.1.0") -addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "0.6.8") -addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.2.0") +// addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.1.14") +// addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.0") +// addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.9.2") +// addSbtPlugin("com.typesafe.sbt" % "sbt-javaversioncheck" % "0.1.0") +addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "0.7.0-RC1") +// addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.2.0") addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.4.0") addSbtPlugin("org.scala-sbt" % "sbt-contraband" % "0.3.0-M4") diff --git a/scripted/sbt/src/main/scala/sbt/test/ScriptedTests.scala b/scripted/sbt/src/main/scala/sbt/test/ScriptedTests.scala index 7502a8ae3..84faf41f3 100644 --- a/scripted/sbt/src/main/scala/sbt/test/ScriptedTests.scala +++ b/scripted/sbt/src/main/scala/sbt/test/ScriptedTests.scala @@ -308,11 +308,16 @@ class ScriptedRunner { tests: Array[String], bootProperties: File, launchOpts: Array[String], - prescripted: java.util.List[File]): Unit = + prescripted: java.util.List[File]): Unit = { + + // Force Log4J to not use a thread context classloader otherwise it throws a CCE + sys.props(org.apache.logging.log4j.util.LoaderUtil.IGNORE_TCCL_PROPERTY) = "true" + run(resourceBaseDirectory, bufferLog, tests, ConsoleLogger(), bootProperties, launchOpts, { f: File => prescripted.add(f); () }) //new FullLogger(Logger.xlog2Log(log))) + } def run(resourceBaseDirectory: File, bufferLog: Boolean,