Skip to content

Commit

Permalink
Steps with Java lambda expressions can now access external maven depe…
Browse files Browse the repository at this point in the history
…ndencies on classpath (fix for issue #5)
  • Loading branch information
mikub committed Jan 11, 2020
1 parent f358c58 commit 880ea80
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/clj/titanoboa/dependencies.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
[clojure.java.io :as io]
[dynapath.util :as dp]
[dynapath.dynamic-classpath :as dc]
[compliment.utils])
[compliment.utils]
[titanoboa.exp])
(:import (java.io File FileOutputStream)))

(def dependencies-path-property "boa.server.dependencies.path")
Expand Down Expand Up @@ -54,7 +55,8 @@
(when-let [i (:import ext-coordinates)]
(log/info "Importing external classes: " i)
(when (sequential? i) (mapv #(import %) i)))
(compliment.utils/flush-caches)))
(compliment.utils/flush-caches)
(titanoboa.exp/init-java-lambda-factory! (.getContextClassLoader (Thread/currentThread)))))

;;TODO there might be need for retry in case the file stays locked for longer?
(defrecord DepsWatcherComponent [deps-file-path stop-callback-fn last-content-atom]
Expand Down
17 changes: 14 additions & 3 deletions src/clj/titanoboa/exp.clj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
(ns titanoboa.exp
(:require [clojure.walk :as walk]
[cognitect.transit :as transit]
[clojure.java.classpath :as cp]
[clojure.tools.logging :as log]
[cognitect.transit :as transit]
[taoensso.nippy :as nippy]
[titanoboa.dependencies :as deps]
[titanoboa.singleton :as singleton])
(:import [pl.joegreen.lambdaFromString LambdaFactory DynamicTypeReference]
(:import [pl.joegreen.lambdaFromString LambdaFactory DynamicTypeReference LambdaFactoryConfiguration]
(java.io ObjectOutputStream)
(clojure.lang PersistentArrayMap)
(java.util Map)
Expand All @@ -16,7 +16,18 @@
(def ^:dynamic *properties* {})
(def ^:dynamic *jobdir* nil)

(def java-lambda-factory (LambdaFactory/get))
(def java-lambda-factory nil)

(defn init-java-lambda-factory!
([cl]
(let [c-path (reduce (fn [v i] (str v (.getCanonicalPath i) java.io.File/pathSeparatorChar)) "" (cp/classpath cl))]
(alter-var-root #'java-lambda-factory (constantly (LambdaFactory/get (-> (LambdaFactoryConfiguration/get)
(.withParentClassLoader cl)
(.withCompilationClassPath c-path)))))))
([]
(init-java-lambda-factory! (.getContextClassLoader (Thread/currentThread)))))

(init-java-lambda-factory!)

(defrecord Expression [value type])

Expand Down

0 comments on commit 880ea80

Please sign in to comment.