Skip to content
Permalink
Browse files

= Upgrade to SBT 1.2.8 and scalafmt

  • Loading branch information...
sirthias committed May 3, 2019
1 parent 63cf07d commit 447a271c6070e0b8e876170ff5474192ec7251ff
Showing with 178 additions and 115 deletions.
  1. +14 −0 .scalafmt.conf
  2. +151 −100 build.sbt
  3. +1 −1 project/build.properties
  4. +11 −14 project/plugins.sbt
  5. +1 −0 version.sbt
@@ -0,0 +1,14 @@
version = 2.0.0-RC5

maxColumn = 120
assumeStandardLibraryStripMargin = true
align = more
newlines.alwaysBeforeTopLevelStatements = true

binPack.parentConstructors = true
runner.optimizer.forceConfigStyleOnOffset = -1

indentOperator = spray

rewrite.rules = [RedundantBraces, RedundantParens, SortImports, SortModifiers, PreferCurlyFors]
rewrite.redundantBraces.maxLines = 5
251 build.sbt
@@ -1,92 +1,145 @@
import com.typesafe.sbt.SbtScalariform.ScalariformKeys
import ReleaseTransformations._

import scalariform.formatter.preferences._

import scala.xml.transform._
import scala.xml.{NodeSeq, Node => XNode}
import sbtcrossproject.CrossPlugin.autoImport.{CrossType, crossProject}
import sbtcrossproject.CrossPlugin.autoImport._

val commonSettings = Seq(
version := "2.1.5",
scalaVersion := "2.12.8",
crossScalaVersions := Seq("2.11.12", "2.12.8", "2.13.0-RC1"),
organization := "org.parboiled",
homepage := Some(new URL("http://parboiled.org")),
description := "Fast and elegant PEG parsing in Scala - lightweight, easy-to-use, powerful",
startYear := Some(2009),
licenses := Seq("Apache-2.0" -> new URL("http://www.apache.org/licenses/LICENSE-2.0.txt")),
javacOptions ++= Seq(
unmanagedResources in Compile += baseDirectory.value.getParentFile.getParentFile / "LICENSE",
scmInfo := Some(ScmInfo(url("https://github.com/sirthias/parboiled2"), "scm:git:git@github.com:sirthias/parboiled2.git")),

scalaVersion := "2.12.8",
crossScalaVersions := Seq("2.11.12", "2.12.8", "2.13.0-RC1"),

scalacOptions ++= Seq(
"-deprecation",
"-encoding", "UTF-8",
"-source", "1.6",
"-target", "1.6",
"-Xlint:unchecked",
"-Xlint:deprecation"),
"-feature",
"-language:_",
"-unchecked",
"-Xlint:_,-missing-interpolator",
"-Ywarn-dead-code",
//"-Ywarn-numeric-widen",
),
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, v)) if v <= 11 => Seq("-target:jvm-1.6")
case _ => Nil
case Some((2, 11)) => Seq(
"-Yno-adapted-args",
"-Ywarn-inaccessible",
"-Ywarn-infer-any",
"-Ywarn-nullary-override",
"-Ywarn-nullary-unit",
"-Xfuture",
)
case Some((2, 12)) => Seq(
"-Yno-adapted-args",
"-Ywarn-inaccessible",
"-Ywarn-infer-any",
"-Ywarn-nullary-override",
"-Ywarn-nullary-unit",
"-Ywarn-unused:imports,-patvars,-privates,-locals,-implicits,-explicits",
"-Ycache-macro-class-loader:last-modified",
"-Ybackend-parallelism", "8",
"-Xfatal-warnings",
"-Xfuture",
"-Xsource:2.13", // new warning: deprecate assignments in argument position
)
case Some((2, 13)) => Seq(
"-Ywarn-unused:imports,-patvars,-privates,-locals,-implicits,-explicits",
"-Ycache-macro-class-loader:last-modified",
"-Ybackend-parallelism", "8",
)
case x => sys.error(s"unsupported scala version: $x")
}
},
scalacOptions ++= List(
"-encoding", "UTF-8",
"-feature",
"-unchecked",
"-deprecation",
"-Xlint",
"-language:_",
"-Xlog-reflective-calls"))

