diff options
author | Eugene Yokota <eed3si9n@gmail.com> | 2017-08-05 05:08:37 -0400 |
---|---|---|
committer | Eugene Yokota <eed3si9n@gmail.com> | 2017-08-05 05:08:37 -0400 |
commit | 392cb3aea7a26adacfcdb65c7cc47764711c871a (patch) | |
tree | 11aa3af5d12f035d4d9ab9dd60c579cf6b2ec51b /src | |
parent | 5a55990edd587fa7c86c776f7f1871597444ee0d (diff) | |
download | sbt-boilerplate-392cb3aea7a26adacfcdb65c7cc47764711c871a.tar.gz sbt-boilerplate-392cb3aea7a26adacfcdb65c7cc47764711c871a.tar.bz2 sbt-boilerplate-392cb3aea7a26adacfcdb65c7cc47764711c871a.zip |
cross build to sbt 1.x
Diffstat (limited to 'src')
-rw-r--r-- | src/main/scala-sbt-0.13/Compat.scala | 21 | ||||
-rw-r--r-- | src/main/scala-sbt-1.0/Compat.scala | 30 | ||||
-rw-r--r-- | src/main/scala/spray/boilerplate/BoilerplatePlugin.scala | 19 | ||||
-rw-r--r-- | src/sbt-test/sbt-boilerplate/simple/build.sbt | 5 | ||||
-rw-r--r-- | src/sbt-test/sbt-boilerplate/simple/project/plugins.sbt | 1 | ||||
-rw-r--r-- | src/sbt-test/sbt-boilerplate/simple/src/main/boilerplate/Foo.template | 7 | ||||
-rw-r--r-- | src/sbt-test/sbt-boilerplate/simple/test | 2 |
7 files changed, 75 insertions, 10 deletions
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 |