Skip to content
Snippets Groups Projects
Unverified Commit ec5f8f13 authored by Cam Saul's avatar Cam Saul Committed by GitHub
Browse files

Fix include-drivers lein middleware (#12436)

* Fix include-plugins middleware when we use multiple lein with-profiles

* Bump core project dep version
parent 032a9320
No related branches found
No related tags found
No related merge requests found
(defproject metabase/lein-include-drivers "1.0.8" (defproject metabase/lein-include-drivers "1.0.9"
:min-lein-version "2.5.0" :min-lein-version "2.5.0"
:eval-in-leiningen true :eval-in-leiningen true
:deploy-repositories [["clojars" {:sign-releases false}]] :deploy-repositories [["clojars" {:sign-releases false}]]
......
(ns leiningen.include-drivers (ns leiningen.include-drivers
(:require [clojure.string :as str] (:require [clojure.string :as str]
[colorize.core :as colorize] [colorize.core :as colorize]
[leiningen.core.project :as p]) [leiningen.core.project :as p])
(:import java.io.File)) (:import java.io.File))
(defonce ^:private ^{:arglists '([s]), :doc "Log a message `s` the first time we see it. This middleware might run
multiple times, and we only really need to log a message the first time we see it."}
log-once
(comp (memoize println) str))
(defn- file-exists? [^String filename] (defn- file-exists? [^String filename]
(.exists (File. filename))) (.exists (File. filename)))
...@@ -35,12 +40,12 @@ ...@@ -35,12 +40,12 @@
{:pre [(string? driver) (seq driver)]} {:pre [(string? driver) (seq driver)]}
(if-let [{:keys [include-drivers-dependencies]} (driver->project driver)] (if-let [{:keys [include-drivers-dependencies]} (driver->project driver)]
(or (every? plugins-file-exists? include-drivers-dependencies) (or (every? plugins-file-exists? include-drivers-dependencies)
(println (log-once
(colorize/color (colorize/color
:red :red
(format "[include-drivers middleware] Not including %s because not all dependencies matching %s found in /plugins" (format "[include-drivers middleware] Not including %s because not all dependencies matching %s found in /plugins"
driver (set include-drivers-dependencies))))) driver (set include-drivers-dependencies)))))
(println (log-once
(colorize/color (colorize/color
:red :red
(format "[include-drivers middleware] Not including %s because we could not its project.clj" driver))))) (format "[include-drivers middleware] Not including %s because we could not its project.clj" driver)))))
...@@ -59,7 +64,7 @@ ...@@ -59,7 +64,7 @@
:else :else
(some-> (System/getenv "DRIVERS") (str/split #",") set (disj "h2" "postgres" "mysql"))) (some-> (System/getenv "DRIVERS") (str/split #",") set (disj "h2" "postgres" "mysql")))
_ (println _ (log-once
(colorize/color (colorize/color
:magenta :magenta
(format "[include-drivers middleware] Attempting to include these drivers: %s" (set drivers)))) (format "[include-drivers middleware] Attempting to include these drivers: %s" (set drivers))))
...@@ -120,7 +125,7 @@ ...@@ -120,7 +125,7 @@
(defn- test-drivers-profile [project] (defn- test-drivers-profile [project]
(let [test-drivers (test-drivers project) (let [test-drivers (test-drivers project)
test-projects (test-drivers-projects test-drivers)] test-projects (test-drivers-projects test-drivers)]
(println (log-once
(colorize/color (colorize/color
:magenta :magenta
(format "[include-drivers middleware] including these drivers: %s" (set test-drivers)))) (format "[include-drivers middleware] including these drivers: %s" (set test-drivers))))
...@@ -130,17 +135,13 @@ ...@@ -130,17 +135,13 @@
:source-paths (test-drivers-source-paths test-drivers) :source-paths (test-drivers-source-paths test-drivers)
:test-paths (test-drivers-test-paths test-drivers)})) :test-paths (test-drivers-test-paths test-drivers)}))
;; When we merge a new profile into the project Leiningen will reload the project, which will cause our middleware to
;; run a second time. Make sure we don't add the profile a second time or we'll be stuck in an infinite loop of adding
;; a new profile and reloading.
(defonce ^:private has-added-test-drivers-profile? (atom false))
(defn middleware (defn middleware
"Add dependencies, source paths, and test paths for to Metabase drivers that are packaged as separate projects and "Add dependencies, source paths, and test paths for to Metabase drivers that are packaged as separate projects and
specified by the `DRIVERS` env var." specified by the `DRIVERS` env var."
[project] [project]
(if @has-added-test-drivers-profile? ;; When we merge a new profile into the project Leiningen will reload the project, which will cause our middleware
;; to run a second time. Make sure we don't add the profile a second time or we'll be stuck in an infinite loop of
;; adding a new profile and reloading.
(if (::has-driver-profiles? project)
project project
(do (p/merge-profiles project [(test-drivers-profile project) {::has-driver-profiles? true}])))
(reset! has-added-test-drivers-profile? true)
(p/merge-profiles project [(test-drivers-profile project)]))))
...@@ -251,7 +251,7 @@ ...@@ -251,7 +251,7 @@
:with-include-drivers-middleware :with-include-drivers-middleware
{:plugins {:plugins
[[metabase/lein-include-drivers "1.0.8"]] [[metabase/lein-include-drivers "1.0.9"]]
:middleware :middleware
[leiningen.include-drivers/middleware]} [leiningen.include-drivers/middleware]}
......
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
<3 Cam" <3 Cam"
(:refer-clojure :exclude [require]) (:refer-clojure :exclude [require])
(:require [clojure.tools.logging :as log] (:require [clojure.string :as str]
[clojure.tools.logging :as log]
[dynapath.util :as dynapath] [dynapath.util :as dynapath]
[metabase.util.i18n :refer [deferred-trs]]) [metabase.util.i18n :refer [deferred-trs]])
(:import [clojure.lang DynamicClassLoader RT] (:import [clojure.lang DynamicClassLoader RT]
...@@ -126,8 +127,9 @@ ...@@ -126,8 +127,9 @@
(apply clojure.core/require args))) (apply clojure.core/require args)))
(catch Throwable e (catch Throwable e
(throw (ex-info (.getMessage e) (throw (ex-info (.getMessage e)
{:classloader (the-classloader) {:classloader (the-classloader)
:classpath-urls (map str (dynapath/all-classpath-urls (the-classloader)))} :classpath-urls (map str (dynapath/all-classpath-urls (the-classloader)))
:system-classpath (sort (str/split (System/getProperty "java.class.path") #"[:;]"))}
e))))) e)))))
(defonce ^:private already-added (atom #{})) (defonce ^:private already-added (atom #{}))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment