Skip to content

Commit

Permalink
Configure jetty-env.xml. Allows specifying JNDI datasources. Inspired…
Browse files Browse the repository at this point in the history
… by maven-jetty-plugin.

Only takes effect when jettyEnvXml equals Some[File], by default None.
Tested with jrebel.
  • Loading branch information
tbje authored and harrah committed Aug 4, 2010
1 parent 8d2275c commit 5e41a47
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
4 changes: 3 additions & 1 deletion project/build/SbtProject.scala
Expand Up @@ -42,9 +42,11 @@ abstract class SbtProject(info: ProjectInfo) extends DefaultProject(info) with t
val ivy = "org.apache.ivy" % "ivy" % "2.1.0" intransitive()
val jsch = "com.jcraft" % "jsch" % "0.1.31" intransitive()
val jetty = "org.mortbay.jetty" % "jetty" % "6.1.14" % "optional"
val jettyplus = "org.mortbay.jetty" % "jetty-plus" % "6.1.14" % "optional"

val jetty7server = "org.eclipse.jetty" % "jetty-server" % "7.0.1.v20091125" % "optional"
val jetty7webapp = "org.eclipse.jetty" % "jetty-webapp" % "7.0.1.v20091125" % "optional"
val jetty7plus = "org.eclipse.jetty" % "jetty-plus" % "7.0.1.v20091125" % "optional"

val testInterface = "org.scala-tools.testing" % "test-interface" % "0.5"

Expand Down Expand Up @@ -80,4 +82,4 @@ abstract class SbtProject(info: ProjectInfo) extends DefaultProject(info) with t
}
def processJettyTemplate(template: String, version: String, imports: String): String =
template.replaceAll("""\Q${jetty.version}\E""", version).replaceAll("""\Q${jetty.imports}\E""", imports)
}
}
3 changes: 3 additions & 0 deletions sbt/src/main/scala/sbt/DefaultProject.scala
Expand Up @@ -388,6 +388,7 @@ abstract class BasicWebScalaProject extends BasicScalaProject with WebScalaProje
def scanInterval = p.scanInterval
def port = jettyPort
def log = p.log
def jettyEnv = jettyEnvXml
}
/** This is the classpath used to determine what classes, resources, and jars to put in the war file.*/
def webappClasspath = publicClasspath
Expand Down Expand Up @@ -420,6 +421,8 @@ abstract class BasicWebScalaProject extends BasicScalaProject with WebScalaProje
/** The port that Jetty runs on. */
def jettyPort: Int = JettyRunner.DefaultPort

def jettyEnvXml : Option[File] = None

lazy val jettyReload = task { jettyInstance.reload(); None } describedAs(JettyReloadDescription)
lazy val jettyRestart = jettyStop && jettyRun
lazy val jettyStop = jettyStopAction
Expand Down
4 changes: 3 additions & 1 deletion sbt/src/main/scala/sbt/WebApp.scala
Expand Up @@ -96,12 +96,14 @@ trait DefaultJettyConfiguration extends JettyConfiguration
def war: Path
def scanDirectories: Seq[File]
def scanInterval: Int


def contextPath: String
def port: Int
/** The classpath containing the classes, jars, and resources for the web application. */
def classpath: PathFinder
def parentLoader: ClassLoader
def jettyEnv: Option[File]
}
abstract class CustomJettyConfiguration extends JettyConfiguration
{
Expand Down Expand Up @@ -145,4 +147,4 @@ private class JettyLoggerBase(delegate: Logger)
else sb.append(piece).append(argStr)
}.toString
}
}
}
16 changes: 16 additions & 0 deletions sbt/src/main/scala/sbt/jetty/LazyJettyRun.scala.templ
@@ -1,3 +1,4 @@

package sbt.jetty

import java.io.File
Expand Down Expand Up @@ -69,9 +70,24 @@ private object LazyJettyRun${jetty.version} extends JettyRun
}
def setLoader() = webapp.setClassLoader(createLoader)

// enable loading of custom jetty-env.xml file.
jettyEnv.foreach{jettyEnvFile:File =>
val envConfig = new EnvConfiguration
envConfig.setJettyEnvXml(jettyEnvFile.toURL)
val confArray : Array[Configuration] = Array(
new WebInfConfiguration,
new WebXmlConfiguration,
envConfig,
new PlusConfiguration,
new JettyWebXmlConfiguration,
new TagLibConfiguration)
webapp.setConfigurations(confArray)
}

setLoader()
server.setHandler(webapp)


val listener = new Scanner.BulkListener with Reload {
def reloadApp() = reload(server, setLoader(), log)
def filesChanged(files: java.util.List[_]) { reloadApp() }
Expand Down
5 changes: 3 additions & 2 deletions sbt/src/main/scala/sbt/jetty/jetty6.imports
@@ -1,7 +1,8 @@

import org.mortbay.jetty.{Handler, Server}
import org.mortbay.jetty.nio.SelectChannelConnector
import org.mortbay.jetty.webapp.{WebAppClassLoader, WebAppContext}
import org.mortbay.jetty.webapp.{WebAppClassLoader, WebAppContext, WebInfConfiguration, Configuration, JettyWebXmlConfiguration, TagLibConfiguration, WebXmlConfiguration}
import org.mortbay.log.{Log, Logger => JLogger}
import org.mortbay.util.Scanner
import org.mortbay.xml.XmlConfiguration
import org.mortbay.xml.XmlConfiguration
import org.mortbay.jetty.plus.webapp.{EnvConfiguration, Configuration=>PlusConfiguration}
6 changes: 4 additions & 2 deletions sbt/src/main/scala/sbt/jetty/jetty7.imports
@@ -1,7 +1,9 @@

import org.eclipse.jetty.server.{Server, Handler}
import org.eclipse.jetty.server.nio.SelectChannelConnector
import org.eclipse.jetty.webapp.{WebAppClassLoader, WebAppContext}
import org.eclipse.jetty.webapp.{WebAppClassLoader, WebAppContext, WebInfConfiguration, Configuration, FragmentConfiguration, JettyWebXmlConfiguration, TagLibConfiguration, WebXmlConfiguration}
import org.eclipse.jetty.util.log.{Log, Logger => JLogger}
import org.eclipse.jetty.util.Scanner
import org.eclipse.jetty.xml.XmlConfiguration
import org.eclipse.jetty.xml.XmlConfiguration
import org.eclipse.jetty.plus.webapp.{EnvConfiguration, Configuration=>PlusConfiguration}

0 comments on commit 5e41a47

Please sign in to comment.