Permalink
Browse files

Initial checkin.

  • Loading branch information...
0 parents commit 6e44be3a556fc44d8aa939caa7e6a45eea480647 @d6y committed May 10, 2011
@@ -0,0 +1,14 @@
+.idea
+.classpath
+.ensime*
+ensime_port
+.externalToolBuilders
+.project
+.settings
+target
+lift_proto.db*
+.scala_dependencies
+lib_managed/
+src_managed/
+project/boot/
+project/plugins/project
32 README
@@ -0,0 +1,32 @@
+Lift Filter for use with Cloudbees
+==================================
+
+When running a Lift application on Cloudbees the Lift run.mode will default to "development". This servlet filter will set the run.mode based on the value set in the cloudbees-web.xml configuration, defaulting to development if not set.
+
+This means a local jetty-run will default to development mode, but a Cloudbees deployment will default to production mode (or whatever value you put in the WEB-INF/cloudbees-web.xml file).
+
+To use
+======
+
+ * Copy the src/main/scala/net.liftmodules.cloudbees.servlet/CloudBeesLiftFilter.scala into your project.
+ * Modify the web.xml as per src/main/webapp/WEB-INF/web.xml
+ * Add a Cloudbees web configuration, based on src/main/webapp/WEB-INF/cloudbees-web.xml
+
+You may need to add the Servlet API as a dependency in your project:
+ "javax.servlet" % "servlet-api" % "2.5" % "provided->default"
+
+Running this project
+====================
+
+This git repository contains a Lift application. Run it via "sbt update jetty" and you'll see http://127.0.0.1:8080/ report "Your run mode is development".
+
+Run it via "bees app:run ./target/scala_2.8.1/cloudbees-lift-filter_2.8.1-1.0.war" and it'll report "Your run mode is Production".
+
+
+ Links
+ =====
+
+ * Tim's original solution: http://groups.google.com/group/liftweb/browse_thread/thread/93f315f98641a63b/5149cd4b4efe49c2?lnk=gst&q=run+mode#5149cd4b4efe49c2
+
+ * CloudBees documentation: https://cloudbees.zendesk.com/entries/459274
+
@@ -0,0 +1,9 @@
+#Project properties
+#Fri Apr 23 11:24:20 PDT 2010
+project.organization=net.liftmodules
+project.name=Cloudbees Lift Filter
+sbt.version=0.7.5
+project.version=1.0
+def.scala.version=2.7.7
+build.scala.versions=2.8.1
+project.initialize=false
@@ -0,0 +1,24 @@
+import sbt._
+
+class LiftProject(info: ProjectInfo) extends DefaultWebProject(info) {
+ val liftVersion = "2.3"
+
+ // uncomment the following if you want to use the snapshot repo
+ // val scalatoolsSnapshot = ScalaToolsSnapshots
+
+ // If you're using JRebel for Lift development, uncomment
+ // this line
+ // override def scanDirectories = Nil
+
+ override def libraryDependencies = Set(
+ "net.liftweb" %% "lift-webkit" % liftVersion % "compile",
+ "org.mortbay.jetty" % "jetty" % "6.1.22" % "test",
+ "junit" % "junit" % "4.5" % "test",
+ "ch.qos.logback" % "logback-classic" % "0.9.26",
+ "org.scala-tools.testing" %% "specs" % "1.6.6" % "test",
+
+ // Required for the Cloudbees filter:
+ "javax.servlet" % "servlet-api" % "2.5" % "provided->default"
+
+ ) ++ super.libraryDependencies
+}
No changes.
@@ -0,0 +1,45 @@
+package bootstrap.liftweb
+
+import net.liftweb._
+import util._
+import Helpers._
+
+import common._
+import http._
+import sitemap._
+import Loc._
+
+
+/**
+ * A class that's instantiated early and run. It allows the application
+ * to modify lift's environment
+ */
+class Boot {
+ def boot {
+ // where to search snippet
+ LiftRules.addToPackages("code")
+
+ // Build SiteMap
+ val entries = List(
+ Menu.i("Home") / "index")
+
+ // set the sitemap. Note if you don't want access control for
+ // each page, just comment this line out.
+ LiftRules.setSiteMap(SiteMap(entries:_*))
+
+ //Show the spinny image when an Ajax call starts
+ LiftRules.ajaxStart =
+ Full(() => LiftRules.jsArtifacts.show("ajax-loader").cmd)
+
+ // Make the spinny image go away when it ends
+ LiftRules.ajaxEnd =
+ Full(() => LiftRules.jsArtifacts.hide("ajax-loader").cmd)
+
+ // Use jQuery 1.4
+ LiftRules.jsArtifacts = net.liftweb.http.js.jquery.JQuery14Artifacts
+
+ // Force the request to be UTF-8
+ LiftRules.early.append(_.setCharacterEncoding("UTF-8"))
+
+ }
+}
@@ -0,0 +1,15 @@
+package code
+package snippet
+
+import net.liftweb.util._
+import net.liftweb.common._
+import Helpers._
+
+import Props.RunModes._
+
+class HelloWorld {
+
+ def runmode = "#mode-name *" #> Props.mode.toString
+
+}
+
@@ -0,0 +1,27 @@
+package net.liftmodules.cloudbees.servlet {
+
+import javax.servlet._
+import javax.servlet.http._
+
+import net.liftweb.http.LiftFilter
+
+//Based on http://groups.google.com/group/liftweb/browse_thread/thread/93f315f98641a63b/5149cd4b4efe49c2?lnk=gst&q=run+mode#5149cd4b4efe49c2
+class CloudBeesLiftFilter extends LiftFilter {
+
+ private def run_mode_set_? = (null != System.getProperty("run.mode"))
+
+ private def run_mode_from(config: FilterConfig) = Option(config.getServletContext.getInitParameter("run.mode"))
+
+ override def init(config: FilterConfig) {
+ if (!run_mode_set_?) {
+ val mode = run_mode_from(config) getOrElse "development"
+ System.setProperty("run.mode", mode)
+ }
+ super.init(config)
+ }
+}
+
+
+
+
+}
@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+<cloudbees-web-app xmlns="http://www.cloudbees.com/xml/webapp/1">
+
+<appid>CLOUDBEES_ACCOUNT/APP_NAME_HERE</appid>
+
+<!-- This servlet context parameter will only be visible when running via CloudBees. -->
+<context-param>
+ <param-name>run.mode</param-name>
+ <param-value>production</param-value>
+</context-param>
+
+<!--
+ An alternative is to restrict the context parameter to particular
+ named CloudBees "environment" values. E.g.,
+
+ <environment name="production">
+ <context-param>
+ <param-name>run.mode</param-name>
+ <param-value>production</param-value>
+ </context-param>
+ </environment>
+
+ <environment name="QA">
+ <context-param>
+ <param-name>run.mode</param-name>
+ <param-value>staging</param-value>
+ </context-param>
+ </environment>
+
+ ... and then deploy via: "bees deploy path/to/war -e QA" or similar.
+
+-->
+
+
+</cloudbees-web-app>
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!DOCTYPE web-app
+PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+"http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<web-app>
+
+<filter>
+ <filter-name>LiftFilter</filter-name>
+ <display-name>Lift Filter</display-name>
+ <description>The Filter that intercepts lift calls</description>
+ <!--<filter-class>net.liftweb.http.LiftFilter</filter-class>-->
+ <filter-class>net.liftmodules.cloudbees.servlet.CloudBeesLiftFilter</filter-class>
+</filter>
+
+
+<filter-mapping>
+ <filter-name>LiftFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+</filter-mapping>
+
+
+</web-app>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,15 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head><meta content="text/html; charset=UTF-8" http-equiv="content-type" /><title>Home</title></head>
+ <body class="lift:content_id=main">
+ <div id="main" class="lift:surround?with=default;at=content">
+ <h2>Welcome to your project!</h2>
+ <p>
+ <span class="lift:helloWorld.runmode">
+ Your run mode is <span id="mode-name">run mode goes here</span>
+ </span>
+ </p>
+ </div>
+ </body>
+</html>
+
@@ -0,0 +1,22 @@
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:lift="http://liftweb.net/">
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
+ <meta name="description" content="" />
+ <meta name="keywords" content="" />
+ <title><span class="lift:Menu.title">code:app:0.1-SNAPSHOT</span></title>
+ <script id="jquery" src="/classpath/jquery.js" type="text/javascript"/>
+ </head>
+ <body>
+ <div class="lift:Menu.builder"/>
+ <div class="lift:Msgs?showAll=true"/>
+
+ <lift:bind name="content" />
+
+ <hr />
+ <h4>
+ <a href="http://www.liftweb.net"><i>Lift</i></a>
+ is Copyright 2007-2011 WorldWide Conferencing, LLC.
+ Distributed under an Apache 2.0 License.
+ </h4>
+ </body>
+</html>
@@ -0,0 +1,23 @@
+<div>
+ <wizard:screen_info><div>Page <wizard:screen_number/> of <wizard:total_screens/></div></wizard:screen_info>
+ <wizard:wizard_top> <div> <wizard:bind/> </div> </wizard:wizard_top>
+ <wizard:screen_top> <div> <wizard:bind/> </div> </wizard:screen_top>
+ <wizard:errors> <div> <ul> <wizard:item> <li> <wizard:bind/> </li> </wizard:item> </ul> </div> </wizard:errors>
+ <div> <wizard:fields>
+ <table>
+ <wizard:line>
+ <tr>
+ <td>
+ <wizard:label><label wizard:for=""><wizard:bind/></label></wizard:label>
+ <wizard:help><span><wizard:bind/></span></wizard:help>
+ <wizard:field_errors> <ul> <wizard:error> <li> <wizard:bind/> </li> </wizard:error> </ul> </wizard:field_errors>
+ </td>
+ <td> <wizard:form/> </td>
+ </tr>
+ </wizard:line>
+ </table>
+ </wizard:fields> </div>
+ <div> <table> <tr> <td> <wizard:prev/> </td> <td> <wizard:cancel/> </td> <td> <wizard:next/> </td> </tr> </table> </div>
+ <wizard:screen_bottom> <div> <wizard:bind/> </div> </wizard:screen_bottom>
+ <wizard:wizard_bottom> <div> <wizard:bind/> </div> </wizard:wizard_bottom>
+</div>

0 comments on commit 6e44be3

Please sign in to comment.