All Downloads are FREE. Search and download functionalities are using the official Maven repository.

meyvn.nrepl_middleware.utils.clj Maven / Gradle / Ivy

The newest version!
(ns meyvn.nrepl-middleware.utils
  (:require [clojure.edn :as edn]
            [clojure.java.io :as io]
            [clojure.string :as str])
  (:import [java.util.jar JarInputStream]
           [clojure.lang AFunction DynamicClassLoader]))

(defn read-conf [file]
  (-> file
      slurp
      edn/read-string))

(defn file->bytes [path]
  (with-open [in (io/input-stream path)
              out (java.io.ByteArrayOutputStream.)]
    (io/copy in out)
    (.toByteArray out)))

(defn meyvn-classpath []
  (let [url  (-> (System/getProperty "java.class.path")
                io/as-file
                io/as-url)
        is  (JarInputStream. (.openStream url))
        mf (.getManifest is)
        coll (-> (.getValue (.getMainAttributes mf) "Class-Path")
                (str/split #"file:"))]
    (str/join ":" (map str/trim coll))))

(defn find-classloader []
  (let [loader (loop [loader (.getContextClassLoader (Thread/currentThread))]
          (let [parent (.getParent loader)]
            (if (instance? DynamicClassLoader parent)
              (recur parent)
              loader)))]
    (if (instance? DynamicClassLoader loader)
      loader
      (throw (IllegalAccessError. "Context classloader is not a DynamicClassLoader")))))




© 2015 - 2024 Weber Informatics LLC | Privacy Policy