-
-
Save mrc/675008 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defproject com.wombat.web/gaeproject "1.0.0-SNAPSHOT" | |
:description "gaeproject information retrieval" | |
:gae-app com.wombat.web.gaeproject.core/app | |
:dev-dependencies [[leiningen/lein-swank "1.2.0-SNAPSHOT"] | |
[uk.org.alienscience/leiningen-war "0.0.2"]] | |
:dependencies [[org.clojure/clojure "1.1.0"] | |
[org.clojure/clojure-contrib "1.1.0"] | |
[ring/ring "0.2.0"] | |
[com.google/appengine-api-1.0-sdk "1.3.3.1"] | |
[com.google/appengine-api-labs "1.3.3.1"] | |
[com.google/appengine-tools "1.3.3.1"] | |
[com.google/appengine-local-runtime "1.3.3.1"] | |
[com.google/appengine-api-stubs "1.3.3.1"]]) | |
(ns leiningen.info | |
"Print all project variables and their values" | |
(:use [clojure.contrib.pprint :only [pprint pprint-indent]])) | |
(defn info | |
[project] | |
(doseq [key (keys project)] | |
(println (format "%s:" (name key))) | |
(pprint (get project key)))) | |
(ns leiningen.classpath | |
"Print each element of this project's classpath as leiningen percieves it" | |
(:use [clojure.contrib.str-utils2 :only [split]])) | |
(defn classpath | |
[project] | |
(doseq [path (sort (split (System/getProperty "java.class.path") #":"))] (println path))) | |
(ns leiningen.gae-server | |
"Start a GAE development server" | |
(:import java.io.File) | |
(:import com.google.apphosting.api.ApiProxy) | |
(:import com.google.appengine.tools.development.LocalServerEnvironment) | |
(:import com.google.appengine.tools.development.ApiProxyLocalFactory) | |
(:require [clojure.contrib.logging :as log]) | |
(:use [clojure.contrib.duck-streams :only [make-parents]]) | |
(:use ring.handler.dump) | |
(:use ring.adapter.jetty)) | |
(defn- init-app-engine | |
"Initialize GAE services for the dev server" | |
[project] | |
(let [file (File. (get project :root)) | |
local-env (proxy [LocalServerEnvironment] [] | |
(getAppDir [] file) | |
(getAddress [] "localhost") | |
(getPort [] (get project :gae-port 8080)) | |
(waitForServerToStart [] nil)) | |
api-proxy (.create (ApiProxyLocalFactory.) local-env)] | |
(make-parents file) | |
(ApiProxy/setDelegate api-proxy))) | |
(defn- set-gae-system-properties | |
"Read the appengine-web.xml file, extract and save all system properties defined in this file." | |
[project] | |
(let [ae-web-xml-path (str (get project :source-path) "/appengine-web.xml") | |
ae-web-xml-file (File. ae-web-xml-path)] | |
(if (and (.exists ae-web-xml-file) | |
(.canRead ae-web-xml-file)) | |
(doseq [system-property (for [xml-element (xml-seq (clojure.xml/parse ae-web-xml-path)) | |
:when (= (:tag xml-element) :property)] | |
(:attrs xml-element))] | |
(System/setProperty (:name system-property) (:value system-property))) | |
(log/log :error (str "Could not find and load appengine-web.xml file at " ae-web-xml-path))))) | |
(defn gae-server | |
[project] | |
(let [app (get project :gae-app (fn [req] (handle-dump req))) | |
port (get project :gae-port 8080)] | |
(init-app-engine project) | |
(set-gae-system-properties project) | |
(run-jetty app {:port port}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment