From 392cb3aea7a26adacfcdb65c7cc47764711c871a Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sat, 5 Aug 2017 05:08:37 -0400 Subject: cross build to sbt 1.x --- build.sbt | 30 ++++++++++++++++------ project.sbt | 15 ----------- project/build.properties | 2 +- project/plugins.sbt | 5 ++-- scripted.sbt | 3 +++ src/main/scala-sbt-0.13/Compat.scala | 21 +++++++++++++++ src/main/scala-sbt-1.0/Compat.scala | 30 ++++++++++++++++++++++ .../spray/boilerplate/BoilerplatePlugin.scala | 19 +++++++------- src/sbt-test/sbt-boilerplate/simple/build.sbt | 5 ++++ .../sbt-boilerplate/simple/project/plugins.sbt | 1 + .../simple/src/main/boilerplate/Foo.template | 7 +++++ src/sbt-test/sbt-boilerplate/simple/test | 2 ++ 12 files changed, 103 insertions(+), 37 deletions(-) delete mode 100644 project.sbt create mode 100644 scripted.sbt create mode 100644 src/main/scala-sbt-0.13/Compat.scala create mode 100644 src/main/scala-sbt-1.0/Compat.scala create mode 100644 src/sbt-test/sbt-boilerplate/simple/build.sbt create mode 100644 src/sbt-test/sbt-boilerplate/simple/project/plugins.sbt create mode 100644 src/sbt-test/sbt-boilerplate/simple/src/main/boilerplate/Foo.template create mode 100644 src/sbt-test/sbt-boilerplate/simple/test diff --git a/build.sbt b/build.sbt index 87eeaf3..f5593fe 100644 --- a/build.sbt +++ b/build.sbt @@ -1,10 +1,24 @@ -sbtPlugin := true +lazy val root = (project in file(".")) + .settings( + sbtPlugin := true, + name := "sbt-boilerplate", + organization := "io.spray", + version := "0.6.1-SNAPSHOT", + description := "An SBT plugin for simple generation of boilerplate", + startYear := Some(2012), + homepage := Some(url("http://github.com/sbt/sbt-boilerplate")), + organizationHomepage := Some(url("http://spray.io")), -scalacOptions := Seq("-deprecation", "-encoding", "utf8") + licenses in GlobalScope += "BSD" -> url("https://github.com/sbt/sbt-boilerplate/raw/master/LICENSE"), -libraryDependencies <+= scalaVersion { - case v if v startsWith "2.9." => "org.specs2" % "specs2_2.9.3" % "1.12.4.1" % "test" - case "2.10.4" => "org.specs2" %% "specs2" % "2.3.13" % "test" -} - -ScalariformSupport.formatSettings \ No newline at end of file + scalacOptions := Seq("-deprecation", "-encoding", "utf8"), + libraryDependencies += { + scalaBinaryVersion.value match { + case v if v startsWith "2.9." => "org.specs2" % "specs2_2.9.3" % "1.12.4.1" % Test + case "2.10" => "org.specs2" %% "specs2" % "2.4.17" % Test + case "2.12" => "org.specs2" %% "specs2" % "2.4.17" % Test + } + }, + ScalariformSupport.formatSettings, + resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases" + ) diff --git a/project.sbt b/project.sbt deleted file mode 100644 index 86f1103..0000000 --- a/project.sbt +++ /dev/null @@ -1,15 +0,0 @@ -name := "sbt-boilerplate" - -organization := "io.spray" - -version := "0.6.1-SNAPSHOT" - -description := "An SBT plugin for simple generation of boilerplate" - -startYear := Some(2012) - -homepage := Some(url("http://github.com/sbt/sbt-boilerplate")) - -organizationHomepage := Some(url("http://spray.io")) - -licenses in GlobalScope += "BSD" -> url("https://github.com/sbt/sbt-boilerplate/raw/master/LICENSE") diff --git a/project/build.properties b/project/build.properties index be6c454..c091b86 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.5 +sbt.version=0.13.16 diff --git a/project/plugins.sbt b/project/plugins.sbt index 92449de..7491444 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,5 +1,4 @@ addSbtPlugin("me.lessis" % "ls-sbt" % "0.1.3") - addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.2.0") - -addSbtPlugin("me.lessis" % "bintray-sbt" % "0.1.2") \ No newline at end of file +addSbtPlugin("me.lessis" % "bintray-sbt" % "0.1.2") +libraryDependencies += "org.scala-sbt" % "scripted-plugin" % sbtVersion.value diff --git a/scripted.sbt b/scripted.sbt new file mode 100644 index 0000000..00920fd --- /dev/null +++ b/scripted.sbt @@ -0,0 +1,3 @@ +import sbt.ScriptedPlugin._ +scriptedSettings +scriptedLaunchOpts += s"-Dproject.version=${version.value}" diff --git a/src/main/scala-sbt-0.13/Compat.scala b/src/main/scala-sbt-0.13/Compat.scala new file mode 100644 index 0000000..6138f7c --- /dev/null +++ b/src/main/scala-sbt-0.13/Compat.scala @@ -0,0 +1,21 @@ +/* + * sbt-boilerplate is distributed under the 2-Clause BSD license. See the LICENSE file in the root + * of the repository. + * + * Copyright (c) 2012-2016 Johannes Rudolph + */ +package spray.boilerplate + +import sbt._ +import Keys._ + +object Compat { + private val boilerplateSource = settingKey[File]("Default directory containing boilerplate template sources.") + private val inputFilter = "*.template" + + def allPaths(f: File) = f.*** + + def watchSourceSettings = Def.settings { + Seq(watchSources in Defaults.ConfigGlobal ++= ((boilerplateSource.value ** inputFilter) --- (boilerplateSource.value ** excludeFilter.value ** inputFilter)).get) + } +} diff --git a/src/main/scala-sbt-1.0/Compat.scala b/src/main/scala-sbt-1.0/Compat.scala new file mode 100644 index 0000000..f1a9d47 --- /dev/null +++ b/src/main/scala-sbt-1.0/Compat.scala @@ -0,0 +1,30 @@ +/* + * sbt-boilerplate is distributed under the 2-Clause BSD license. See the LICENSE file in the root + * of the repository. + * + * Copyright (c) 2012-2016 Johannes Rudolph + */ +package spray.boilerplate + +import sbt._ +import Keys._ +import sbt.internal.io.Source + +object Compat { + private val boilerplateSource = settingKey[File]("Default directory containing boilerplate template sources.") + private val inputFilter = """.*\.template""".r + + def allPaths(f: File) = f.allPaths + + def watchSourceSettings = Def.settings { + Seq( + watchSources in Defaults.ConfigGlobal += + new Source( + boilerplateSource.value, + new NameFilter { + override def accept(name: String): Boolean = inputFilter.pattern.matcher(name).matches() + }, + NothingFilter) + ) + } +} diff --git a/src/main/scala/spray/boilerplate/BoilerplatePlugin.scala b/src/main/scala/spray/boilerplate/BoilerplatePlugin.scala index 88e6661..50bcfd5 100644 --- a/src/main/scala/spray/boilerplate/BoilerplatePlugin.scala +++ b/src/main/scala/spray/boilerplate/BoilerplatePlugin.scala @@ -31,13 +31,12 @@ object BoilerplatePlugin extends AutoPlugin { boilerplateSignature := "// auto-generated by sbt-boilerplate\n") private def rawBoilerplateSettings: Seq[Setting[_]] = { - val inputFilter = "*.template" - Seq( - boilerplateSource := sourceDirectory.value / "boilerplate", - watchSources in Defaults.ConfigGlobal ++= ((boilerplateSource.value ** inputFilter) --- (boilerplateSource.value ** excludeFilter.value ** inputFilter)).get, - boilerplateGenerate := generateFromTemplates(streams.value, boilerplateSignature.value, boilerplateSource.value, sourceManaged.value), - mappings in packageSrc ++= managedSources.value pair (Path.relativeTo(sourceManaged.value) | Path.flat), - sourceGenerators <+= boilerplateGenerate) + Compat.watchSourceSettings ++ + Seq( + boilerplateSource := sourceDirectory.value / "boilerplate", + boilerplateGenerate := generateFromTemplates(streams.value, boilerplateSignature.value, boilerplateSource.value, sourceManaged.value), + mappings in packageSrc ++= managedSources.value pair (Path.relativeTo(sourceManaged.value) | Path.flat), + sourceGenerators += boilerplateGenerate) } def generateFromTemplates(streams: TaskStreams, signature: String, sourceDir: File, targetDir: File): Seq[File] = { @@ -53,7 +52,7 @@ object BoilerplatePlugin extends AutoPlugin { new File(f.getParent, newName) } - val mapping = (files pair rebase(sourceDir, targetDir)).map { + val mapping = (files pair Path.rebase(sourceDir, targetDir)).map { case (orig, target) ⇒ (orig, changeExtension(target)) } @@ -87,12 +86,12 @@ object BoilerplatePlugin extends AutoPlugin { } val toRemove = - targetDir.*** + Compat.allPaths(targetDir) // apply filters with increasing effort .filter(f ⇒ f.exists && f.isFile) .filter(_.length >= signature.length) .filter(!fileSet(_)) - .filter(containsSignature) + .filter(containsSignature _) .get toRemove.foreach { f ⇒ diff --git a/src/sbt-test/sbt-boilerplate/simple/build.sbt b/src/sbt-test/sbt-boilerplate/simple/build.sbt new file mode 100644 index 0000000..927e631 --- /dev/null +++ b/src/sbt-test/sbt-boilerplate/simple/build.sbt @@ -0,0 +1,5 @@ +lazy val root = (project in file(".")) + .enablePlugins(spray.boilerplate.BoilerplatePlugin) + .settings( + scalaVersion := "2.11.11" + ) diff --git a/src/sbt-test/sbt-boilerplate/simple/project/plugins.sbt b/src/sbt-test/sbt-boilerplate/simple/project/plugins.sbt new file mode 100644 index 0000000..a64c442 --- /dev/null +++ b/src/sbt-test/sbt-boilerplate/simple/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("io.spray" % "sbt-boilerplate" % sys.props("project.version")) diff --git a/src/sbt-test/sbt-boilerplate/simple/src/main/boilerplate/Foo.template b/src/sbt-test/sbt-boilerplate/simple/src/main/boilerplate/Foo.template new file mode 100644 index 0000000..5478233 --- /dev/null +++ b/src/sbt-test/sbt-boilerplate/simple/src/main/boilerplate/Foo.template @@ -0,0 +1,7 @@ +package x + +object Foo { + [#def applyFunc[[#P1#], R](input: Tuple1[[#P1#]], func: ([#P1#]) => R): R = + func([#input._1#])# + ] +} diff --git a/src/sbt-test/sbt-boilerplate/simple/test b/src/sbt-test/sbt-boilerplate/simple/test new file mode 100644 index 0000000..5ea794e --- /dev/null +++ b/src/sbt-test/sbt-boilerplate/simple/test @@ -0,0 +1,2 @@ +> compile +$ exists target/scala-2.11/src_managed/main/Foo.scala -- cgit v1.2.3