Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion framework/src/play/src/main/scala/play/api/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ trait WithDefaultConfiguration {
self: Application =>

protected lazy val initialConfiguration = Threads.withContextClassLoader(self.classloader) {
Configuration.load(path, mode)
Configuration.load(path, mode, this match {
case dev: DevSettings => dev.devSettings
case _ => Map.empty
})
}

private lazy val fullConfiguration = global.onLoadConfig(initialConfiguration, path, classloader, mode)
Expand Down
15 changes: 10 additions & 5 deletions framework/src/play/src/main/scala/play/api/Configuration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ object Configuration {
* loads `Configuration` from 'conf/application.conf' in Dev mode
* @return configuration to be used
*/
private[play] def loadDev(appPath: File) = {
private[play] def loadDev(appPath: File, devSettings: Map[String,String]): Config = {
try {
val file = Option(System.getProperty("config.file")).map(f => new File(f)).getOrElse(new File(appPath, "conf/application.conf"))
ConfigFactory.load(ConfigFactory.parseFileAnySyntax(file))
val file = {
devSettings.get("config.file").orElse(Option(System.getProperty("config.file")))
.map(f => new File(f)).getOrElse(new File(appPath, "conf/application.conf"))
}
ConfigFactory.parseMap(devSettings.asJava).withFallback(
ConfigFactory.load(ConfigFactory.parseFileAnySyntax(file))
)
} catch {
case e: ConfigException => throw configError(e.origin, e.getMessage, Some(e))
}
Expand All @@ -48,10 +53,10 @@ object Configuration {
* @param mode Application mode.
* @return a `Configuration` instance
*/
def load(appPath: File, mode: Mode.Mode = Mode.Dev) = {
def load(appPath: File, mode: Mode.Mode = Mode.Dev, devSettings: Map[String,String] = Map.empty) = {
try {
val currentMode = Play.maybeApplication.map(_.mode).getOrElse(mode)
if (currentMode == Mode.Prod) Configuration(dontAllowMissingConfig) else Configuration(loadDev(appPath))
if (currentMode == Mode.Prod) Configuration(dontAllowMissingConfig) else Configuration(loadDev(appPath, devSettings))
} catch {
case e: ConfigException => throw configError(e.origin, e.getMessage, Some(e))
case e : Throwable => throw e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ trait SourceMapper {

}

trait DevSettings {
def devSettings: Map[String,String]
}

/**
* generic layout for initialized Applications
*/
Expand Down Expand Up @@ -121,7 +125,10 @@ class ReloadableApplication(sbtLink: SBTLink) extends ApplicationProvider {
case _ => None
}
}
}),Mode.Dev)
}), Mode.Dev) with DevSettings {
import scala.collection.JavaConverters._
lazy val devSettings: Map[String,String] = sbtLink.settings.asScala.toMap
}

Play.start(newApplication)

Expand Down
3 changes: 3 additions & 0 deletions framework/src/sbt-link/src/main/java/play/core/SBTLink.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package play.core;

import java.io.*;
import java.util.*;

/**
* Generic interface that helps the communication between a Play Application
Expand Down Expand Up @@ -30,4 +31,6 @@ public interface SBTLink {

public String markdownToHtml(String markdown, String pagePath);

public Map<String,String> settings();

}
2 changes: 2 additions & 0 deletions framework/src/sbt-plugin/src/main/scala/PlayKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,7 @@ trait PlayKeys {

val playPlugin = SettingKey[Boolean]("play-plugin")

val devSettings = SettingKey[Seq[(String,String)]]("play-dev-settings")

}
object PlayKeys extends PlayKeys
7 changes: 6 additions & 1 deletion framework/src/sbt-plugin/src/main/scala/PlayReloader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ trait PlayReloader {
var fileTimestamps = calculateTimestamps

def hasChangedFiles: Boolean = monitoredFiles.exists{ f =>
val fileChanged = fileTimestamps.get(f.getAbsolutePath).map{ timestamp =>
val fileChanged = fileTimestamps.get(f.getAbsolutePath).map { timestamp =>
f.lastModified != timestamp
}.getOrElse{
state.log.debug("Did not find expected timestamp of file: " + f.getAbsolutePath + " in timestamps. Marking it as changed...")
Expand All @@ -143,6 +143,11 @@ trait PlayReloader {

val watchChanges: Seq[Int] = monitoredDirs.map( f => jnotify.addWatch(f.getAbsolutePath) )

lazy val settings = {
import scala.collection.JavaConverters._
extracted.get(PlayKeys.devSettings).toMap.asJava
}

// --- Utils

def markdownToHtml(markdown: String, pagePath: String) = {
Expand Down
4 changes: 4 additions & 0 deletions framework/src/sbt-plugin/src/main/scala/PlaySettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ trait PlaySettings {
coffeescriptOptions := Seq.empty[String],
closureCompilerOptions := Seq.empty[String],

// Settings

devSettings := Nil,

// Templates

templatesImport := Seq("play.api.templates._", "play.api.templates.PlayMagic._"),
Expand Down