Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to specify context-params in the project file. #192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
45 changes: 33 additions & 12 deletions src/leiningen/ring/war.clj
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,45 @@

(def default-servlet-version "2.5")

(defn make-context-params
"Take this `params-map` and construct from it a sequence of
s-expression representations of context-param elements."
[params-map]
(if
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a when, since it doesn't appear to have an else clause

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(if
(when

(map? params-map)
(map
#(vector
:context-param
[:param-name (name %)]
[:param-value (params-map %)])
(keys params-map))))

(defn make-web-sexpr
"Take this `project` and construct from it an s-expression
representation of the complete web.xml file"
[project]
(let [ring-options (:ring project)]
[:web-app
(get web-app-attrs
(get-in project [:ring :servlet-version] default-servlet-version)
{})
(make-context-params (:context-params ring-options))
[:listener
[:listener-class (listener-class project)]]
[:servlet
[:servlet-name (servlet-name project)]
[:servlet-class (servlet-class project)]]
[:servlet-mapping
[:servlet-name (servlet-name project)]
[:url-pattern (url-pattern project)]]]))

(defn make-web-xml [project]
(let [ring-options (:ring project)]
(if (contains? ring-options :web-xml)
(slurp (:web-xml ring-options))
(indent-str
(sexp-as-element
[:web-app
(get web-app-attrs
(get-in project [:ring :servlet-version] default-servlet-version)
{})
[:listener
[:listener-class (listener-class project)]]
[:servlet
[:servlet-name (servlet-name project)]
[:servlet-class (servlet-class project)]]
[:servlet-mapping
[:servlet-name (servlet-name project)]
[:url-pattern (url-pattern project)]]])))))
(make-web-sexpr project))))))

(defn generate-handler [project handler-sym]
(if (get-in project [:ring :servlet-path-info?] true)
Expand Down
2 changes: 1 addition & 1 deletion test/leiningen/test/ring.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
(:use clojure.test))

(deftest replace-me ;; FIXME: write
(is false "No tests have been written."))
(is false "No tests have been written."))
21 changes: 21 additions & 0 deletions test/leiningen/test/war.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(ns leiningen.test.war
(:require [clojure.test :refer :all]
[leiningen.ring.war :refer :all]))

(deftest test-generate-war
(testing "Generation of context params elements"
(is (empty? (make-context-params {}))
"If no context params are specified, none should be generated")
(is (empty? (make-context-params "froboz"))
"If the argument to make-context-params is not a map, no context params should be generated")
(is (= 1 (count (make-context-params {:foo "bar"})))
"If one context param is specified, one should be generated")
(is (= '([:context-param [:param-name "foo"][:param-value "bar"]])
(make-context-params {:foo "bar"})))
(is (= '([:context-param [:param-name "foo"][:param-value 123]])
(make-context-params {:foo 123})))
(is (= 2 (count (make-context-params {:foo "bar" :froboz "baz"})))
"If two context params are specified, two should be generated"))
(testing "Generation of war file"
(is (= "" (make-web-xml {:ring {:web-xml "/dev/null"}}))
"If a file path is specified as :web-xml, the content of that file should be returned")))