alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Play Framework/Scala example source code file (Build.scala)

This example Play Framework source code file (Build.scala) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Play Framework (and Scala) source code examples by using tags.

All credit for the original source code belongs to Play Framework; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Play Framework tags/keywords

abstractlogger, applicationbuild, boolean, build, compile, int, project, seq, string, task, taskkey

The Build.scala Play Framework example source code

/*
 * Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
 */
import sbt._
import Keys._

object ApplicationBuild extends Build {

  val appName = "play-position-mapper"
  val appVersion = "1.0-SNAPSHOT"

  val bufferLogger = new AbstractLogger {
    @volatile var messages = List.empty[String]
    def getLevel = Level.Error
    def setLevel(newLevel: Level.Value) = ()
    def setTrace(flag: Int) = ()
    def getTrace = 0
    def successEnabled = false
    def setSuccessEnabled(flag: Boolean) = ()
    def control(event: ControlEvent.Value, message: => String) = ()
    def logAll(events: Seq[LogEvent]) = events.foreach(log)
    def trace(t: => Throwable) = ()
    def success(message: => String) = ()
    def log(level: Level.Value, message: => String) = {
      if (level == Level.Error) synchronized {
        messages = message :: messages
      }
    }
  }

  import complete.DefaultParsers._

  def simpleParser(state: State) = Space ~> any.+.map(_.mkString(""))

  def checkLogContains(msg: String): Task[Boolean] = task {
    if (!bufferLogger.messages.exists(_.contains(msg))) {
      sys.error("Did not find log message:\n    '" + msg + "'\nin output:\n" + bufferLogger.messages.reverse.mkString("    ", "\n    ", ""))
    }
    true
  }

  val checkLogContainsTask = InputKey[Boolean]("check-log-contains") <<=
    InputTask.separate[String, Boolean](simpleParser _)(state(s => checkLogContains))

  val compileIgnoreErrorsTask = TaskKey[Unit]("compile-ignore-errors") <<= state.map { state =>
    Project.runTask(compile in Compile, state)
  }

  val main = Project(appName, file(".")).enablePlugins(play.PlayScala).settings(
    version := appVersion,
    extraLoggers ~= { currentFunction =>
      (key: ScopedKey[_]) => {
        bufferLogger +: currentFunction(key)
      }
    },
    checkLogContainsTask,
    compileIgnoreErrorsTask
  )

}

Other Play Framework source code examples

Here is a short list of links related to this Play Framework Build.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.