PageRenderTime 67ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/langley/Play20
Scala | 222 lines | 132 code | 85 blank | 5 comment | 7 complexity | 09426bb31d25b452374326b68380be90 MD5 | raw file
  1. package sbt
  2. import Keys._
  3. import PlayKeys._
  4. trait PlaySettings {
  5. this: PlayCommands with PlayPositionMapper =>
  6. protected def whichLang(name: String): Seq[Setting[_]] = {
  7. if (name == JAVA) {
  8. defaultJavaSettings
  9. } else if (name == SCALA) {
  10. defaultScalaSettings
  11. } else {
  12. Seq.empty
  13. }
  14. }
  15. lazy val defaultJavaSettings = Seq[Setting[_]](
  16. templatesImport ++= Seq(
  17. "models._",
  18. "controllers._",
  19. "java.lang._",
  20. "java.util._",
  21. "scala.collection.JavaConversions._",
  22. "scala.collection.JavaConverters._",
  23. "play.api.i18n._",
  24. "play.core.j.PlayMagicForJava._",
  25. "play.mvc._",
  26. "play.data._",
  27. "play.api.data.Field",
  28. "play.mvc.Http.Context.Implicit._",
  29. "views.%format%._"),
  30. routesImport ++= Seq(
  31. "play.libs.F"
  32. ),
  33. ebeanEnabled := true
  34. )
  35. lazy val defaultScalaSettings = Seq[Setting[_]](
  36. templatesImport ++= Seq(
  37. "models._",
  38. "controllers._",
  39. "play.api.i18n._",
  40. "play.api.mvc._",
  41. "play.api.data._",
  42. "views.%format%._"))
  43. def closureCompilerSettings(optionCompilerOptions: com.google.javascript.jscomp.CompilerOptions) = Seq[Setting[_]](
  44. resourceGenerators in Compile <<= JavascriptCompiler(Some(optionCompilerOptions))(Seq(_)),
  45. resourceGenerators in Compile <+= LessCompiler,
  46. resourceGenerators in Compile <+= CoffeescriptCompiler
  47. )
  48. lazy val defaultSettings = Seq[Setting[_]](
  49. scalaVersion := play.core.PlayVersion.scalaVersion,
  50. playPlugin := false,
  51. resolvers ++= Seq(
  52. "Typesafe Releases Repository" at "http://repo.typesafe.com/typesafe/releases/",
  53. "Typesafe Snapshots Repository" at "http://repo.typesafe.com/typesafe/snapshots/"
  54. ),
  55. target <<= baseDirectory / "target",
  56. sourceDirectory in Compile <<= baseDirectory / "app",
  57. sourceDirectory in Test <<= baseDirectory / "test",
  58. confDirectory <<= baseDirectory / "conf",
  59. resourceDirectory in Compile <<= baseDirectory / "conf",
  60. scalaSource in Compile <<= baseDirectory / "app",
  61. scalaSource in Test <<= baseDirectory / "test",
  62. javaSource in Compile <<= baseDirectory / "app",
  63. javaSource in Test <<= baseDirectory / "test",
  64. distDirectory <<= baseDirectory / "dist",
  65. distExcludes := Seq.empty,
  66. libraryDependencies <+= (playPlugin) { isPlugin =>
  67. val d = "play" %% "play" % play.core.PlayVersion.current
  68. if(isPlugin)
  69. d % "provided"
  70. else
  71. d
  72. },
  73. libraryDependencies += "play" %% "play-test" % play.core.PlayVersion.current % "test",
  74. parallelExecution in Test := false,
  75. fork in Test := true,
  76. testOptions in Test += Tests.Argument(TestFrameworks.Specs2, "sequential", "true"),
  77. testOptions in Test += Tests.Argument(TestFrameworks.JUnit, "junitxml", "console"),
  78. testListeners <<= (target, streams).map((t, s) => Seq(new eu.henkelmann.sbt.JUnitXmlTestsListener(t.getAbsolutePath, s.log))),
  79. testResultReporter <<= testResultReporterTask,
  80. testResultReporterReset <<= testResultReporterResetTask,
  81. sourceGenerators in Compile <+= (state, confDirectory, sourceManaged in Compile, routesImport) map RouteFiles,
  82. // Adds config directory's source files to continuous hot reloading
  83. watchSources <+= confDirectory map { all => all },
  84. sourceGenerators in Compile <+= (state, sourceDirectory in Compile, sourceManaged in Compile, templatesTypes, templatesImport) map ScalaTemplates,
  85. // Adds app directory's source files to continuous hot reloading
  86. watchSources <++= baseDirectory map { path => ((path / "app") ** "*").get },
  87. commands ++= Seq(shCommand, playCommand, playRunCommand, playStartCommand, h2Command, classpathCommand, licenseCommand, computeDependenciesCommand),
  88. shellPrompt := playPrompt,
  89. copyResources in Compile <<= (copyResources in Compile, playCopyAssets) map { (r, pr) => r ++ pr },
  90. mainClass in (Compile, run) := Some("play.core.server.NettyServer"),
  91. compile in (Compile) <<= PostCompile(scope = Compile),
  92. dist <<= distTask,
  93. computeDependencies <<= computeDependenciesTask,
  94. playVersion := play.core.PlayVersion.current,
  95. playCommonClassloader <<= playCommonClassloaderTask,
  96. playCopyAssets <<= playCopyAssetsTask,
  97. playCompileEverything <<= playCompileEverythingTask,
  98. playPackageEverything <<= playPackageEverythingTask,
  99. playReload <<= playReloadTask,
  100. playStage <<= playStageTask,
  101. cleanFiles <+= distDirectory,
  102. logManager <<= extraLoggers(PlayLogManager.default(playPositionMapper)),
  103. ivyLoggingLevel := UpdateLogging.DownloadOnly,
  104. routesImport := Seq.empty[String],
  105. playMonitoredFiles <<= playMonitoredFilesTask,
  106. playDefaultPort := 9000,
  107. playOnStarted := Nil,
  108. playOnStopped := Nil,
  109. // Assets
  110. playAssetsDirectories := Seq.empty[File],
  111. playExternalAssets := Seq.empty[(File, File => PathFinder, String)],
  112. playAssetsDirectories <+= baseDirectory / "public",
  113. requireJs := Nil,
  114. requireJsFolder := "",
  115. requireJsShim := "",
  116. requireNativePath := None,
  117. buildRequire <<= buildRequireTask,
  118. packageBin in Compile <<= (packageBin in Compile).dependsOn(buildRequire),
  119. resourceGenerators in Compile <+= LessCompiler,
  120. resourceGenerators in Compile <+= CoffeescriptCompiler,
  121. resourceGenerators in Compile <+= JavascriptCompiler(fullCompilerOptions = None),
  122. lessEntryPoints <<= (sourceDirectory in Compile)(base => ((base / "assets" ** "*.less") --- base / "assets" ** "_*")),
  123. coffeescriptEntryPoints <<= (sourceDirectory in Compile)(base => base / "assets" ** "*.coffee"),
  124. javascriptEntryPoints <<= (sourceDirectory in Compile)(base => ((base / "assets" ** "*.js") --- (base / "assets" ** "_*"))),
  125. lessOptions := Seq.empty[String],
  126. coffeescriptOptions := Seq.empty[String],
  127. closureCompilerOptions := Seq.empty[String],
  128. // Settings
  129. devSettings := Nil,
  130. // Templates
  131. templatesImport := Seq("play.api.templates._", "play.api.templates.PlayMagic._"),
  132. templatesTypes := {
  133. case "html" => ("play.api.templates.Html", "play.api.templates.HtmlFormat")
  134. case "txt" => ("play.api.templates.Txt", "play.api.templates.TxtFormat")
  135. case "xml" => ("play.api.templates.Xml", "play.api.templates.XmlFormat")
  136. })
  137. }