val formattingSettings = scalariformSettings ++ Seq(
ScalariformKeys.preferences := ScalariformKeys.preferences.value
.setPreference(RewriteArrowSymbols, true)
.setPreference(AlignParameters, true)
.setPreference(AlignSingleLineCaseStatements, true)
.setPreference(DoubleIndentClassDeclaration, true)
.setPreference(PreserveDanglingCloseParenthesis, true))
scalacOptions in (Compile, console) ~= (_ filterNot (o o == "-Ywarn-unused-import" || o == "-Xfatal-warnings")),
scalacOptions in (Test, console) ~= (_ filterNot (o o == "-Ywarn-unused-import" || o == "-Xfatal-warnings")),
scalacOptions in (Compile, doc) += "-no-link-warnings",
sourcesInBase := false,

val publishingSettings = Seq(
// file headers
headerLicense := Some(HeaderLicense.ALv2("2009-2019", "Mathias Doenitz")),

// reformat main and test sources on compile
scalafmtOnCompile := true,
)

lazy val crossSettings = Seq(
sourceDirectories in (Compile, scalafmt) := (unmanagedSourceDirectories in Compile).value,
sourceDirectories in (Test, scalafmt) := (unmanagedSourceDirectories in Test).value
)

lazy val scalajsSettings = Seq(
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule).withSourceMap(false)),
scalaJSStage in Global := FastOptStage,
scalacOptions ~= { _.filterNot(_ == "-Ywarn-dead-code") :+ "-P:scalajs:sjsDefinedByDefault" }
)

lazy val publishingSettings = Seq(
publishMavenStyle := true,
useGpg := true,
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (version.value.trim.endsWith("SNAPSHOT")) Some("snapshots" at nexus + "content/repositories/snapshots")
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
},
pomIncludeRepository := { _ => false },
pomExtra :=
<scm>
<url>git@github.com:sirthias/parboiled2.git</url>
<connection>scm:git:git@github.com:sirthias/parboiled2.git</connection>
</scm>
<developers>
<developer>
<id>sirthias</id>
<name>Mathias Doenitz</name>
</developer>
<developer>
<id>alexander-myltsev</id>
<name>Alexander Myltsev</name>
<url>http://www.linkedin.com/in/alexandermyltsev</url>
</developer>
</developers>)

val noPublishingSettings = Seq(
publishArtifact := false,
publishTo := Some(Resolver.file("Unused transient repository", file("target/unusedrepo"))))

val utestSettings = Seq(
testFrameworks := Seq(new TestFramework("utest.runner.Framework")))
publishArtifact in Test := false,
pomIncludeRepository := (_ false),
publishTo := sonatypePublishTo.value,
developers := List(
Developer("sirthias", "Mathias Doenitz", "devnull@bullet.io", url("https://github.com/sirthias")),
Developer("alexander-myltsev", "Alexander Myltsev", "", url("http://www.linkedin.com/in/alexandermyltsev"))
)
)

lazy val releaseSettings = {
val runCompile = ReleaseStep(action = { st: State
val extracted = Project.extract(st)
val ref = extracted.get(thisProjectRef)
extracted.runAggregated(compile in Compile in ref, st)
})

Seq(
releaseCrossBuild := true,
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runCompile,
runTest,
setReleaseVersion,
commitReleaseVersion,
tagRelease,
publishArtifacts,
setNextVersion,
commitNextVersion,
releaseStepCommand("sonatypeReleaseAll"),
pushChanges
)
)
}

val utestSettings = Seq(testFrameworks := Seq(new TestFramework("utest.runner.Framework")))

lazy val parboiledOsgiSettings = osgiSettings ++ Seq(
OsgiKeys.exportPackage := Seq("org.parboiled2.*;version=${Bundle-Version}"),
OsgiKeys.privatePackage := Seq()
)

/////////////////////// DEPENDENCIES /////////////////////////

