PageRenderTime 159ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

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

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