<commit_before>(ns leiningen.ring.run-server
  (:use ring.adapter.jetty
        ring.middleware.stacktrace
        ring.middleware.reload
        [clojure.java.browse :only (browse-url)]))

(defn try-ports
  "Try running a function with different ports until it succeeds"
  [func ports]
  (try (func (first ports))
       (catch java.net.BindException ex
         (if-let [ports (next ports)]
           (try-ports func ports)
           (throw ex)))))

(defn- add-destroy-callback [{destroy-fn :destroy}]
  (when destroy-fn
    (. (Runtime/getRuntime)
       (addShutdownHook (Thread. destroy-fn)))))

(defn- run-init [{init-fn :init}]
  (when init-fn
    (init-fn)))

(defn- get-handler [{handler :handler}]
  (-> handler
      wrap-stacktrace
      wrap-reload))

(def suitable-ports (range 3000 3011))

(defn- start-jetty [{port :port :as options}]
  (let [handler (get-handler options)]
    (if port
      (run-jetty handler {:port (Integer. port), :join? false})
      (try-ports
       #(start-jetty (assoc options :port %))
       suitable-ports))))

(defn- open-browser [server {headless? :headless?}]
  (let [connector (first (.getConnectors server))
        host      (or (.getHost connector) "0.0.0.0")
        port      (.getPort connector)
        url-host  (if (= host "0.0.0.0") "127.0.0.1" host)]
    (println "Started server on port" port)
    (when-not headless?
      (browse-url (str "http://" url-host ":" port)))))

(defn run-server [options]
  (add-destroy-callback options)
  (run-init options)
  (doto (start-jetty options)
    (open-browser options)
    (.join)))<commit_msg>Fixed adapter options not being passed to server<commit_after>(ns leiningen.ring.run-server
  (:use ring.adapter.jetty
        ring.middleware.stacktrace
        ring.middleware.reload
        [clojure.java.browse :only (browse-url)]))

(defn try-ports
  "Try running a function with different ports until it succeeds"
  [func ports]
  (try (func (first ports))
       (catch java.net.BindException ex
         (if-let [ports (next ports)]
           (try-ports func ports)
           (throw ex)))))

(defn- add-destroy-callback [{destroy-fn :destroy}]
  (when destroy-fn
    (. (Runtime/getRuntime)
       (addShutdownHook (Thread. destroy-fn)))))

(defn- run-init [{init-fn :init}]
  (when init-fn
    (init-fn)))

(defn- get-handler [{handler :handler}]
  (-> handler
      wrap-stacktrace
      wrap-reload))

(defn- jetty-options [{port :port :as options}]
  (-> options
      (assoc :join? false)
      (assoc :port (Integer. port))))

(def suitable-ports (range 3000 3011))

(defn- start-jetty [options]
  (let [handler (get-handler options)]
    (if (:port options)
      (run-jetty handler (jetty-options options))
      (try-ports #(start-jetty (assoc options :port %))
                 suitable-ports))))

(defn- open-browser [server {headless? :headless?}]
  (let [connector (first (.getConnectors server))
        host      (or (.getHost connector) "0.0.0.0")
        port      (.getPort connector)
        url-host  (if (= host "0.0.0.0") "127.0.0.1" host)]
    (println "Started server on port" port)
    (when-not headless?
      (browse-url (str "http://" url-host ":" port)))))

(defn run-server [options]
  (add-destroy-callback options)
  (run-init options)
  (doto (start-jetty options)
    (open-browser options)
    (.join)))
{'fraction_non_alphanumeric': 0.15611940298507462, 'fraction_numerical': 0.013134328358208954, 'mean_word_length': 2.748322147651007, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5879912', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1121, 'n_words': 301}