def scalaReflect(v: String) = "org.scala-lang" % "scala-reflect" % v % "provided"
val shapeless = Def.setting("com.chuusai" %%% "shapeless" % "2.3.3" % "compile")
val utest = Def.setting("com.lihaoyi" %%% "utest" % "0.6.7" % Test)
val scalaCheck = Def.setting("org.scalacheck" %%% "scalacheck" % "1.14.0" % Test)
val shapeless = Def.setting("com.chuusai" %%% "shapeless" % "2.3.3" % "compile")
val utest = Def.setting("com.lihaoyi" %%% "utest" % "0.6.7" % Test)
val scalaCheck = Def.setting("org.scalacheck" %%% "scalacheck" % "1.14.0" % Test)
val `scala-reflect` = Def.setting("org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided")

// since ScalaCheck native is not available from the original authors @lolgab made a release
// see https://github.com/rickynils/scalacheck/issues/396#issuecomment-467782592
val scalaCheckNative = Def.setting("com.github.lolgab" %%% "scalacheck" % "1.14.1" % Test)
val scalaCheckNative = Def.setting("com.github.lolgab" %%% "scalacheck" % "1.14.1" % Test)

// benchmarks and examples only
val `json4s-native` = "org.json4s" %% "json4s-native" % "3.6.5"
val `json4s-jackson` = "org.json4s" %% "json4s-jackson" % "3.6.5"
val `spray-json` = "io.spray" %% "spray-json" % "1.3.5"

/////////////////////// PROJECTS /////////////////////////

@@ -95,49 +148,49 @@ lazy val root = project.in(file("."))
.aggregate(parboiledJVM, parboiledJS)
.aggregate(parboiledCoreJVM, parboiledCoreJS)
.settings(commonSettings)
.settings(noPublishingSettings)
.settings(
publishArtifact := false,
)

lazy val examples = project
.enablePlugins(AutomateHeaderPlugin)
.dependsOn(parboiledJVM)
.settings(commonSettings)
.settings(noPublishingSettings)
.settings(libraryDependencies ++= Seq(utest.value, "io.spray" %% "spray-json" % "1.3.5"))
.settings(libraryDependencies ++= Seq(utest.value, `spray-json`))
.settings(utestSettings)
.settings(publishArtifact := false)

lazy val bench = inputKey[Unit]("Runs the JSON parser benchmark with a simple standard config")

lazy val jsonBenchmark = project
.enablePlugins(AutomateHeaderPlugin)
.dependsOn(examples)
.enablePlugins(JmhPlugin)
.settings(commonSettings)
.settings(noPublishingSettings)
.settings(publishArtifact := false)
.settings(
libraryDependencies ++= Seq(
"org.json4s" %% "json4s-native" % "3.6.5",
"org.json4s" %% "json4s-jackson" % "3.6.5"),
libraryDependencies ++= Seq(`json4s-native`, `json4s-jackson`),
bench := (run in Compile).partialInput(" -i 10 -wi 10 -f1 -t1").evaluated)

lazy val scalaParser = project
.enablePlugins(AutomateHeaderPlugin)
.dependsOn(parboiledJVM)
.settings(commonSettings)
.settings(noPublishingSettings)
.settings(publishArtifact := false)
.settings(libraryDependencies ++= Seq(shapeless.value, utest.value))
.settings(utestSettings)

lazy val parboiledOsgiSettings = osgiSettings ++ Seq(
OsgiKeys.exportPackage := Seq("org.parboiled2.*;version=${Bundle-Version}"),
OsgiKeys.privatePackage := Seq()
)

