Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
vemv committed Jul 4, 2023
1 parent 7bd8b58 commit e66185b
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 50 deletions.
47 changes: 46 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,39 @@ jobs:

- run:
name: Lint
command: cd tools.deps; lein with-profile -user,+test,+eastwood eastwood
working_directory: tools.deps
command: lein with-profile -user,+test,+eastwood eastwood

test-lein-plugin:
parameters:
executor:
type: executor
executor: << parameters.executor >>
environment:
PROJECT_VERSION: 999.99.9
steps:
- checkout
- restore_cache:
keys:
- v2-dependencies-{{ checksum "project.clj" }}

- run:
name: Fetch dependencies
command: "$LEIN_DEPS_COMMAND || $LEIN_DEPS_COMMAND || $LEIN_DEPS_COMMAND"

- run:
name: Install
command: make install-base

- run:
name: Test
working_directory: lein-plugin
command: lein with-profile -user,-dev test || lein with-profile -user,-dev test || lein with-profile -user,-dev test

- run:
name: Lint
working_directory: lein-plugin
command: lein with-profile -user,+test,+eastwood eastwood

deploy:
executor: openjdk8_deploy
Expand Down Expand Up @@ -178,6 +210,9 @@ workflows:
integration_test_parallelism: ["1"]
shorten: ["true", "false"]
slice: ["1", "2", "3", "4", "5"]
requires:
- test-deps-edn
- test-lein-plugin
- test-deps-edn:
filters:
branches:
Expand All @@ -187,10 +222,20 @@ workflows:
matrix:
parameters:
executor: [openjdk8, openjdk11, openjdk16, openjdk17]
- test-lein-plugin:
filters:
branches:
only: /.*/
tags:
only: /^v\d+\.\d+\.\d+(-alpha\d+)?$/
matrix:
parameters:
executor: [openjdk8, openjdk11, openjdk16, openjdk17]
- deploy:
requires:
- test
- test-deps-edn
- test-lein-plugin
filters:
branches:
ignore: /.*/
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ install: install-base install-deps
deploy: check-env inline-deps
lein with-profile -user,-dev,+plugin.mranderson/config deploy clojars
cd tools.deps; lein with-profile -user deploy clojars
cd ../lein-plugin; lein with-profile -user deploy clojars

check-env:
ifndef CLOJARS_USERNAME
Expand Down
18 changes: 18 additions & 0 deletions lein-plugin/project.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(def project-version (or (not-empty (System/getenv "PROJECT_VERSION"))
"0.0.0"))

(defproject mx.cider/lein-enrich-classpath project-version
:dependencies [[mx.cider/enrich-classpath ~project-version]
[org.clojure/clojure "1.11.1"]]
:pedantic? ~(if (System/getenv "CI")
:abort
;; :pedantic? can be problematic for certain local dev workflows:
false)
:profiles {:test {:dependencies [[leiningen-core "2.10.0"]]}
:eastwood {:plugins [[jonase/eastwood "1.4.0"]]
:eastwood {:add-linters [:boxed-math
:performance]}}}
:deploy-repositories [["clojars" {:url "https://clojars.org/repo"
:username :env/clojars_username
:password :env/clojars_password
:sign-releases false}]])
104 changes: 104 additions & 0 deletions lein-plugin/src/cider/enrich_classpath/plugin_v2.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
(ns cider.enrich-classpath.plugin-v2
(:refer-clojure :exclude [time])
(:require
[leiningen.core.classpath :as leiningen.classpath]
[cider.enrich-classpath :as enrich-classpath]
[cider.enrich-classpath.logging :refer [debug info warn]]
[leiningen.core.main]
[clojure.string :as string]
[clojure.edn :as edn]))

(defn format-nrepl-options [{:keys [transport nrepl-handler socket nrepl-middleware host port]}]
(->> [["--transport" (when (qualified-symbol? transport)
(pr-str (str transport)))]
["--handler" (when (qualified-symbol? nrepl-handler)
(pr-str (str nrepl-handler)))]
["--socket" (some-> socket not-empty pr-str)]
["--middleware" (when-let [s (some->> nrepl-middleware
(filterv qualified-symbol?)
(not-empty)
(pr-str))]
(str "\"" s "\""))]
["--host" (some-> host not-empty pr-str)]
["--port" (some-> port str not-empty)]]
(filter second)
(reduce into [])
(string/join " ")))

(comment
(format-nrepl-options {:transport 'a/b
:nrepl-handler 'b/c
:socket "sfsf"
:host "l"
:port 23423
:nrepl-middleware '[foo/bar
quux/quuz
baz
(fn []
)]}))

(defn format-jvm-opts [{:keys [jvm-opts compile-path]}]
(let [a (->> jvm-opts
(mapv pr-str))
b (some->> compile-path
not-empty
string/trim
(str "-Dclojure.compile.path="))
all (cond-> a
b (conj b))
res (not-empty (string/join " " all))]
(if res
(str " " res " ")
"")))

(defn middleware* [{:keys [repl-options] :as project}]
(let [java (or (some-> project :java not-empty string/trim)
"java")
nrepl-options (format-nrepl-options repl-options)
sep (System/getProperty "path.separator")
orig (cond-> project
(not-any? (comp '#{nrepl/nrepl nrepl} first) (:dependencies project))
(update :dependencies conj '[nrepl/nrepl "1.0.0"])

true
(assoc :pedantic? false)

true
leiningen.classpath/get-classpath)
orig (string/join sep orig)
{{{:keys [tools
dependencies
managed-dependencies
java-source-paths
jdk-sources]} :results} :enrich-classpath}
(enrich-classpath/middleware (-> project
(assoc-in [:enrich-classpath :shorten] true)
(assoc-in [:enrich-classpath :only-present-results?] true)))

suffix
(->> [dependencies
managed-dependencies
java-source-paths
tools
jdk-sources]
(reduce into [])
(remove empty?)
(string/join sep))

enriched-classpath (str orig ":" suffix)]
(format "%s -cp %s%sclojure.main -m nrepl.cmdline %s"
java
enriched-classpath
(format-jvm-opts project)
nrepl-options)))

(defn middleware [project]
;; XXX failsafe. as a last resource, `echo` the strace
(println (middleware* project))
;; XXX exit 1 too
(leiningen.core.main/exit 0))

;; export PROJECT_VERSION=0.0.0
;; make install
;; cd lein-sample
;; lein repl
45 changes: 45 additions & 0 deletions lein-plugin/test/cider/enrich_classpath/plugin_v2_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
(ns cider.enrich-classpath.plugin-v2-test
(:require
[cider.enrich-classpath.plugin-v2 :as sut]
[clojure.string :as string]
[clojure.test :refer [deftest is]]))

(def classpath-starts-with
"~/enrich-classpath/lein-plugin/test:~/enrich-classpath/lein-plugin/src:~/enrich-classpath/lein-plugin/resources:~/enrich-classpath/lein-plugin/the-compile-path:~/.m2/repository/clj-time/clj-time/0.11.0/clj-time-0.11.0.jar:~/.m2/repository/org/slf4j/jul-to-slf4j/1.7.20/jul-to-slf4j-1.7.20.jar:~/.m2/repository/com/typesafe/config/1.2.0/config-1.2.0.jar:~/.m2/repository/org/clojure/java.classpath/0.2.2/java.classpath-0.2.2.jar:~/.m2/repository/puppetlabs/typesafe-config/0.1.5/typesafe-config-0.1.5.jar:~/.m2/repository/puppetlabs/trapperkeeper/3.0.0/trapperkeeper-3.0.0.jar:~/.m2/repository/org/clojure/tools.logging/0.4.0/tools.logging-0.4.0.jar:~/.m2/repository/tigris/tigris/0.1.1/tigris-0.1.1.jar:~/.m2/repository/org/eclipse/jetty/jetty-http/9.4.28.v20200408/jetty-http-9.4.28.v20200408.jar:~/.m2/repository/org/eclipse/jetty/jetty-io/9.4.28.v20200408/jetty-io-9.4.28.v20200408.jar:~/.m2/repository/org/tcrawley/dynapath/0.2.5/dynapath-0.2.5.jar:~/.m2/repository/org/codehaus/janino/janino/3.0.8/janino-3.0.8.jar:~/.m2/repository/ring/ring-servlet/1.5.0/ring-servlet-1.5.0.jar:~/.m2/repository/org/clojure/tools.macro/0.1.5/tools.macro-0.1.5.jar:~/.m2/repository/clj-commons/fs/1.5.1/fs-1.5.1.jar:~/.m2/repository/beckon/beckon/0.1.1/beckon-0.1.1.jar:~/.m2/repository/digest/digest/1.4.3/digest-1.4.3.jar:~/.m2/repository/org/codehaus/janino/commons-compiler/3.0.8/commons-compiler-3.0.8.jar:~/.m2/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar:~/.m2/repository/ring/ring-codec/1.0.0/ring-codec-1.0.0.jar:~/.m2/repository/org/eclipse/jetty/websocket/websocket-common/9.4.28.v20200408/websocket-common-9.4.28.v20200408.jar:~/.m2/repository/org/eclipse/jetty/jetty-xml/9.4.28.v20200408/jetty-xml-9.4.28.v20200408.jar:~/.m2/repository/org/clojure/tools.analyzer/0.6.9/tools.analyzer-0.6.9.jar:~/.m2/repository/prismatic/schema/1.1.9/schema-1.1.9.jar:~/.m2/repository/com/fasterxml/jackson/dataformat/jackson-dataformat-smile/2.9.0/jackson-dataformat-smile-2.9.0.jar:~/.m2/repository/puppetlabs/trapperkeeper-webserver-jetty9/4.1.0/trapperkeeper-webserver-jetty9-4.1.0.jar:~/.m2/repository/org/gnu/gettext/libintl/0.18.3/libintl-0.18.3.jar:~/.m2/repository/org/eclipse/jetty/jetty-server/9.4.28.v20200408/jetty-server-9.4.28.v20200408.jar:~/.m2/repository/org/eclipse/jetty/jetty-util/9.4.28.v20200408/jetty-util-9.4.28.v20200408.jar:~/.m2/repository/org/clojure/tools.reader/1.0.0-beta4/tools.reader-1.0.0-beta4.jar:~/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar:~/.m2/repository/prismatic/plumbing/0.4.2/plumbing-0.4.2.jar:~/.m2/repository/org/eclipse/jetty/jetty-continuation/9.4.28.v20200408/jetty-continuation-9.4.28.v20200408.jar:~/.m2/repository/org/eclipse/jetty/jetty-security/9.4.28.v20200408/jetty-security-9.4.28.v20200408.jar:~/.m2/repository/org/clojure/core.memoize/0.5.9/core.memoize-0.5.9.jar:~/.m2/repository/org/clojure/tools.cli/0.3.6/tools.cli-0.3.6.jar:~/.m2/repository/org/flatland/ordered/1.5.7/ordered-1.5.7.jar:~/.m2/repository/org/flatland/useful/0.11.6/useful-0.11.6.jar:~/.m2/repository/org/eclipse/jetty/jetty-jmx/9.4.28.v20200408/jetty-jmx-9.4.28.v20200408.jar:~/.m2/repository/org/eclipse/jetty/websocket/websocket-servlet/9.4.28.v20200408/websocket-servlet-9.4.28.v20200408.jar:~/.m2/repository/puppetlabs/i18n/0.8.0/i18n-0.8.0.jar:~/.m2/repository/org/eclipse/jetty/jetty-servlet/9.4.28.v20200408/jetty-servlet-9.4.28.v20200408.jar:~/.m2/repository/cheshire/cheshire/5.8.0/cheshire-5.8.0.jar:~/.m2/repository/de/kotka/lazymap/3.1.0/lazymap-3.1.0.jar:~/.m2/repository/org/yaml/snakeyaml/1.24/snakeyaml-1.24.jar:~/.m2/repository/org/ow2/asm/asm-all/4.2/asm-all-4.2.jar:~/.m2/repository/org/clojure/data.priority-map/0.0.7/data.priority-map-0.0.7.jar:~/.m2/repository/cpath-clj/cpath-clj/0.1.2/cpath-clj-0.1.2.jar:~/.m2/repository/org/eclipse/jetty/jetty-client/9.4.28.v20200408/jetty-client-9.4.28.v20200408.jar:~/.m2/repository/puppetlabs/kitchensink/3.0.0/kitchensink-3.0.0.jar:~/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.9.0/jackson-core-2.9.0.jar:~/.m2/repository/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar:~/.m2/repository/org/clojure/clojure/1.10.1/clojure-1.10.1.jar:~/.m2/repository/clj-commons/clj-yaml/0.7.0/clj-yaml-0.7.0.jar:~/.m2/repository/com/fasterxml/jackson/dataformat/jackson-dataformat-cbor/2.9.0/jackson-dataformat-cbor-2.9.0.jar:~/.m2/repository/org/ini4j/ini4j/0.5.2/ini4j-0.5.2.jar:~/.m2/repository/ch/qos/logback/logback-access/1.2.3/logback-access-1.2.3.jar:~/.m2/repository/nrepl/nrepl/1.0.0/nrepl-1.0.0.jar:~/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.20/log4j-over-slf4j-1.7.20.jar:~/.m2/repository/org/eclipse/jetty/websocket/websocket-api/9.4.28.v20200408/websocket-api-9.4.28.v20200408.jar:~/.m2/repository/org/clojure/core.specs.alpha/0.2.44/core.specs.alpha-0.2.44.jar:~/.m2/repository/slingshot/slingshot/0.12.2/slingshot-0.12.2.jar:~/.m2/repository/org/apache/commons/commons-compress/1.18/commons-compress-1.18.jar:~/.m2/repository/org/eclipse/jetty/websocket/websocket-client/9.4.28.v20200408/websocket-client-9.4.28.v20200408.jar:~/.m2/repository/org/eclipse/jetty/jetty-webapp/9.4.28.v20200408/jetty-webapp-9.4.28.v20200408.jar:~/.m2/repository/puppetlabs/ssl-utils/3.0.4/ssl-utils-3.0.4.jar:~/.m2/repository/org/clojure/core.cache/0.6.5/core.cache-0.6.5.jar:~/.m2/repository/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar:~/.m2/repository/org/clojure/java.jmx/0.3.4/java.jmx-0.3.4.jar:~/.m2/repository/org/clojure/core.async/0.4.490/core.async-0.4.490.jar:~/.m2/repository/org/eclipse/jetty/jetty-proxy/9.4.28.v20200408/jetty-proxy-9.4.28.v20200408.jar:~/.m2/repository/commons-codec/commons-codec/1.10/commons-codec-1.10.jar:~/.m2/repository/joda-time/joda-time/2.8.2/joda-time-2.8.2.jar:~/.m2/repository/org/clojure/spec.alpha/0.2.176/spec.alpha-0.2.176.jar:~/.m2/repository/puppetlabs/trapperkeeper-filesystem-watcher/1.2.0/trapperkeeper-filesystem-watcher-1.2.0.jar:~/.m2/repository/org/eclipse/jetty/websocket/websocket-server/9.4.28.v20200408/websocket-server-9.4.28.v20200408.jar:~/.m2/repository/org/eclipse/jetty/jetty-servlets/9.4.28.v20200408/jetty-servlets-9.4.28.v20200408.jar:~/.m2/repository/org/clojure/tools.analyzer.jvm/0.7.2/tools.analyzer.jvm-0.7.2.jar:~/.m2/repository/org/tukaani/xz/1.8/xz-1.8.jar:~/.mx.cider/enrich-classpath/<shortened>.jar:~/.mx.cider/enrich-classpath/<shortened>.jar:")

(deftest middleware
(let [[java cp classpath jvmopt1 jvmopt2 compile-path clojure-main m nrepl host localhost port portno :as segments]
(-> (sut/middleware* '{:repl-options {:host "localhost"
:port 33421}
:source-paths ["src"]
:test-paths ["test"]
:resource-paths ["resources"]
:plugins [[refactor-nrepl "3.6.0"]]
:dependencies [[puppetlabs/trapperkeeper-webserver-jetty9 "4.1.0"]]
:repositories [["central" {:url "https://repo1.maven.org/maven2/" :snapshots false}]
["clojars" {:url "https://repo.clojars.org/"}]]
:jvm-opts ["-Dfoo=bar"
"-Xyz"]
:compile-path "the-compile-path"
:managed-dependencies [[commons-codec "1.10"]
[org.slf4j/slf4j-api "1.7.25"]
[org.clojure/tools.reader "1.0.0-beta4"]]})
(string/split #"\s"))

classpath (-> classpath
(string/replace (System/getProperty "user.home" ) "~")
(string/replace #".mx.cider/enrich-classpath/\d+/\d+/\d+.jar"
".mx.cider/enrich-classpath/<shortened>.jar"))]
(is (= "java" java))
(is (= "-cp" cp))
(is (string/starts-with? classpath classpath-starts-with))
(is (= "\"-Dfoo=bar\"" jvmopt1))
(is (= "\"-Xyz\"" jvmopt2))
(is (= "-Dclojure.compile.path=the-compile-path" compile-path))
(is (= "clojure.main" clojure-main))
(is (= "-m" m))
(is (= "nrepl.cmdline" nrepl))
(is (= "--host" host))
(is (= "\"localhost\"" localhost))
(is (= "--port" port))
(is (= "33421" portno))))
11 changes: 11 additions & 0 deletions lein-sample/project.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(defproject lein-sample "0.1.0"
:repl-options {:port 33421}
:plugins [[cider/cider-nrepl "0.31.0"] ;; should add its middleware
[refactor-nrepl "3.6.0"] ;; should add its middleware
[mx.cider/enrich-classpath ~(or (not-empty (System/getenv "PROJECT_VERSION"))
"0.0.0")]]
:middleware [cider.enrich-classpath.plugin-v2/middleware]
:dependencies [[puppetlabs/trapperkeeper-webserver-jetty9 "4.1.0"]]
:managed-dependencies [[commons-codec "1.10"]
[org.slf4j/slf4j-api "1.7.25"]
[org.clojure/tools.reader "1.0.0-beta4"]])
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
:url "https://www.eclipse.org/legal/epl-2.0/"}

:dependencies [^:inline-dep [fipp "0.6.25" :exclusions [org.clojure/clojure]]
[org.clojure/clojure "1.10.3"] ;; Hard-require a recent-enough version of Clojure, since other plugins may require an overly old one which would make Fipp fail.
[org.clojure/clojure "1.11.1"] ;; Hard-require a recent-enough version of Clojure, since other plugins may require an overly old one which would make Fipp fail.
]

:pedantic? ~(if (System/getenv "CI")
Expand Down
Loading

0 comments on commit e66185b

Please sign in to comment.