PageRenderTime 21ms CodeModel.GetById 8ms app.highlight 9ms RepoModel.GetById 1ms 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
  1package sbt
  2
  3import Keys._
  4import PlayKeys._
  5
  6trait PlaySettings {
  7  this: PlayCommands with PlayPositionMapper =>
  8  
  9  protected def whichLang(name: String): Seq[Setting[_]] = {
 10    if (name == JAVA) {
 11      defaultJavaSettings
 12    } else if (name == SCALA) {
 13      defaultScalaSettings
 14    } else {
 15      Seq.empty
 16    }
 17  }
 18  lazy val defaultJavaSettings = Seq[Setting[_]](
 19
 20    templatesImport ++= Seq(
 21      "models._",
 22      "controllers._",
 23
 24      "java.lang._",
 25      "java.util._",
 26
 27      "scala.collection.JavaConversions._",
 28      "scala.collection.JavaConverters._",
 29
 30      "play.api.i18n._",
 31      "play.core.j.PlayMagicForJava._",
 32
 33      "play.mvc._",
 34      "play.data._",
 35      "play.api.data.Field",
 36
 37      "play.mvc.Http.Context.Implicit._",
 38
 39      "views.%format%._"),
 40
 41    routesImport ++= Seq(
 42      "play.libs.F"
 43    ),
 44
 45    ebeanEnabled := true
 46
 47  )
 48
 49  lazy val defaultScalaSettings = Seq[Setting[_]](
 50
 51    templatesImport ++= Seq(
 52      "models._",
 53      "controllers._",
 54
 55      "play.api.i18n._",
 56
 57      "play.api.mvc._",
 58      "play.api.data._",
 59
 60      "views.%format%._"))
 61
 62  def closureCompilerSettings(optionCompilerOptions: com.google.javascript.jscomp.CompilerOptions) = Seq[Setting[_]](
 63    resourceGenerators in Compile <<= JavascriptCompiler(Some(optionCompilerOptions))(Seq(_)),
 64    resourceGenerators in Compile <+= LessCompiler,
 65    resourceGenerators in Compile <+= CoffeescriptCompiler
 66  )
 67
 68  lazy val defaultSettings = Seq[Setting[_]](
 69
 70    scalaVersion := play.core.PlayVersion.scalaVersion,
 71
 72    playPlugin := false,
 73
 74    resolvers ++= Seq(
 75      "Typesafe Releases Repository" at "http://repo.typesafe.com/typesafe/releases/",
 76      "Typesafe Snapshots Repository" at "http://repo.typesafe.com/typesafe/snapshots/"
 77    ),
 78
 79    target <<= baseDirectory / "target",
 80
 81    sourceDirectory in Compile <<= baseDirectory / "app",
 82    sourceDirectory in Test <<= baseDirectory / "test",
 83
 84    confDirectory <<= baseDirectory / "conf",
 85
 86    resourceDirectory in Compile <<= baseDirectory / "conf",
 87
 88    scalaSource in Compile <<= baseDirectory / "app",
 89    scalaSource in Test <<= baseDirectory / "test",
 90
 91    javaSource in Compile <<= baseDirectory / "app",
 92    javaSource in Test <<= baseDirectory / "test",
 93
 94    distDirectory <<= baseDirectory / "dist",
 95
 96    distExcludes := Seq.empty,
 97
 98    libraryDependencies <+= (playPlugin) { isPlugin =>
 99      val d = "play" %% "play" % play.core.PlayVersion.current
100      if(isPlugin)
101         d % "provided"
102      else
103        d
104    },
105
106    libraryDependencies += "play" %% "play-test" % play.core.PlayVersion.current % "test",
107
108    parallelExecution in Test := false,
109
110    fork in Test := true,
111
112    testOptions in Test += Tests.Argument(TestFrameworks.Specs2, "sequential", "true"),
113
114    testOptions in Test += Tests.Argument(TestFrameworks.JUnit, "junitxml", "console"),
115
116    testListeners <<= (target, streams).map((t, s) => Seq(new eu.henkelmann.sbt.JUnitXmlTestsListener(t.getAbsolutePath, s.log))),
117
118    testResultReporter <<= testResultReporterTask,
119
120    testResultReporterReset <<= testResultReporterResetTask,
121
122    sourceGenerators in Compile <+= (state, confDirectory, sourceManaged in Compile, routesImport) map RouteFiles,
123
124    // Adds config directory's source files to continuous hot reloading
125    watchSources <+= confDirectory map { all => all },
126
127    sourceGenerators in Compile <+= (state, sourceDirectory in Compile, sourceManaged in Compile, templatesTypes, templatesImport) map ScalaTemplates,
128
129    // Adds app directory's source files to continuous hot reloading
130    watchSources <++= baseDirectory map { path => ((path / "app") ** "*").get },
131
132    commands ++= Seq(shCommand, playCommand, playRunCommand, playStartCommand, h2Command, classpathCommand, licenseCommand, computeDependenciesCommand),
133
134    shellPrompt := playPrompt,
135
136    copyResources in Compile <<= (copyResources in Compile, playCopyAssets) map { (r, pr) => r ++ pr },
137
138    mainClass in (Compile, run) := Some("play.core.server.NettyServer"),
139
140    compile in (Compile) <<= PostCompile(scope = Compile),
141
142    dist <<= distTask,
143
144    computeDependencies <<= computeDependenciesTask,
145
146    playVersion := play.core.PlayVersion.current,
147
148    playCommonClassloader <<= playCommonClassloaderTask,
149
150    playCopyAssets <<= playCopyAssetsTask,
151
152    playCompileEverything <<= playCompileEverythingTask,
153
154    playPackageEverything <<= playPackageEverythingTask,
155
156    playReload <<= playReloadTask,
157
158    playStage <<= playStageTask,
159
160    cleanFiles <+= distDirectory,
161
162    logManager <<= extraLoggers(PlayLogManager.default(playPositionMapper)),
163
164    ivyLoggingLevel := UpdateLogging.DownloadOnly,
165
166    routesImport := Seq.empty[String],
167
168    playMonitoredFiles <<= playMonitoredFilesTask,
169
170    playDefaultPort := 9000,
171
172    playOnStarted := Nil,
173
174    playOnStopped := Nil,
175
176    // Assets
177
178    playAssetsDirectories := Seq.empty[File],
179
180    playExternalAssets := Seq.empty[(File, File => PathFinder, String)],
181
182    playAssetsDirectories <+= baseDirectory / "public",
183
184    requireJs := Nil,
185
186    requireJsFolder := "",
187
188    requireJsShim := "",
189
190    requireNativePath := None,
191
192    buildRequire <<= buildRequireTask,
193
194    packageBin in Compile <<= (packageBin in Compile).dependsOn(buildRequire),
195
196    resourceGenerators in Compile <+= LessCompiler,
197    resourceGenerators in Compile <+= CoffeescriptCompiler,
198    resourceGenerators in Compile <+= JavascriptCompiler(fullCompilerOptions = None),
199
200    lessEntryPoints <<= (sourceDirectory in Compile)(base => ((base / "assets" ** "*.less") --- base / "assets" ** "_*")),
201    coffeescriptEntryPoints <<= (sourceDirectory in Compile)(base => base / "assets" ** "*.coffee"),
202    javascriptEntryPoints <<= (sourceDirectory in Compile)(base => ((base / "assets" ** "*.js") --- (base / "assets" ** "_*"))),
203
204    lessOptions := Seq.empty[String],
205    coffeescriptOptions := Seq.empty[String],
206    closureCompilerOptions := Seq.empty[String],
207
208    // Settings
209
210    devSettings := Nil,
211
212    // Templates
213
214    templatesImport := Seq("play.api.templates._", "play.api.templates.PlayMagic._"),
215
216    templatesTypes := {
217      case "html" => ("play.api.templates.Html", "play.api.templates.HtmlFormat")
218      case "txt" => ("play.api.templates.Txt", "play.api.templates.TxtFormat")
219      case "xml" => ("play.api.templates.Xml", "play.api.templates.XmlFormat")
220    })
221
222}