lazy val parboiledJVM = parboiled.jvm
lazy val parboiledJS = parboiled.js
lazy val parboiledNative = parboiled.native
lazy val parboiled = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Pure)
.enablePlugins(AutomateHeaderPlugin, SbtOsgi)
.dependsOn(parboiledCore)
.settings(commonSettings)
.settings(formattingSettings)
.settings(publishingSettings)
.settings(parboiledOsgiSettings)
.settings(utestSettings)
.jvmSettings(
mappings in (Compile, packageBin) ++= (mappings in (parboiledCoreJVM.project, Compile, packageBin)).value,
mappings in (Compile, packageSrc) ++= (mappings in (parboiledCoreJVM.project, Compile, packageSrc)).value,
@@ -157,18 +210,19 @@ lazy val parboiled = crossProject(JSPlatform, JVMPlatform, NativePlatform)
crossScalaVersions := Seq("2.11.12")
)
.settings(
libraryDependencies ++= Seq(scalaReflect(scalaVersion.value), shapeless.value, utest.value),
libraryDependencies ++= Seq(`scala-reflect`.value, shapeless.value, utest.value),
mappings in (Compile, packageBin) ~= (_.groupBy(_._2).toSeq.map(_._2.head)), // filter duplicate outputs
mappings in (Compile, packageDoc) ~= (_.groupBy(_._2).toSeq.map(_._2.head)), // filter duplicate outputs
pomPostProcess := { // we need to remove the dependency onto the parboiledCore module from the POM
import scala.xml.transform._
import scala.xml.{NodeSeq, Node => XNode}

val filter = new RewriteRule {
override def transform(n: XNode) = if ((n \ "artifactId").text.startsWith("parboiledcore")) NodeSeq.Empty else n
}
new RuleTransformer(filter).transform(_).head
}
)
.settings(utestSettings)
.enablePlugins(SbtOsgi).settings(parboiledOsgiSettings:_*)

lazy val generateActionOps = taskKey[Seq[File]]("Generates the ActionOps boilerplate source file")

@@ -188,30 +242,27 @@ lazy val workaroundScala213 = Def.settings(
}
)

lazy val parboiledCore = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(CrossType.Pure).in(file("parboiled-core"))
lazy val parboiledCoreJVM = parboiledCore.jvm
lazy val parboiledCoreJS = parboiledCore.js
lazy val parboiledCoreNative = parboiledCore.native
lazy val parboiledCore = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("parboiled-core"))
.enablePlugins(AutomateHeaderPlugin)
.settings(commonSettings)
.settings(formattingSettings)
.settings(noPublishingSettings)
.settings(publishArtifact := false)
.settings(utestSettings)
.settings(
workaroundScala213,
libraryDependencies ++= Seq(scalaReflect(scalaVersion.value), shapeless.value, utest.value),
//workaroundScala213,
libraryDependencies ++= Seq(`scala-reflect`.value, shapeless.value, utest.value),
generateActionOps := ActionOpsBoilerplate((sourceManaged in Compile).value, streams.value),
(sourceGenerators in Compile) += generateActionOps.taskValue
)
.jvmSettings(
libraryDependencies ++= Seq(scalaCheck.value)
)
.jsSettings(
libraryDependencies ++= Seq(scalaCheck.value)
)
.jvmSettings(libraryDependencies += scalaCheck.value)
.jsSettings(libraryDependencies += scalaCheck.value)
.nativeSettings(
nativeLinkStubs := true,
scalaVersion := "2.11.12",
crossScalaVersions := Seq("2.11.12"),
libraryDependencies ++= Seq(scalaCheckNative.value)
)

lazy val parboiledCoreJVM = parboiledCore.jvm
lazy val parboiledCoreJS = parboiledCore.js
lazy val parboiledCoreNative = parboiledCore.native
libraryDependencies += scalaCheckNative.value
)
@@ -1 +1 @@
sbt.version=0.13.18
sbt.version=1.2.8
@@ -1,15 +1,12 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.3.0")

addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.1")

addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.6")

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.27")

addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.3")

addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.0")

addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.9")

addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.0")
addSbtPlugin("io.crashbox" % "sbt-gpg" % "0.2.0")
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.11")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.4")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.2.0")
addSbtPlugin("io.spray" % "sbt-boilerplate" % "0.6.1")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.27")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.9")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "0.6.0")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.4")
addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.3")
@@ -0,0 +1 @@
version in ThisBuild := "2.1.6-SNAPSHOT"

0 comments on commit 447a271

Please sign in to comment.
You can’t perform that action at this time.