Skip to content

Commit

Permalink
Fix the template build
Browse files Browse the repository at this point in the history
* Made template build no longer depend on the Play build - this was
  causing big issues and confusion with scala versions etc. Instead it
  now depends on a static version of play-ws, which is ok.
* Made template build read Play version from version.sbt, but make it
  overridable for when we publish templates.
* Made template build default to Scala 2.10.5 for snapshots (this means
  it will work in CI) and 2.11.6 for production versions (which is what
  we want when we deploy the templates).
* Fixed #4551, logback.xml configuration was missing coloredLevel
  configuration.
* Provided a logback.xml to template build so that s3 plugin and template
  publishing doesn't spew massive amounts of debug to console.
  • Loading branch information
jroper committed May 28, 2015
1 parent 0a07c82 commit 5d7adcb
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 15 deletions.
33 changes: 21 additions & 12 deletions templates/build.sbt
@@ -1,9 +1,16 @@
import play.sbt.activator.Templates._
import play.core.PlayVersion

templateSettings

scalaVersion := "2.10.5"
scalaVersion := {
// If we're a snapshot build, then default to 2.10.5, since this is what gets built by default for Play
// If we're a production build, then we want 2.11.6
sys.props.getOrElse("scala.version", if (isSnapshot.value) {
"2.10.5"
} else {
"2.11.6"
})
}

crossScalaVersions := Seq("2.10.5", "2.11.6")

Expand All @@ -18,31 +25,33 @@ templates := {
).map(template => dir / template)
}

lazy val playDocsUrl = {
version := sys.props.getOrElse("play.version", version.value)

def playDocsUrl(version: String) = {
// Use a version like 2.4.x for the documentation
val docVersion = PlayVersion.current.replaceAll("""(\d+)\.(\d+)\D(.*)""", "$1.$2.x")
val docVersion = version.replaceAll("""(\d+)\.(\d+)\D(.*)""", "$1.$2.x")
s"http://www.playframework.com/documentation/${docVersion}"
}

// Use different names for release and milestone templates
lazy val templateNameAndTitle = {
val officialRelease = PlayVersion.current.matches("[0-9.]+") // Match final versions but not *-SNAPSHOT or *-RC1
def templateNameAndTitle(version: String) = {
val officialRelease = version.matches("[0-9.]+") // Match final versions but not *-SNAPSHOT or *-RC1
if (officialRelease) ("", "") else ("-preview", " (Preview)")
}

templateParameters := Map(
"PLAY_VERSION" -> PlayVersion.current,
"PLAY_VERSION" -> version.value,
"SCALA_VERSION" -> scalaVersion.value,
"PLAY_DOCS_URL" -> playDocsUrl,
"PLAY_DOCS_URL" -> playDocsUrl(version.value),
"SBT_VERSION" -> "0.13.8",
"COFFEESCRIPT_VERSION" -> "1.0.0",
"LESS_VERSION" -> "1.0.6",
"JSHINT_VERSION" -> "1.0.3",
"DIGEST_VERSION" -> "1.1.0",
"RJS_VERSION" -> "1.0.7",
"MOCHA_VERSION" -> "1.1.0",
"ENHANCER_VERSION" -> "1.1.0-RC2",
"EBEAN_VERSION" -> "1.0.0-RC1",
"TEMPLATE_NAME_SUFFIX" -> templateNameAndTitle._1,
"TEMPLATE_TITLE_SUFFIX" -> templateNameAndTitle._2
"ENHANCER_VERSION" -> "1.1.0",
"EBEAN_VERSION" -> "1.0.0",
"TEMPLATE_NAME_SUFFIX" -> templateNameAndTitle(version.value)._1,
"TEMPLATE_TITLE_SUFFIX" -> templateNameAndTitle(version.value)._2
)
2 changes: 2 additions & 0 deletions templates/play-java-intro/conf/logback.xml
@@ -1,4 +1,6 @@
<configuration>

<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
Expand Down
2 changes: 2 additions & 0 deletions templates/play-java/conf/logback.xml
@@ -1,4 +1,6 @@
<configuration>

<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
Expand Down
2 changes: 2 additions & 0 deletions templates/play-scala-intro/conf/logback.xml
@@ -1,4 +1,6 @@
<configuration>

<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
Expand Down
2 changes: 2 additions & 0 deletions templates/play-scala/conf/logback.xml
@@ -1,4 +1,6 @@
<configuration>

<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
Expand Down
18 changes: 17 additions & 1 deletion templates/project/Build.scala
Expand Up @@ -5,6 +5,20 @@ import sbt.Keys._
import com.typesafe.sbt.S3Plugin._
import sbt.complete.{Parsers, Parser}

/**
* This must be here, and not in build.sbt, since Project.setSbtFiles only works from a .scala file
*/
object TemplatesBuild extends Build {
lazy val root = (project in file("."))
.setSbtFiles(
// Load the version from Play's version.sbt
// Order is important, load the version first, then load build.sbt which may modify it with the play.version
// system property.
file("../framework/version.sbt"),
file("./build.sbt")
)
}

object Templates {

val templates = SettingKey[Seq[File]]("activatorTemplates")
Expand Down Expand Up @@ -134,7 +148,7 @@ object Templates {
}
},

publishTemplatesTo := "typesafe.com",
publishTemplatesTo := "api.typesafe.com",
doPublishTemplates := {
val host = publishTemplatesTo.value
val creds = Credentials.forHost(credentials.value, host).getOrElse {
Expand Down Expand Up @@ -314,4 +328,6 @@ object Templates {
.map(_.trim)
.filterNot(_.isEmpty)
.map(_.replaceAll("<p>", "").replaceAll("</p>", ""))

play.api.Logger.configure(play.api.Environment.simple())
}
10 changes: 8 additions & 2 deletions templates/project/plugins.sbt
@@ -1,5 +1,11 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-s3" % "0.5")

lazy val plugins = (project in file(".")).dependsOn(playWs)
// Depend on hard coded play-ws version, since we don't need/want the latest, and the system
// properties from this build interfere with the system properties from Play's build. This
// can be updated to something else when needed, but doesn't need to be.
libraryDependencies += "com.typesafe.play" %% "play-ws" % "2.4.0"

lazy val playWs = ProjectRef(Path.fileProperty("user.dir").getParentFile / "framework", "Play-WS")
// Add a resources directory, so that we can include a logback configuration, otherwise we
// get debug logs for everything which is huge.
resourceDirectories in Compile += baseDirectory.value / "resources"
resources in Compile ++= (baseDirectory.value / "resources").***.get
17 changes: 17 additions & 0 deletions templates/project/resources/logback.xml
@@ -0,0 +1,17 @@
<!--
~ Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
-->
<!-- The default logback configuration that Play uses if no other configuration is provided -->
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%level %logger{15} - %message%n%xException</pattern>
</encoder>
</appender>

<root level="WARN">
<appender-ref ref="STDOUT" />
</root>

</configuration>

0 comments on commit 5d7adcb

Please sign in to comment.