1 | import sbt._ |
---|
2 | import Keys._ |
---|
3 | |
---|
4 | object PlayBuild extends Build { |
---|
5 | |
---|
6 | import Resolvers._ |
---|
7 | import Dependencies._ |
---|
8 | import BuildSettings._ |
---|
9 | import Generators._ |
---|
10 | import LocalSBT._ |
---|
11 | import Tasks._ |
---|
12 | |
---|
13 | lazy val TemplatesProject = Project( |
---|
14 | "Templates", |
---|
15 | file("src/templates"), |
---|
16 | settings = buildSettings ++ Seq( |
---|
17 | libraryDependencies := templatesDependencies, |
---|
18 | publishTo := Some(playRepository), |
---|
19 | publishArtifact in (Compile, packageDoc) := false, |
---|
20 | publishArtifact in (Compile, packageSrc) := false, |
---|
21 | unmanagedJars in Compile += compilerJar, |
---|
22 | scalacOptions ++= Seq("-Xlint","-deprecation", "-unchecked","-encoding", "utf8"), |
---|
23 | javacOptions ++= Seq("-encoding", "utf8"), |
---|
24 | resolvers += typesafe |
---|
25 | ) |
---|
26 | ).settings(com.typesafe.sbtscalariform.ScalariformPlugin.defaultScalariformSettings: _*) |
---|
27 | |
---|
28 | lazy val AnormProject = Project( |
---|
29 | "Anorm", |
---|
30 | file("src/anorm"), |
---|
31 | settings = buildSettings ++ Seq( |
---|
32 | libraryDependencies := anormDependencies, |
---|
33 | publishTo := Some(playRepository), |
---|
34 | scalacOptions ++= Seq("-encoding", "utf8"), |
---|
35 | javacOptions ++= Seq("-encoding", "utf8"), |
---|
36 | publishArtifact in (Compile, packageDoc) := false, |
---|
37 | publishArtifact in (Compile, packageSrc) := true |
---|
38 | ) |
---|
39 | ).settings(com.typesafe.sbtscalariform.ScalariformPlugin.defaultScalariformSettings: _*) |
---|
40 | |
---|
41 | lazy val PlayProject = Project( |
---|
42 | "Play", |
---|
43 | file("src/play"), |
---|
44 | settings = buildSettings ++ Seq( |
---|
45 | libraryDependencies := runtime, |
---|
46 | sourceGenerators in Compile <+= sourceManaged in Compile map PlayVersion, |
---|
47 | publishTo := Some(playRepository), |
---|
48 | scalacOptions ++= Seq("-Xlint","-deprecation", "-unchecked","-encoding", "utf8"), |
---|
49 | javacOptions ++= Seq("-encoding", "utf8"), |
---|
50 | publishArtifact in (Compile, packageDoc) := false, |
---|
51 | publishArtifact in (Compile, packageSrc) := true, |
---|
52 | resolvers += typesafe, |
---|
53 | sourceGenerators in Compile <+= (dependencyClasspath in TemplatesProject in Runtime, packageBin in TemplatesProject in Compile, scalaSource in Compile, sourceManaged in Compile, streams) map ScalaTemplates, |
---|
54 | compile in (Compile) <<= PostCompile |
---|
55 | ) |
---|
56 | ).settings(com.typesafe.sbtscalariform.ScalariformPlugin.defaultScalariformSettings: _*).dependsOn(TemplatesProject, AnormProject) |
---|
57 | |
---|
58 | lazy val PlayTestProject = Project( |
---|
59 | "Play-Test", |
---|
60 | file("src/play-test"), |
---|
61 | settings = buildSettings ++ Seq( |
---|
62 | libraryDependencies := testDependencies, |
---|
63 | publishTo := Some(playRepository), |
---|
64 | scalacOptions ++= Seq("-deprecation","-Xcheckinit", "-encoding", "utf8"), |
---|
65 | javacOptions ++= Seq("-encoding", "utf8"), |
---|
66 | publishArtifact in (Compile, packageDoc) := false, |
---|
67 | publishArtifact in (Compile, packageSrc) := true, |
---|
68 | resolvers += typesafe |
---|
69 | ) |
---|
70 | ).settings(com.typesafe.sbtscalariform.ScalariformPlugin.defaultScalariformSettings: _*).dependsOn(PlayProject) |
---|
71 | |
---|
72 | lazy val SbtPluginProject = Project( |
---|
73 | "SBT-Plugin", |
---|
74 | file("src/sbt-plugin"), |
---|
75 | settings = buildSettings ++ Seq( |
---|
76 | sbtPlugin := true, |
---|
77 | publishMavenStyle := false, |
---|
78 | libraryDependencies := sbtDependencies, |
---|
79 | addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-core" % "2.0.0"), |
---|
80 | unmanagedJars in Compile ++= sbtJars, |
---|
81 | publishTo := Some(playIvyRepository), |
---|
82 | scalacOptions ++= Seq("-Xlint", "-deprecation", "-unchecked","-encoding", "utf8"), |
---|
83 | javacOptions ++= Seq("-encoding", "utf8"), |
---|
84 | publishArtifact in (Compile, packageDoc) := false, |
---|
85 | publishArtifact in (Compile, packageSrc) := false, |
---|
86 | resolvers += typesafe |
---|
87 | ) |
---|
88 | ).settings(com.typesafe.sbtscalariform.ScalariformPlugin.defaultScalariformSettings: _*).dependsOn(PlayProject, TemplatesProject, ConsoleProject) |
---|
89 | |
---|
90 | lazy val ConsoleProject = Project( |
---|
91 | "Console", |
---|
92 | file("src/console"), |
---|
93 | settings = buildSettings ++ Seq( |
---|
94 | libraryDependencies := consoleDependencies, |
---|
95 | sourceGenerators in Compile <+= sourceManaged in Compile map PlayVersion, |
---|
96 | unmanagedJars in Compile ++= sbtJars, |
---|
97 | publishTo := Some(playRepository), |
---|
98 | scalacOptions ++= Seq("-deprecation","-Xcheckinit", "-encoding", "utf8"), |
---|
99 | javacOptions ++= Seq("-encoding", "utf8"), |
---|
100 | publishArtifact in (Compile, packageDoc) := false, |
---|
101 | publishArtifact in (Compile, packageSrc) := true, |
---|
102 | resolvers += typesafe |
---|
103 | ) |
---|
104 | ).settings(com.typesafe.sbtscalariform.ScalariformPlugin.defaultScalariformSettings: _*) |
---|
105 | |
---|
106 | val Root = Project( |
---|
107 | "Root", |
---|
108 | file("."), |
---|
109 | settings = buildSettings ++ Seq( |
---|
110 | libraryDependencies := runtime, |
---|
111 | cleanFiles ++= Seq(file("../dist"), file("../repository/local")), |
---|
112 | resetRepositoryTask, |
---|
113 | buildRepositoryTask, |
---|
114 | distTask, |
---|
115 | generateAPIDocsTask, |
---|
116 | publish <<= (publish in PlayProject, publish in TemplatesProject, publish in AnormProject, publish in SbtPluginProject, publish in ConsoleProject, publish in PlayTestProject) map { (_,_,_,_,_,_) => }, |
---|
117 | publishLocal <<= (publishLocal in PlayProject, publishLocal in TemplatesProject, publishLocal in AnormProject, publishLocal in SbtPluginProject, publishLocal in ConsoleProject, publishLocal in PlayTestProject) map { (_,_,_,_,_,_) => } |
---|
118 | ) |
---|
119 | ).settings(com.typesafe.sbtscalariform.ScalariformPlugin.defaultScalariformSettings: _*) |
---|
120 | .dependsOn(PlayProject).aggregate(AnormProject, TemplatesProject, PlayProject, SbtPluginProject, ConsoleProject, PlayTestProject) |
---|
121 | |
---|
122 | object BuildSettings { |
---|
123 | |
---|
124 | val buildOrganization = "play" |
---|
125 | val buildVersion = Option(System.getProperty("play.version")).filterNot(_.isEmpty).getOrElse("2.0-unknown") |
---|
126 | val buildScalaVersion = "2.9.1" |
---|
127 | val buildSbtVersion = "0.11.2" |
---|
128 | |
---|
129 | val buildSettings = Defaults.defaultSettings ++ Seq ( |
---|
130 | organization := buildOrganization, |
---|
131 | version := buildVersion, |
---|
132 | scalaVersion := buildScalaVersion, |
---|
133 | logManager <<= extraLoggers(PlayLogManager.default), |
---|
134 | ivyLoggingLevel := UpdateLogging.DownloadOnly |
---|
135 | ) |
---|
136 | |
---|
137 | } |
---|
138 | |
---|
139 | object LocalSBT { |
---|
140 | |
---|
141 | import BuildSettings._ |
---|
142 | |
---|
143 | def isJar(f:java.io.File) = f.getName.endsWith(".jar") |
---|
144 | |
---|
145 | val sbtJars:Seq[java.io.File] = { |
---|
146 | file("sbt/boot/scala-" + buildScalaVersion + "/org.scala-tools.sbt/sbt/" + buildSbtVersion).listFiles.filter(isJar) ++ |
---|
147 | file("sbt/boot/scala-" + buildScalaVersion + "/org.scala-tools.sbt/sbt/" + buildSbtVersion + "/xsbti").listFiles.filter(isJar) ++ |
---|
148 | Seq(file("sbt/boot/scala-" + buildScalaVersion + "/lib/jline.jar")) |
---|
149 | } |
---|
150 | |
---|
151 | val compilerJar:java.io.File = { |
---|
152 | file("sbt/boot/scala-" + buildScalaVersion + "/lib/scala-compiler.jar") |
---|
153 | } |
---|
154 | |
---|
155 | } |
---|
156 | |
---|
157 | object Resolvers { |
---|
158 | import BuildSettings._ |
---|
159 | |
---|
160 | val playLocalRepository = Resolver.file("Play Local Repository", file("../repository/local"))(Resolver.ivyStylePatterns) |
---|
161 | |
---|
162 | val typesafe = "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/" |
---|
163 | |
---|
164 | val typesafeReleases = "Typesafe Releases Repository" at "http://repo.typesafe.com/typesafe/maven-releases/" |
---|
165 | val typesafeSnapshot = "Typesafe Snapshots Repository" at "http://repo.typesafe.com/typesafe/maven-snapshots/" |
---|
166 | val playRepository = if (buildVersion.endsWith("SNAPSHOT")) typesafeSnapshot else typesafeReleases |
---|
167 | |
---|
168 | val typesafeIvyReleases = Resolver.url("Typesafe Ivy Releases Repository", url("http://repo.typesafe.com/typesafe/ivy-releases/"))(Resolver.ivyStylePatterns) |
---|
169 | val typesafeIvySnapshot = Resolver.url("Typesafe Ivy Snapshots Repository", url("http://repo.typesafe.com/typesafe/ivy-snapshots/"))(Resolver.ivyStylePatterns) |
---|
170 | val playIvyRepository = if (buildVersion.endsWith("SNAPSHOT")) typesafeIvySnapshot else typesafeIvyReleases |
---|
171 | } |
---|
172 | |
---|
173 | object Dependencies { |
---|
174 | |
---|
175 | val runtime = Seq( |
---|
176 | "io.netty" % "netty" % "3.3.0.Final", |
---|
177 | "org.slf4j" % "slf4j-api" % "1.6.4", |
---|
178 | "org.slf4j" % "jul-to-slf4j" % "1.6.4", |
---|
179 | "org.slf4j" % "jcl-over-slf4j" % "1.6.4", |
---|
180 | "ch.qos.logback" % "logback-core" % "1.0.0", |
---|
181 | "ch.qos.logback" % "logback-classic" % "1.0.0", |
---|
182 | "com.github.scala-incubator.io" %% "scala-io-file" % "0.2.0", |
---|
183 | "com.typesafe.akka" % "akka-actor" % "2.0.1", |
---|
184 | "com.typesafe.akka" % "akka-slf4j" % "2.0.1", |
---|
185 | "com.google.guava" % "guava" % "10.0.1", |
---|
186 | |
---|
187 | ("org.avaje" % "ebean" % "2.7.3" notTransitive()) |
---|
188 | .exclude("javax.persistence", "persistence-api") |
---|
189 | , |
---|
190 | |
---|
191 | "org.hibernate.javax.persistence" % "hibernate-jpa-2.0-api" % "1.0.1.Final", |
---|
192 | "com.h2database" % "h2" % "1.3.158", |
---|
193 | "org.scala-tools" %% "scala-stm" % "0.4", |
---|
194 | |
---|
195 | ("com.jolbox" % "bonecp" % "0.7.1.RELEASE" notTransitive()) |
---|
196 | .exclude("com.google.guava", "guava") |
---|
197 | .exclude("org.slf4j", "slf4j-api") |
---|
198 | , |
---|
199 | |
---|
200 | "org.yaml" % "snakeyaml" % "1.9", |
---|
201 | "org.hibernate" % "hibernate-validator" % "4.2.0.Final", |
---|
202 | |
---|
203 | ("org.springframework" % "spring-context" % "3.0.7.RELEASE" notTransitive()) |
---|
204 | .exclude("org.springframework", "spring-aop") |
---|
205 | .exclude("org.springframework", "spring-beans") |
---|
206 | .exclude("org.springframework", "spring-core") |
---|
207 | .exclude("org.springframework", "spring-expression") |
---|
208 | .exclude("org.springframework", "spring-asm") |
---|
209 | , |
---|
210 | |
---|
211 | ("org.springframework" % "spring-core" % "3.0.7.RELEASE" notTransitive()) |
---|
212 | .exclude("org.springframework", "spring-asm") |
---|
213 | .exclude("commons-logging", "commons-logging") |
---|
214 | , |
---|
215 | |
---|
216 | ("org.springframework" % "spring-beans" % "3.0.7.RELEASE" notTransitive()) |
---|
217 | .exclude("org.springframework", "spring-core") |
---|
218 | , |
---|
219 | |
---|
220 | "joda-time" % "joda-time" % "2.0", |
---|
221 | "org.joda" % "joda-convert" % "1.1", |
---|
222 | "javassist" % "javassist" % "3.12.1.GA", |
---|
223 | "commons-lang" % "commons-lang" % "2.6", |
---|
224 | |
---|
225 | ("com.ning" % "async-http-client" % "1.7.0" notTransitive()) |
---|
226 | .exclude("org.jboss.netty", "netty") |
---|
227 | , |
---|
228 | |
---|
229 | "oauth.signpost" % "signpost-core" % "1.2.1.1", |
---|
230 | "com.codahale" %% "jerkson" % "0.5.0", |
---|
231 | |
---|
232 | ("org.reflections" % "reflections" % "0.9.6" notTransitive()) |
---|
233 | .exclude("com.google.guava", "guava") |
---|
234 | .exclude("javassist", "javassist") |
---|
235 | , |
---|
236 | |
---|
237 | "javax.servlet" % "javax.servlet-api" % "3.0.1", |
---|
238 | "javax.transaction" % "jta" % "1.1", |
---|
239 | "tyrex" % "tyrex" % "1.0.1", |
---|
240 | |
---|
241 | ("jaxen" % "jaxen" % "1.1.3" notTransitive()) |
---|
242 | .exclude("maven-plugins", "maven-cobertura-plugin") |
---|
243 | .exclude("maven-plugins", "maven-findbugs-plugin") |
---|
244 | .exclude("dom4j", "dom4j") |
---|
245 | .exclude("jdom", "jdom") |
---|
246 | .exclude("xml-apis", "xml-apis") |
---|
247 | .exclude("xerces", "xercesImpl") |
---|
248 | .exclude("xom", "xom") |
---|
249 | , |
---|
250 | |
---|
251 | "net.sf.ehcache" % "ehcache-core" % "2.5.0", |
---|
252 | |
---|
253 | "org.specs2" %% "specs2" % "1.7.1" % "test", |
---|
254 | "com.novocode" % "junit-interface" % "0.8" % "test", |
---|
255 | |
---|
256 | "org.fluentlenium" % "fluentlenium-festassert" % "0.5.6" % "test" |
---|
257 | ) |
---|
258 | |
---|
259 | val sbtDependencies = Seq( |
---|
260 | "com.typesafe.config" % "config" % "0.2.1", |
---|
261 | "rhino" % "js" % "1.7R2", |
---|
262 | |
---|
263 | ("com.google.javascript" % "closure-compiler" % "r1810" notTransitive()) |
---|
264 | .exclude("args4j", "args4j") |
---|
265 | .exclude("com.google.guava", "guava") |
---|
266 | .exclude("org.json", "json") |
---|
267 | .exclude("com.google.protobuf", "protobuf-java") |
---|
268 | .exclude("org.apache.ant", "ant") |
---|
269 | .exclude("com.google.code.findbugs", "jsr305") |
---|
270 | .exclude("com.googlecode.jarjar", "jarjar") |
---|
271 | .exclude("junit", "junit") |
---|
272 | , |
---|
273 | |
---|
274 | "com.github.scala-incubator.io" %% "scala-io-file" % "0.2.0", |
---|
275 | |
---|
276 | ("org.avaje" % "ebean" % "2.7.3" notTransitive()) |
---|
277 | .exclude("javax.persistence", "persistence-api") |
---|
278 | , |
---|
279 | |
---|
280 | "com.h2database" % "h2" % "1.3.158", |
---|
281 | "javassist" % "javassist" % "3.12.1.GA", |
---|
282 | "org.pegdown" % "pegdown" % "1.1.0" |
---|
283 | ) |
---|
284 | |
---|
285 | val consoleDependencies = Seq( |
---|
286 | "com.github.scala-incubator.io" %% "scala-io-file" % "0.2.0" |
---|
287 | ) |
---|
288 | |
---|
289 | val templatesDependencies = Seq( |
---|
290 | "com.github.scala-incubator.io" %% "scala-io-file" % "0.2.0", |
---|
291 | "org.specs2" %% "specs2" % "1.7.1" % "test" |
---|
292 | ) |
---|
293 | |
---|
294 | val anormDependencies = Seq( |
---|
295 | ) |
---|
296 | |
---|
297 | val testDependencies = Seq( |
---|
298 | "org.specs2" %% "specs2" % "1.7.1", |
---|
299 | "com.novocode" % "junit-interface" % "0.8", |
---|
300 | |
---|
301 | "org.fluentlenium" % "fluentlenium-festassert" % "0.5.6" |
---|
302 | ) |
---|
303 | |
---|
304 | } |
---|
305 | |
---|
306 | object Generators { |
---|
307 | |
---|
308 | val PlayVersion = { dir:File => |
---|
309 | val file = dir / "PlayVersion.scala" |
---|
310 | IO.write(file, |
---|
311 | """|package play.core |
---|
312 | | |
---|
313 | |object PlayVersion { |
---|
314 | | val current = "%s" |
---|
315 | |} |
---|
316 | """.stripMargin.format(BuildSettings.buildVersion) |
---|
317 | ) |
---|
318 | Seq(file) |
---|
319 | } |
---|
320 | |
---|
321 | } |
---|
322 | |
---|
323 | // ----- Post compile |
---|
324 | |
---|
325 | lazy val PostCompile = (dependencyClasspath in Compile, compile in Compile, classDirectory in Compile) map { (deps,analysis,classes) => |
---|
326 | |
---|
327 | // Ebean (really hacky sorry) |
---|
328 | |
---|
329 | import java.net._ |
---|
330 | |
---|
331 | val cp = deps.map(_.data.toURL).toArray :+ classes.toURL |
---|
332 | val cl = new URLClassLoader(cp) |
---|
333 | |
---|
334 | val t = cl.loadClass("com.avaje.ebean.enhance.agent.Transformer").getConstructor(classOf[Array[URL]], classOf[String]).newInstance(cp, "debug=0").asInstanceOf[AnyRef] |
---|
335 | val ft = cl.loadClass("com.avaje.ebean.enhance.ant.OfflineFileTransform").getConstructor( |
---|
336 | t.getClass, classOf[ClassLoader], classOf[String], classOf[String] |
---|
337 | ).newInstance(t, ClassLoader.getSystemClassLoader, classes.getAbsolutePath, classes.getAbsolutePath).asInstanceOf[AnyRef] |
---|
338 | |
---|
339 | ft.getClass.getDeclaredMethod("process", classOf[String]).invoke(ft,"play/db/ebean/**") |
---|
340 | |
---|
341 | analysis |
---|
342 | } |
---|
343 | |
---|
344 | |
---|
345 | object Tasks { |
---|
346 | |
---|
347 | import BuildSettings._ |
---|
348 | |
---|
349 | // ----- Reset repo |
---|
350 | |
---|
351 | val resetRepository = TaskKey[File]("reset-repository") |
---|
352 | val resetRepositoryTask = resetRepository := { |
---|
353 | val repository = file("../repository/local") |
---|
354 | IO.createDirectory(repository) |
---|
355 | repository |
---|
356 | } |
---|
357 | |
---|
358 | // ----- Generate API docs |
---|
359 | |
---|
360 | val generateAPIDocs = TaskKey[Unit]("api-docs") |
---|
361 | val generateAPIDocsTask = TaskKey[Unit]("api-docs") <<= (fullClasspath in Test, compilers, streams) map { (classpath, cs, s) => |
---|
362 | |
---|
363 | IO.delete(file("../documentation/api")) |
---|
364 | // Scaladoc |
---|
365 | val sourceFiles = |
---|
366 | (file("src/play/src/main/scala/play/api") ** "*.scala").get ++ |
---|
367 | (file("src/play-test/src/main/scala") ** "*.scala").get ++ |
---|
368 | (file("src/play/src/main/scala/views") ** "*.scala").get ++ |
---|
369 | (file("src/anorm/src/main/scala") ** "*.scala").get ++ |
---|
370 | (file("src/play/target/scala-2.9.1/src_managed/main/views/html/helper") ** "*.scala").get |
---|
371 | new Scaladoc(10, cs.scalac)("Play " + BuildSettings.buildVersion + " Scala API", sourceFiles, classpath.map(_.data), file("../documentation/api/scala"), Nil, s.log) |
---|
372 | |
---|
373 | // Javadoc |
---|
374 | val javaSources = Seq(file("src/play/src/main/java"), file("src/play-test/src/main/java")).mkString(":") |
---|
375 | val javaApiTarget = file("../documentation/api/java") |
---|
376 | val javaClasspath = classpath.map(_.data).mkString(":") |
---|
377 | """javadoc -windowtitle playframework -doctitle Play """ + BuildSettings.buildVersion + """ Java API -sourcepath %s -d %s -subpackages play -exclude play.api:play.core -classpath %s""".format(javaSources, javaApiTarget, javaClasspath) ! s.log |
---|
378 | |
---|
379 | } |
---|
380 | |
---|
381 | // ----- Build repo |
---|
382 | |
---|
383 | val buildRepository = TaskKey[Unit]("build-repository") |
---|
384 | val buildRepositoryTask = TaskKey[Unit]("build-repository") <<= (resetRepository, update, update in test, publishLocal, scalaVersion, streams) map { (repository, updated, testUpdated, published, scalaVersion, s) => |
---|
385 | |
---|
386 | def checksum(algo:String)(bytes:Array[Byte]) = { |
---|
387 | import java.security.MessageDigest |
---|
388 | val digest = MessageDigest.getInstance(algo) |
---|
389 | digest.reset() |
---|
390 | digest.update(bytes) |
---|
391 | digest.digest().map(0xFF & _).map { "%02x".format(_) }.foldLeft(""){_ + _} |
---|
392 | } |
---|
393 | |
---|
394 | def copyWithChecksums(files:(File,File)) { |
---|
395 | IO.copyFile(files._1, files._2) |
---|
396 | Seq("md5","sha1").foreach { algo => |
---|
397 | IO.write(file(files._2.getAbsolutePath + "." + algo), checksum(algo)(IO.readBytes(files._2))) |
---|
398 | } |
---|
399 | } |
---|
400 | |
---|
401 | def writeWithChecksums(f:File, content:String) { |
---|
402 | IO.write(f, content) |
---|
403 | Seq("md5","sha1").foreach { algo => |
---|
404 | IO.write(file(f.getAbsolutePath + "." + algo), checksum(algo)(content.getBytes)) |
---|
405 | } |
---|
406 | } |
---|
407 | |
---|
408 | // Retrieve all ivy files from cache |
---|
409 | // (since we cleaned the cache and run update just before, all these dependencies are useful) |
---|
410 | val ivyFiles = ((repository / "../cache" * "*").filter { d => |
---|
411 | d.isDirectory && d.getName != "scala_%s".format(scalaVersion) |
---|
412 | } ** "ivy-*.xml").get |
---|
413 | |
---|
414 | // From the ivy files, deduct the dependencies |
---|
415 | val dependencies = ivyFiles.map { descriptor => |
---|
416 | val organization = descriptor.getParentFile.getParentFile.getName |
---|
417 | val name = descriptor.getParentFile.getName |
---|
418 | val version = descriptor.getName.drop(4).dropRight(4) |
---|
419 | descriptor -> (organization, name, version) |
---|
420 | } |
---|
421 | |
---|
422 | // Resolve artifacts for these dependencies (only jars) |
---|
423 | val dependenciesWithArtifacts = dependencies.map { |
---|
424 | case (descriptor, (organization, name, version)) => { |
---|
425 | var jars = (descriptor.getParentFile ** ("*-" + version + ".jar")).get |
---|
426 | s.log.info("Found dependency %s::%s::%s -> %s".format( |
---|
427 | organization, name, version, jars.map(_.getName).mkString(", ") |
---|
428 | )) |
---|
429 | (descriptor, jars, (organization, name, version)) |
---|
430 | } |
---|
431 | } |
---|
432 | |
---|
433 | // Build the local repository from these informations |
---|
434 | dependenciesWithArtifacts.foreach { |
---|
435 | case (descriptor, jars, (organization, name, version)) => { |
---|
436 | val dependencyDir = repository / organization / name / version |
---|
437 | val artifacts = jars.map(j => dependencyDir / j.getParentFile.getName / (j.getName.dropRight(5 + version.size) + ".jar")) |
---|
438 | val ivy = dependencyDir / "ivys/ivy.xml" |
---|
439 | |
---|
440 | (Seq(descriptor -> ivy) ++ jars.zip(artifacts)).foreach(copyWithChecksums) |
---|
441 | } |
---|
442 | } |
---|
443 | |
---|
444 | // Special sbt plugins |
---|
445 | val pluginIvyFiles = ((repository / "../cache/scala_%s/sbt_%s".format(buildScalaVersion, buildSbtVersion) * "*").filter { d => |
---|
446 | d.isDirectory && d.getName != "play" |
---|
447 | } ** "ivy-*.xml").get |
---|
448 | |
---|
449 | // From the ivy files, deduct the dependencies |
---|
450 | val pluginDependencies = pluginIvyFiles.map { descriptor => |
---|
451 | val organization = descriptor.getParentFile.getParentFile.getName |
---|
452 | val name = descriptor.getParentFile.getName |
---|
453 | val version = descriptor.getName.drop(4).dropRight(4) |
---|
454 | descriptor -> (organization, name, version) |
---|
455 | } |
---|
456 | |
---|
457 | // Resolve artifacts for these dependencies (only jars) |
---|
458 | val pluginDependenciesWithArtifacts = pluginDependencies.map { |
---|
459 | case (descriptor, (organization, name, version)) => { |
---|
460 | var jars = (descriptor.getParentFile ** ("*-" + version + ".jar")).get |
---|
461 | s.log.info("Found dependency %s::%s::%s -> %s".format( |
---|
462 | organization, name, version, jars.map(_.getName).mkString(", ") |
---|
463 | )) |
---|
464 | (descriptor, jars, (organization, name, version)) |
---|
465 | } |
---|
466 | } |
---|
467 | |
---|
468 | // Build the local repository from these informations |
---|
469 | pluginDependenciesWithArtifacts.foreach { |
---|
470 | case (descriptor, jars, (organization, name, version)) => { |
---|
471 | val dependencyDir = repository / organization / name / "scala_%s".format(buildScalaVersion) / "sbt_%s".format(buildSbtVersion) / version |
---|
472 | val artifacts = jars.map(j => dependencyDir / j.getParentFile.getName / (j.getName.dropRight(5 + version.size) + ".jar")) |
---|
473 | val ivy = dependencyDir / "ivys/ivy.xml" |
---|
474 | |
---|
475 | (Seq(descriptor -> ivy) ++ jars.zip(artifacts)).foreach(copyWithChecksums) |
---|
476 | } |
---|
477 | } |
---|
478 | |
---|
479 | } |
---|
480 | |
---|
481 | // ----- Dist package |
---|
482 | |
---|
483 | val dist = TaskKey[File]("dist") |
---|
484 | val distTask = dist <<= (buildRepository, publish, generateAPIDocs) map { (_,_,_) => |
---|
485 | |
---|
486 | import sbt.NameFilter._ |
---|
487 | |
---|
488 | val root = file("..") |
---|
489 | val packageName = "play-" + buildVersion |
---|
490 | |
---|
491 | val files = { |
---|
492 | (root ** "*") --- |
---|
493 | (root ** "dist") --- |
---|
494 | (root ** "dist" ** "*") --- |
---|
495 | (root ** "*.log") --- |
---|
496 | (root ** "logs") --- |
---|
497 | (root / "repository/cache") --- |
---|
498 | (root / "repository/cache" ** "*") --- |
---|
499 | (root / "framework/sbt/boot") --- |
---|
500 | (root / "framework/sbt/boot" ** "*") --- |
---|
501 | (root ** "project/project") --- |
---|
502 | (root ** "target") --- |
---|
503 | (root ** "target" ** "*") --- |
---|
504 | (root ** ".*") --- |
---|
505 | (root ** ".*") --- |
---|
506 | (root ** ".git" ** "*") --- |
---|
507 | (root ** "*.lock") |
---|
508 | } |
---|
509 | |
---|
510 | val zipFile = root / "dist" / (packageName + ".zip") |
---|
511 | |
---|
512 | IO.delete(root / "dist") |
---|
513 | IO.createDirectory(root / "dist") |
---|
514 | IO.zip(files x rebase(root, packageName), zipFile) |
---|
515 | |
---|
516 | zipFile |
---|
517 | } |
---|
518 | |
---|
519 | // ----- Compile templates |
---|
520 | |
---|
521 | val ScalaTemplates = { (classpath:Seq[Attributed[File]], templateEngine:File, sourceDirectory:File, generatedDir:File, streams:sbt.std.TaskStreams[sbt.Project.ScopedKey[_]]) => |
---|
522 | val classloader = new java.net.URLClassLoader(classpath.map(_.data.toURI.toURL).toArray, this.getClass.getClassLoader) |
---|
523 | val compiler = classloader.loadClass("play.templates.ScalaTemplateCompiler") |
---|
524 | val generatedSource = classloader.loadClass("play.templates.GeneratedSource") |
---|
525 | |
---|
526 | (generatedDir ** "*.template.scala").get.foreach { source => |
---|
527 | val constructor = generatedSource.getDeclaredConstructor(classOf[java.io.File]) |
---|
528 | val sync = generatedSource.getDeclaredMethod("sync") |
---|
529 | val generated = constructor.newInstance(source) |
---|
530 | try { |
---|
531 | sync.invoke(generated) |
---|
532 | } catch { |
---|
533 | case e:java.lang.reflect.InvocationTargetException =>{ |
---|
534 | val t = e.getTargetException |
---|
535 | t.printStackTrace() |
---|
536 | throw t |
---|
537 | } |
---|
538 | } |
---|
539 | } |
---|
540 | |
---|
541 | (sourceDirectory ** "*.scala.html").get.foreach { template => |
---|
542 | val compile = compiler.getDeclaredMethod("compile", classOf[java.io.File], classOf[java.io.File], classOf[java.io.File], classOf[String], classOf[String], classOf[String]) |
---|
543 | try { |
---|
544 | compile.invoke(null, template, sourceDirectory, generatedDir, "play.api.templates.Html", "play.api.templates.HtmlFormat", "import play.api.templates._\nimport play.api.templates.PlayMagic._") |
---|
545 | } catch { |
---|
546 | case e:java.lang.reflect.InvocationTargetException => { |
---|
547 | streams.log.error("Compilation failed for %s".format(template)) |
---|
548 | throw e.getTargetException |
---|
549 | } |
---|
550 | } |
---|
551 | } |
---|
552 | |
---|
553 | (generatedDir ** "*.scala").get.map(_.getAbsoluteFile) |
---|
554 | } |
---|
555 | |
---|
556 | } |
---|
557 | |
---|
558 | } |
---|