Skip to content

Commit

Permalink
Replace javax servlet classes with Jakarta servlet
Browse files Browse the repository at this point in the history
  • Loading branch information
madoxas committed Dec 2, 2024
1 parent 48e03bf commit 31e89a2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/leiningen/ring/uberwar.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
:when (str/ends-with? pathname ".jar")]
(io/file pathname)))

(defn- contains-javax-servlet-class? [^JarFile jar-file]
(some? (.getEntry jar-file "javax/servlet/Servlet.class")))
(defn- contains-jakarta-servlet-class? [^JarFile jar-file]
(some? (.getEntry jar-file "jakarta/servlet/Servlet.class")))

(defn- pom-properties* [^JarEntry entry]
(when (str/ends-with? (.getName entry) "pom.properties")
Expand All @@ -46,7 +46,7 @@
(defn- war-path-for-jar [^File jar]
(with-open [jar-file (JarFile. jar)]
;; Servlet container will have its own servlet-api implementation
(when-not (contains-javax-servlet-class? jar-file)
(when-not (contains-jakarta-servlet-class? jar-file)
(let [name-from-pom (some->> (find-pom-properties jar-file)
(jar-name-from-pom-properties jar-file))]
(->> (or name-from-pom (.getName jar))
Expand Down
2 changes: 1 addition & 1 deletion src/leiningen/ring/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@
(merge-fn project profiles)
project))

(def ring-version "1.6.1")
(def ring-version "1.13.0")
12 changes: 6 additions & 6 deletions src/leiningen/ring/war.clj
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
`(let [handler# ~(generate-resolve handler-sym)]
(fn [request#]
(let [context# (.getContextPath
^javax.servlet.http.HttpServletRequest
^jakarta.servlet.http.HttpServletRequest
(:servlet-request request#))]
(handler#
(assoc request#
Expand All @@ -135,7 +135,7 @@
(let [servlet-ns (symbol (servlet-ns project))]
(compile-form project servlet-ns
`(do (ns ~servlet-ns
(:gen-class :extends javax.servlet.http.HttpServlet))
(:gen-class :extends jakarta.servlet.http.HttpServlet))
(def ~'service-method)
(defn ~'-service [servlet# request# response#]
(~'service-method servlet# request# response#)))
Expand All @@ -151,15 +151,15 @@
(assert-vars-exist project init-sym destroy-sym handler-sym)
(compile-form project project-ns
`(do (ns ~project-ns
(:gen-class :implements [javax.servlet.ServletContextListener]))
(:gen-class :implements [jakarta.servlet.ServletContextListener]))
~(let [servlet-context-event (gensym)]
`(do
(defn ~'-contextInitialized [this# ~servlet-context-event]
~(if init-sym
`(~(generate-resolve init-sym)))
(let [handler# ~(generate-handler project handler-sym)
make-service-method# ~(generate-resolve
'ring.util.servlet/make-service-method)
'ring.util.jakarta.servlet/make-service-method)
method# (make-service-method# handler# ~@(when async? [{:async? true}]))]
(alter-var-root
~(generate-resolve (symbol servlet-ns "service-method"))
Expand Down Expand Up @@ -233,8 +233,8 @@

(defn add-servlet-dep [project]
(-> project
(deps/add-if-missing ['ring/ring-servlet ring-version])
(deps/add-if-missing '[javax.servlet/javax.servlet-api "3.1.0"])))
(deps/add-if-missing ['org.ring-clojure/ring-jakarta-servlet ring-version])
(deps/add-if-missing '[jakarta.servlet/jakarta.servlet-api "6.1.0"])))

(defn war
"Create a $PROJECT-$VERSION.war file."
Expand Down

0 comments on commit 31e89a2

Please sign in to comment.