Skip to content

Commit

Permalink
small refactor to move the keys of the plugin into their own object
Browse files Browse the repository at this point in the history
  • Loading branch information
casualjim committed Jul 23, 2012
1 parent 2ea4c86 commit 2f9cebc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ Configure the plugin in `build.sbt`:
import com.mojolly.scalate.ScalatePlugin._

seq(scalateSettings:_*)

import ScalateKeys._

scalateTemplateDirectory in Compile <<= (baseDirectory) { _ / "src/main/webapp/WEB-INF" }
scalateTemplateDirectory in Compile <<= (sourceDirectory in Compile) { _ / "webapp" / "WEB-INF" }

scalateImports ++= Seq(
"import scalaz._",
Expand Down
51 changes: 29 additions & 22 deletions plugin/src/main/scala/ScalatePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,27 @@ object ScalatePlugin extends Plugin {

val Scalate = config("scalate") hide

val scalateTemplateDirectory = SettingKey[File]("scalate-template-directory",
"Locations of template files.")
object ScalateKeys {

val scalateLoggingConfig = SettingKey[File]("scalate-logging-config",
"Logback config to get rid of that infernal debug output.")
val scalateTemplateDirectory = SettingKey[File]("scalate-template-directory",
"Locations of template files.")

val scalateImports = SettingKey[Seq[String]]("scalate-imports",
"The import statements for Scalate templates")
val scalateLoggingConfig = SettingKey[File]("scalate-logging-config",
"Logback config to get rid of that infernal debug output.")

val scalateBindings = SettingKey[Seq[Binding]]("scalate-bindings",
"The bindings for Scalate templates")

val scalateOverwrite = SettingKey[Boolean]("scalate-overwrite",
"Always generate the Scala sources even when they haven't changed")
val scalateImports = SettingKey[Seq[String]]("scalate-imports",
"The import statements for Scalate templates")

val scalateBindings = SettingKey[Seq[Binding]]("scalate-bindings",
"The bindings for Scalate templates")

val scalateOverwrite = SettingKey[Boolean]("scalate-overwrite",
"Always generate the Scala sources even when they haven't changed")

val scalateClasspaths = TaskKey[ScalateClasspaths]("scalate-classpaths")
}

import ScalateKeys._

private def scalateLoggingConfigValue: Initialize[File] =
(resourceDirectory in Compile) { (d) => new File(d, "/logback.xml") }
Expand All @@ -45,23 +52,23 @@ object ScalatePlugin extends Plugin {
}
}

val scalateClasspaths = TaskKey[ScalateClasspaths]("scalate-classpaths")
type Generator = {
var sources: File
var targetDirectory: File
var logConfig: File
var overwrite: Boolean
var scalateImports: Array[String]
var scalateBindings: Array[Array[AnyRef]]
def execute: Array[File]
}

final case class ScalateClasspaths(classpath: PathFinder, scalateClasspath: PathFinder)

def scalateClasspathsTask(cp: Classpath, scalateCp: Classpath) = ScalateClasspaths(cp.map(_.data), scalateCp.map(_.data))

def generateScalateSource(out: TaskStreams, outputDir: File, inputDir: File, logConfig: File, cp: Classpath, imports: Seq[String], bindings: Seq[Binding], overwrite: Boolean) = {
withScalateClassLoader(cp.files) { classLoader =>
type Generator = {
var sources: File
var targetDirectory: File
var logConfig: File
var overwrite: Boolean
var scalateImports: Array[String]
var scalateBindings: Array[Array[AnyRef]]
def execute: Array[File]
}


val className = "com.mojolly.scalate.Generator"
val klass = classLoader.loadClass(className)
val inst = klass.newInstance
Expand Down
12 changes: 4 additions & 8 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
resolvers += Resolver.url("sbt-plugin-releases",
new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(
Resolver.ivyStylePatterns)
// resolvers += Resolver.url("sbt-plugin-releases",
// new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(
// Resolver.ivyStylePatterns)


//addSbtPlugin("com.typesafe.sbtscalariform" % "sbtscalariform" % "0.3.1")

// addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.1.2")

addSbtPlugin("com.jsuereth" % "xsbt-gpg-plugin" % "0.6")
// addSbtPlugin("com.jsuereth" % "xsbt-gpg-plugin" % "0.6")


// libraryDependencies <+= (scalaVersion) { sv => ("com.typesafe.sbtscalariform" % "sbtscalariform" % "0.3.1").extra(CustomPomParser.SbtVersionKey -> "0.11.2", CustomPomParser.ScalaVersionKey -> sv).copy(crossVersion = false) }

// libraryDependencies <+= (scalaVersion) { sv => ("com.jsuereth" % "xsbt-gpg-plugin" % "0.6").extra(CustomPomParser.SbtVersionKey -> "0.11.2", CustomPomParser.ScalaVersionKey -> sv).copy(crossVersion = false) }

0 comments on commit 2f9cebc

Please sign in to comment.