PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/src/sbt-plugin/src/main/scala/PlaySettings.scala

https://github.com/ashkulkarni/playframework
Scala | 281 lines | 169 code | 92 blank | 20 comment | 2 complexity | 48f5f88ecc1d0a7163dfd9b69a04f50b MD5 | raw file
Possible License(s): Apache-2.0
  1. /*
  2. * Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
  3. */
  4. package play
  5. import sbt._
  6. import Keys._
  7. import play.PlayImport._
  8. import PlayKeys._
  9. import com.typesafe.sbt.SbtNativePackager._
  10. import com.typesafe.sbt.packager.Keys._
  11. import play.sbtplugin.ApplicationSecretGenerator
  12. import com.typesafe.sbt.web.SbtWeb.autoImport._
  13. import WebKeys._
  14. import scala.language.postfixOps
  15. trait PlaySettings {
  16. this: PlayCommands with PlayPositionMapper with PlayRun with PlaySourceGenerators =>
  17. lazy val defaultJavaSettings = Seq[Setting[_]](
  18. templatesImport ++= defaultJavaTemplatesImport,
  19. routesImport ++= Seq(
  20. "play.libs.F"
  21. ),
  22. ebeanEnabled := true
  23. )
  24. lazy val defaultScalaSettings = Seq[Setting[_]](
  25. templatesImport ++= defaultScalaTemplatesImport
  26. )
  27. def closureCompilerSettings(optionCompilerOptions: com.google.javascript.jscomp.CompilerOptions) = Seq[Setting[_]](
  28. resourceGenerators in Compile <<= JavascriptCompiler(Some(optionCompilerOptions))(Seq(_)),
  29. resourceGenerators in Compile <+= LessCompiler,
  30. resourceGenerators in Compile <+= CoffeescriptCompiler
  31. )
  32. /** Ask SBT to manage the classpath for the given configuration. */
  33. def manageClasspath(config: Configuration) = managedClasspath in config <<= (classpathTypes in config, update) map { (ct, report) =>
  34. Classpaths.managedJars(config, ct, report)
  35. }
  36. lazy val defaultSettings = Seq[Setting[_]](
  37. scalaVersion := play.core.PlayVersion.scalaVersion,
  38. playPlugin := false,
  39. resolvers ++= Seq(
  40. "Typesafe Releases Repository" at "http://repo.typesafe.com/typesafe/releases/"
  41. ),
  42. target <<= baseDirectory(_ / "target"),
  43. sourceDirectory in Compile <<= baseDirectory(_ / "app"),
  44. sourceDirectory in Test <<= baseDirectory(_ / "test"),
  45. confDirectory <<= baseDirectory(_ / "conf"),
  46. resourceDirectory in Compile <<= baseDirectory(_ / "conf"),
  47. scalaSource in Compile <<= baseDirectory(_ / "app"),
  48. scalaSource in Test <<= baseDirectory(_ / "test"),
  49. javaSource in Compile <<= baseDirectory(_ / "app"),
  50. javaSource in Test <<= baseDirectory(_ / "test"),
  51. javacOptions in (Compile, doc) := List("-encoding", "utf8"),
  52. libraryDependencies <+= (playPlugin) {
  53. isPlugin =>
  54. val d = "com.typesafe.play" %% "play" % play.core.PlayVersion.current
  55. if (isPlugin)
  56. d % "provided"
  57. else
  58. d
  59. },
  60. libraryDependencies += "com.typesafe.play" %% "play-test" % play.core.PlayVersion.current % "test",
  61. ivyConfigurations += DocsApplication,
  62. libraryDependencies += "com.typesafe.play" %% "play-docs" % play.core.PlayVersion.current % DocsApplication.name,
  63. manageClasspath(DocsApplication),
  64. parallelExecution in Test := false,
  65. fork in Test := true,
  66. testOptions in Test += Tests.Argument(TestFrameworks.Specs2, "sequential", "true", "junitxml", "console"),
  67. testOptions in Test += Tests.Argument(TestFrameworks.JUnit, "--ignore-runners=org.specs2.runner.JUnitRunner"),
  68. // Make sure Specs2 is at the end of the list of test frameworks, so that it gets priority over
  69. // JUnit. This is a hack/workaround to prevent Specs2 tests with @RunsWith annotations being
  70. // picked up by JUnit. We don't want JUnit to run the tests since JUnit ignores the Specs2
  71. // runnner, which means the tests run but their results are ignored by SBT.
  72. testFrameworks ~= {
  73. tf => tf.filter(_ != TestFrameworks.Specs2).:+(TestFrameworks.Specs2)
  74. },
  75. testListeners <<= (target, streams).map((t, s) => Seq(new eu.henkelmann.sbt.JUnitXmlTestsListener(t.getAbsolutePath, s.log))),
  76. testResultReporter <<= testResultReporterTask,
  77. testResultReporterReset <<= testResultReporterResetTask,
  78. generateReverseRouter := true,
  79. generateRefReverseRouter := true,
  80. namespaceReverseRouter := false,
  81. sourceGenerators in Compile <+= (state, confDirectory, sourceManaged in Compile, routesImport, generateReverseRouter, generateRefReverseRouter, namespaceReverseRouter) map {
  82. (s, cd, sm, ri, grr, grrr, nrr) => RouteFiles(s, Seq(cd), sm, ri, grr, grrr, nrr)
  83. },
  84. // Adds config directory's source files to continuous hot reloading
  85. watchSources <+= confDirectory map {
  86. all => all
  87. },
  88. sourceGenerators in Compile <+= (state, unmanagedSourceDirectories in Compile, sourceManaged in Compile, templatesTypes, templatesImport, excludeFilter in unmanagedSources) map ScalaTemplates,
  89. // Adds app directory's source files to continuous hot reloading
  90. watchSources <++= baseDirectory map {
  91. path => ((path / "app") ** "*" --- (path / "app/assets") ** "*").get
  92. },
  93. commands ++= Seq(shCommand, playStartCommand, h2Command, classpathCommand, licenseCommand, computeDependenciesCommand),
  94. // THE `in Compile` IS IMPORTANT!
  95. run in Compile <<= playRunSetting,
  96. shellPrompt := playPrompt,
  97. mainClass in (Compile, run) := Some("play.core.server.NettyServer"),
  98. compile in (Compile) <<= PostCompile(scope = Compile),
  99. compile in Test <<= PostCompile(Test),
  100. computeDependencies <<= computeDependenciesTask,
  101. playVersion := play.core.PlayVersion.current,
  102. // all dependencies from outside the project (all dependency jars)
  103. playDependencyClasspath <<= externalDependencyClasspath in Runtime,
  104. // all user classes, in this project and any other subprojects that it depends on
  105. playReloaderClasspath <<= Classpaths.concatDistinct(exportedProducts in Runtime, internalDependencyClasspath in Runtime),
  106. playCommonClassloader <<= playCommonClassloaderTask,
  107. playDependencyClassLoader := createURLClassLoader,
  108. playReloaderClassLoader := createDelegatedResourcesClassLoader,
  109. playCompileEverything <<= playCompileEverythingTask,
  110. playReload <<= playReloadTask,
  111. sourcePositionMappers += playPositionMapper,
  112. ivyLoggingLevel := UpdateLogging.DownloadOnly,
  113. routesImport := Seq.empty[String],
  114. playMonitoredFiles <<= playMonitoredFilesTask,
  115. playDefaultPort := 9000,
  116. // Default hooks
  117. playRunHooks := Nil,
  118. playInteractionMode := play.PlayConsoleInteractionMode,
  119. // Assets
  120. requireJs := Nil,
  121. requireJsFolder := "",
  122. requireJsShim := "",
  123. requireNativePath := None,
  124. buildRequire <<= buildRequireTask,
  125. packageBin in Compile <<= (packageBin in Compile).dependsOn(buildRequire),
  126. lessEntryPoints <<= (sourceDirectory in Compile)(base => ((base / "assets" ** "*.less") --- base / "assets" ** "_*")),
  127. coffeescriptEntryPoints <<= (sourceDirectory in Compile)(base => base / "assets" ** "*.coffee"),
  128. javascriptEntryPoints <<= (sourceDirectory in Compile)(base => ((base / "assets" ** "*.js") --- (base / "assets" ** "_*"))),
  129. lessOptions := Seq.empty[String],
  130. coffeescriptOptions := Seq.empty[String],
  131. closureCompilerOptions := Seq.empty[String],
  132. // sbt-web
  133. sourceDirectory in Assets := (sourceDirectory in Compile).value / "assets",
  134. sourceDirectory in TestAssets := (sourceDirectory in Test).value / "assets",
  135. jsFilter in Assets := new PatternFilter("""[^_].*\.js""".r.pattern),
  136. resourceDirectory in Assets := baseDirectory.value / "public",
  137. public in Assets := (public in Assets).value / "public",
  138. WebKeys.stagingDirectory := WebKeys.stagingDirectory.value / "public",
  139. products in Runtime += (public in Assets).value.getParentFile,
  140. products in Compile += WebKeys.stagingDirectory.value.getParentFile,
  141. playAssetsWithCompilation := {
  142. val ignore = ((assets in Assets)?).value
  143. (compile in Compile).value
  144. },
  145. fullClasspath in Test := (fullClasspath in Test).dependsOn(assets in Assets).value,
  146. packageBin in Compile := (packageBin in Compile).dependsOn(WebKeys.stage).value,
  147. // Settings
  148. devSettings := Nil,
  149. // Templates
  150. templatesImport := defaultTemplatesImport,
  151. templatesTypes := Map(
  152. "html" -> "play.api.templates.HtmlFormat",
  153. "txt" -> "play.api.templates.TxtFormat",
  154. "xml" -> "play.api.templates.XmlFormat",
  155. "js" -> "play.api.templates.JavaScriptFormat"
  156. ),
  157. // Native packaging
  158. sourceDirectory in Universal <<= baseDirectory(_ / "dist"),
  159. mainClass in Compile := Some("play.core.server.NettyServer"),
  160. mappings in Universal ++= {
  161. val confDirectoryLen = confDirectory.value.getCanonicalPath.length
  162. val pathFinder = confDirectory.value ** ("*" -- "routes")
  163. pathFinder.get map {
  164. confFile: File =>
  165. confFile -> ("conf/" + confFile.getCanonicalPath.substring(confDirectoryLen))
  166. }
  167. },
  168. mappings in Universal ++= {
  169. val docDirectory = (doc in Compile).value
  170. val docDirectoryLen = docDirectory.getCanonicalPath.length
  171. val pathFinder = docDirectory ** "*"
  172. pathFinder.get map {
  173. docFile: File =>
  174. docFile -> ("share/doc/api/" + docFile.getCanonicalPath.substring(docDirectoryLen))
  175. }
  176. },
  177. mappings in Universal ++= {
  178. val pathFinder = baseDirectory.value * "README*"
  179. pathFinder.get map {
  180. readmeFile: File =>
  181. readmeFile -> readmeFile.getName
  182. }
  183. },
  184. // Adds the Play application directory to the command line args passed to Play
  185. bashScriptExtraDefines += "addJava \"-Duser.dir=$(cd \"${app_home}/..\"; pwd -P)\"\n",
  186. generateSecret <<= ApplicationSecretGenerator.generateSecretTask,
  187. updateSecret <<= ApplicationSecretGenerator.updateSecretTask
  188. )
  189. }