Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

Commit

Permalink
Update to support development independent of client projects.
Browse files Browse the repository at this point in the history
  • Loading branch information
daithiocrualaoich committed Apr 12, 2012
1 parent c4a087f commit e87c956
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 50 deletions.
5 changes: 4 additions & 1 deletion .gitignore
@@ -1,2 +1,5 @@
.idea*
target/
.cache
.classpath
.project
target/
5 changes: 3 additions & 2 deletions build.sbt
Expand Up @@ -13,11 +13,12 @@ resolvers ++= Seq(
"Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
)

seq(scalariformSettings: _*)


//adding plugin here as we want it to propagate to projects that use this plugin
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.7.3")

addSbtPlugin("play" % "sbt-plugin" % "2.0")

addSbtPlugin("com.typesafe.sbtscalariform" % "sbtscalariform" % "0.3.1")


Binary file added dev/sbt-launch-0.11.2.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions project/plugins.sbt
Expand Up @@ -5,6 +5,6 @@ resolvers ++= Seq(

addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.0.0")

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.0.0")



addSbtPlugin("com.typesafe.sbtscalariform" % "sbtscalariform" % "0.3.1")
17 changes: 17 additions & 0 deletions sbt011
@@ -0,0 +1,17 @@
#!/bin/bash

# SBT configuration
export SBT_BOOT_DIR=${HOME}/.sbt/boot/

if [ ! -d "${SBT_BOOT_DIR}" ]; then
mkdir -p ${SBT_BOOT_DIR}
fi

if [ -f "~/.sbtconfig" ]; then
. ~/.sbtconfig
fi

java -Xmx768M -XX:MaxPermSize=384m \
-Dhttp.proxyHost=devscreen.gudev.gnl -Dhttp.proxyPort=3128 \
-Dsbt.boot.directory=$SBT_BOOT_DIR \
-jar `dirname $0`/dev/sbt-launch-0.11.2.jar "$@"
82 changes: 37 additions & 45 deletions src/main/scala/frontend/Frontend.scala
Expand Up @@ -9,9 +9,7 @@ import AssemblyKeys._
import PlayProject._
import com.typesafe.sbtscalariform.ScalariformPlugin


object Frontend extends Plugin
{
object Frontend extends Plugin {
val LessFile = """(.*)\.less$""".r
val CoffeeFile = """(.*)\.coffee$""".r
val JavaScriptFile = """(.*)\.js$""".r
Expand All @@ -25,7 +23,8 @@ object Frontend extends Plugin

private def digestFor(file: File): String = Hash.toHex(Files.getDigest(file, MessageDigest.getInstance("MD5")))

private def staticFileRoutes = (baseDirectory , streams, sourceManaged).map { (base, s, sourceDir) => {
private def staticFileRoutes = (baseDirectory, streams, sourceManaged).map { (base, s, sourceDir) =>
{
val staticMap = hashFiles(base).map {
case (raw, cached) => """ "%s" -> "%s" """ format (raw, cached)
} mkString (",")
Expand All @@ -34,35 +33,27 @@ object Frontend extends Plugin
package controllers
object Static {
lazy val staticMappings = Map[String, String](
%s
)
lazy val reverseMappings = staticMappings.map{ _.swap }
def at(path: String, file: String) = Assets.at(path, reverseMappings(file))
def at(path: String) = "/assets/" + staticMappings(path)
}
""" format (staticMap)


val file = sourceDir / "controllers" / "Static.scala"

IO.write(file, template)

Seq(file)

}
}

def hashFiles(base: File): Seq[(String,String)] = {

def hashFiles(base: File): Seq[(String, String)] = {
val assetsDir = (base / "app" / "assets")

val resourceFiles = (assetsDir ** "*").get.filter(!_.isDirectory)

val hashedResourceFiles = resourceFiles.flatMap(f => f.relativeTo(assetsDir).map((digestFor(f), _)))

val generatedPaths = hashedResourceFiles flatMap {
Expand Down Expand Up @@ -95,48 +86,49 @@ object Frontend extends Plugin

def buildDeployArtifact =
(assembly, streams, baseDirectory, target, resourceManaged in Compile, name) map {
(jar, s, baseDir, outDir, resourcesDir, projectName) => {
val log = s.log
(jar, s, baseDir, outDir, resourcesDir, projectName) =>
{
val log = s.log

val distFile = outDir / "artifacts.zip"
log.info("Disting %s ..." format distFile)
val distFile = outDir / "artifacts.zip"
log.info("Disting %s ..." format distFile)

if (distFile exists) { distFile delete() }
if (distFile exists) { distFile delete () }

val cacheBustedResources = hashFiles(baseDir)

val cacheBustedResources = hashFiles(baseDir)
val resourceAssetsDir = resourcesDir / "public"
val resourceAssets = cacheBustedResources map {
case (key, cachedKey) =>
(resourceAssetsDir / key, cachedKey)
} filter { fileExists }

val resourceAssetsDir = resourcesDir / "public"
val resourceAssets = cacheBustedResources map { case (key, cachedKey) =>
(resourceAssetsDir / key, cachedKey)
} filter { fileExists }
val publicAssetsDir = baseDir / "public"
val publicAssets = cacheBustedResources map {
case (key, cachedKey) =>
(publicAssetsDir / key, cachedKey)
} filter { fileExists }

val publicAssetsDir = baseDir / "public"
val publicAssets = cacheBustedResources map { case (key, cachedKey) =>
(publicAssetsDir / key, cachedKey)
} filter { fileExists }
val staticFiles = (resourceAssets ++ publicAssets) map {
case (file, cachedKey) =>
val locationInZip = "packages/%s/static-files/%s".format(projectName, cachedKey)
log.verbose("Static file %s -> %s" format (file, locationInZip))
(file, locationInZip)
}

val filesToZip = Seq(
baseDir / "conf" / "deploy.json" -> "deploy.json",
jar -> "packages/%s/%s".format(projectName, jar.getName)
) ++ staticFiles

val staticFiles = (resourceAssets ++ publicAssets) map { case (file, cachedKey) =>
val locationInZip = "packages/%s/static-files/%s".format(projectName, cachedKey)
log.verbose("Static file %s -> %s" format (file, locationInZip))
(file, locationInZip)
}

val filesToZip = Seq(
baseDir / "conf" / "deploy.json" -> "deploy.json",
jar -> "packages/%s/%s".format(projectName, jar.getName)
) ++ staticFiles
IO.zip(filesToZip, distFile)

// Tells TeamCity to publish the artifact => leave this println in here
println("##teamcity[publishArtifacts '%s => .']" format distFile)

IO.zip(filesToZip, distFile)

//tells TeamCity to publish the artifact => leav this println in here
println("##teamcity[publishArtifacts '%s => .']" format distFile)

log.info("Done disting.")
jar
}
log.info("Done disting.")
jar
}
}

private def fileExists(f: (File, String)) = f._1.exists()
Expand Down

0 comments on commit e87c956

Please sign in to comment.