Skip to content

Commit 98c7263

Browse files
vemvbbatsov
authored andcommitted
Remove Dynapath, accomodate enrich-classpath
Fixes #122 Fixes #120 Fixes #105 Fixes #103 Fixes #50
1 parent 32459cc commit 98c7263

File tree

19 files changed

+299
-439
lines changed

19 files changed

+299
-439
lines changed

.circleci/config.yml

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ jobs:
161161
- run:
162162
name: Running tests
163163
command: make test
164+
# Eastwood is run for every item in the CI matrix, because its results are sensitive to the code in the runtime,
165+
# so we make the most out of this linter by exercising all profiles, JDK versions, etc.
166+
- run:
167+
name: Running Eastwood
168+
command: make eastwood
164169

165170
######################################################################
166171
#
@@ -172,10 +177,9 @@ jobs:
172177
# The ci-test-matrix does the following:
173178
#
174179
# - run tests against the target matrix
175-
# - Java 8 and 11
180+
# - Java 8, 11, 16 and 17
176181
# - Clojure 1.8, 1.9, 1.10, master
177182
# - linter, eastwood and cljfmt
178-
# - runs code coverage report
179183

180184
workflows:
181185
version: 2.1
@@ -186,17 +190,7 @@ workflows:
186190
parameters:
187191
jdk_version: [openjdk8, openjdk11, openjdk16, openjdk17]
188192
clojure_version: ["1.8", "1.9", "1.10", "master"]
189-
test_profiles: ["+test", "+test,+no-dynapath"]
190-
- util_job:
191-
# This step exercises JDK8 specifically. Eastwood, given its runtime-based approach can detect problems specific to JDK8
192-
# (specifically, it will analyze the `java.legacy-parser` ns):
193-
name: Code Linting, JDK8 (Eastwood only)
194-
jdk_version: openjdk8
195-
steps:
196-
- run:
197-
name: Running Eastwood
198-
command: |
199-
make eastwood
193+
test_profiles: ["+test", "+test,+enrich-classpath"]
200194
- util_job:
201195
name: Code Linting, (latest LTS JDK)
202196
jdk_version: openjdk17
@@ -209,7 +203,3 @@ workflows:
209203
name: Running clj-kondo
210204
command: |
211205
make kondo
212-
- run:
213-
name: Running Eastwood
214-
command: |
215-
make eastwood

.clj-kondo/config.edn

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{:output {:progress true
22
:exclude-files ["analysis.cljc" "meta.cljc" "inspect_test.clj"]}
33
:linters {:unused-private-var {:level :warning
4-
:exclude [orchard.query-test/a-private orchard.query-test/docd-fn]}}}
4+
:exclude [orchard.query-test/a-private orchard.query-test/docd-fn]}
5+
;; Enable this opt-in linter:
6+
:unsorted-required-namespaces
7+
{:level :warning}}}

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
## master (unreleased)
44

5+
### Changes
6+
7+
* Remove `dynapath` dependency
8+
* With it, defns related with mutable classloader are now deprecated and are no-ops
9+
* `-Dorchard.use-dynapath=false` has no effect now either.
10+
* Accomodate [`enrich-classpath`](https://github.com/clojure-emacs/enrich-classpath)
11+
* Now, if you intend to use Orchard for its Java functionality, it is expected that you use enrich-classpath also.
12+
* If not present, Java-related features won't work (but at least won't throw a compile-time error).
13+
514
### Bugs Fixed
615

716
* [#135](https://github.com/clojure-emacs/orchard/issues/135): Fix problematic double var lookup in `orchard.xref/fn-refs`.

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: test test-watch docs eastwood cljfmt release deploy clean
1+
.PHONY: test test-watch docs eastwood cljfmt release deploy clean .EXPORT_ALL_VARIABLES
22

33
VERSION ?= 1.10
44

@@ -7,10 +7,11 @@ TEST_PROFILES ?= +test
77
resources/clojuredocs/export.edn:
88
curl -o $@ https://github.com/clojure-emacs/clojuredocs-export-edn/raw/master/exports/export.compact.edn
99

10-
test:
10+
# .EXPORT_ALL_VARIABLES passes TEST_PROFILES to Lein so that it can inspect the active profiles, which is needed for a complete Eastwood setup:
11+
test: clean .EXPORT_ALL_VARIABLES
1112
lein with-profile -user,-dev,+$(VERSION),$(TEST_PROFILES) test
1213

13-
test-watch: test-resources/clojuredocs/export.edn
14+
test-watch: test-resources/clojuredocs/export.edn clean
1415
lein with-profile +$(VERSION),$(TEST_PROFILES) test-refresh
1516

1617
eastwood:

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ Orchard is meant to run alongside your application and we can't have a
5151
dev tools library interfere with your app right? Dependency collisions are nasty problems which are best solved
5252
by making sure there can't be any shared libraries to cause the conflict.
5353

54-
Currently Orchard has one runtime dependency (`dynapath`), but we hope to eliminate it at some point.
55-
5654
### API Optimized for Editors
5755

5856
Code editors can't know what symbols resolve to without consulting a REPL that's why they would typically
@@ -86,18 +84,19 @@ Just add `orchard` as a dependency and start hacking.
8684
Consult the [API documentation](https://cljdoc.org/d/cider/orchard/CURRENT) to get a better idea about the
8785
functionality that's provided.
8886

87+
#### Using `enrich-classpath` for best results
88+
89+
There are features that Orchard intends to provide (especially, those related to Java interaction) which need to assume a pre-existing initial classpath that already has various desirable items, such as the JDK sources, third-party sources, special jars such as `tools` (for JDK8), a given project's own Java sources... all that is a domain in itself, which is why our [enrich-classpath](https://github.com/clojure-emacs/enrich-classpath) project does it.
90+
91+
For getting the most out of Orchard, it is therefore recommended/necessary to use `enrich-classpath`. Please refer to its installation/usage instructions.
92+
8993
## Configuration options
9094

9195
So far, Orchard follows these options, which can be specified as Java system properties
9296
(which means that end users can choose to set them globally without fiddling with tooling internals):
9397

94-
* `"-Dorchard.use-dynapath=false"` (default: true)
95-
* if `false`, all features that currently depend on dynapath (and therefore alter the classpath) will be disabled.
96-
* This is a way to avoid a number of known issues: [#103](https://github.com/clojure-emacs/orchard/issues/103), [#105](https://github.com/clojure-emacs/orchard/issues/105), [#112](https://github.com/clojure-emacs/orchard/pull/112).
97-
* Note that if this option is `false`, Orchard clients will have to figure out themselves a way to e.g. fetch Java sources.
98-
* It is foreseen that soon enough this will be reliably offered as a Lein plugin.
9998
* `"-Dorchard.initialize-cache.silent=true"` (default: `true`)
100-
* if `false`, the _class info cache_ initialization may print warnings (possibly spurious ones).xx
99+
* if `false`, the _class info cache_ initialization may print warnings (possibly spurious ones).
101100

102101
## History
103102

dev/user.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[clojure.set :as set]
88
[clojure.string :as string]
99
[clojure.test :as test]
10-
[clojure.tools.namespace.repl :refer [refresh refresh-all clear refresh-dirs set-refresh-dirs]]))
10+
[clojure.tools.namespace.repl :refer [clear refresh refresh-all refresh-dirs set-refresh-dirs]]))
1111

1212
(def jdk8?
1313
(->> "java.version" System/getProperty (re-find #"^1.8.")))

project.clj

Lines changed: 21 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,13 @@
1-
;;;; The following code allows to add the JDK sources without `dynapath` being present.
2-
3-
(require '[clojure.java.io :as io])
4-
5-
(import '[java.util.zip ZipInputStream]
6-
'[java.io FileOutputStream])
7-
8-
(defmacro while-let [[sym expr] & body]
9-
`(loop [~sym ~expr]
10-
(when ~sym
11-
~@body
12-
(recur ~expr))))
13-
14-
(defn jdk-find [f]
15-
(let [home (io/file (System/getProperty "java.home"))
16-
parent (.getParentFile home)
17-
paths [(io/file home f)
18-
(io/file home "lib" f)
19-
(io/file parent f)
20-
(io/file parent "lib" f)]]
21-
(->> paths (filter #(.canRead ^java.io.File %)) first str)))
22-
23-
(def jdk-sources
24-
(let [java-path->zip-path (fn [path]
25-
(some-> (io/resource path)
26-
^java.net.JarURLConnection (. openConnection)
27-
(. getJarFileURL)
28-
io/as-file
29-
str))]
30-
(or (java-path->zip-path "java.base/java/lang/Object.java") ; JDK9+
31-
(java-path->zip-path "java/lang/Object.java") ; JDK8-
32-
(jdk-find "src.zip"))))
33-
34-
(defn uncompress [path target]
35-
(let [zis (-> target io/input-stream ZipInputStream.)]
36-
(while-let [entry (-> zis .getNextEntry)]
37-
(let [size (-> entry .getSize)
38-
bytes (byte-array 1024)
39-
dest (->> entry .getName (io/file path))
40-
dir (-> entry .getName (clojure.string/split #"/") butlast)
41-
_ (->> (clojure.string/join "/" dir) (java.io.File. path) .mkdirs)
42-
output (FileOutputStream. dest)]
43-
(loop [len (-> zis (.read bytes))]
44-
(when (pos? len)
45-
(-> output (.write bytes 0 len))
46-
(recur (-> zis (.read bytes)))))
47-
(-> output .close)))))
48-
49-
(defn unzipped-jdk-source []
50-
(when-not (-> "unzipped-jdk-source" io/file .exists)
51-
(let [choice jdk-sources]
52-
(-> "unzipped-jdk-source" io/file .mkdirs)
53-
;; For some reason simply adding a .zip to the classpath doesn't work, so one has to uncompress the contents:
54-
(uncompress "./unzipped-jdk-source/" choice)))
55-
"unzipped-jdk-source")
56-
571
(def jdk8? (->> "java.version" System/getProperty (re-find #"^1.8.")))
582

59-
;;;; Project definition
60-
613
(defproject cider/orchard "0.7.3"
624
:description "A fertile ground for Clojure tooling"
635
:url "https://github.com/clojure-emacs/orchard"
646
:license {:name "Eclipse Public License"
657
:url "http://www.eclipse.org/legal/epl-v10.html"}
668
:scm {:name "git" :url "https://github.com/clojure-emacs/orchard"}
679

68-
:dependencies [[org.tcrawley/dynapath "1.1.0"]
69-
[org.clojure/clojurescript "1.10.520"]]
10+
:dependencies [[org.clojure/clojurescript "1.10.520"]]
7011
:exclusions [org.clojure/clojure] ; see versions matrix below
7112

7213
:aliases {"bump-version" ["change" "version" "leiningen.release/bump-version"]}
@@ -83,8 +24,7 @@
8324
:password :env/clojars_password
8425
:sign-releases false}]]
8526

86-
:jvm-opts ["-Dorchard.use-dynapath=true"
87-
"-Dclojure.main.report=stderr"]
27+
:jvm-opts ["-Dclojure.main.report=stderr"]
8828

8929
:source-paths ["src" "src-jdk8" "src-newer-jdks"]
9030
:test-paths ~(cond-> ["test"]
@@ -110,15 +50,15 @@
11050
:resource-paths ["test-resources"
11151
"not-a.jar"
11252
"does-not-exist.jar"]
53+
:java-source-paths ["test-java"]
11354
;; Initialize the cache verbosely, as usual, so that possible issues can be more easily diagnosed:
11455
:jvm-opts ["-Dorchard.initialize-cache.silent=false"
115-
"-Dorchard.internal.test-suite-running=true"]}
56+
"-Dorchard.internal.test-suite-running=true"
57+
"-Dorchard.internal.has-enriched-classpath=false"]}
11658

117-
:no-dynapath {:jvm-opts ["-Dorchard.use-dynapath=false"]
118-
:resource-paths [~(unzipped-jdk-source)]
119-
:plugins ~(if jdk8?
120-
'[[lein-jdk-tools "0.1.1"]]
121-
[])}
59+
:enrich-classpath {:plugins [[mx.cider/enrich-classpath "1.5.0"]]
60+
:middleware [cider.enrich-classpath/middleware]
61+
:jvm-opts ["-Dorchard.internal.has-enriched-classpath=true"]}
12262

12363
;; Development tools
12464
:dev {:dependencies [[org.clojure/tools.namespace "1.1.0"]]
@@ -132,9 +72,16 @@
13272
letfn [[:block 1] [:inner 2]]}}}
13373

13474
:clj-kondo [:test
135-
{:dependencies [[clj-kondo "2021.10.19"]]}]
136-
137-
:eastwood {:plugins [[jonase/eastwood "0.9.9"]]
138-
:eastwood {:exclude-namespaces [~(if jdk8?
139-
'orchard.java.parser
140-
'orchard.java.legacy-parser)]}}})
75+
{:dependencies [[clj-kondo "2021.12.01"]]}]
76+
77+
:eastwood {:plugins [[jonase/eastwood "1.0.0"]]
78+
:eastwood {:exclude-namespaces ~(cond-> []
79+
jdk8?
80+
(conj 'orchard.java.parser)
81+
82+
(or (not jdk8?)
83+
(not (-> "TEST_PROFILES"
84+
System/getenv
85+
(doto assert)
86+
(.contains "enrich-classpath"))))
87+
(conj 'orchard.java.legacy-parser))}}})

src-newer-jdks/orchard/java/parser.clj

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
[clojure.string :as str])
88
(:import
99
(java.io StringReader StringWriter)
10-
(javax.lang.model.element Element ElementKind ExecutableElement
11-
TypeElement VariableElement)
10+
(javax.lang.model.element Element ElementKind ExecutableElement TypeElement VariableElement)
1211
(javax.swing.text.html HTML$Tag HTMLEditorKit$ParserCallback)
1312
(javax.swing.text.html.parser ParserDelegator)
1413
(javax.tools ToolProvider)
@@ -69,9 +68,15 @@
6968
sources (-> (.getStandardFileManager compiler nil nil nil)
7069
(.getJavaFileObjectsFromFiles [tmpfile]))
7170
doclet (class (reify Doclet
72-
(init [this _ _] (reset! result nil))
73-
(run [this root] (reset! result root) true)
74-
(getSupportedOptions [this] #{})))
71+
(init [_this _ _]
72+
(reset! result nil))
73+
74+
(run [_this root]
75+
(reset! result root)
76+
true)
77+
78+
(getSupportedOptions [_this]
79+
#{})))
7580
out (StringWriter.) ; discard compiler messages
7681
opts (apply conj ["--show-members" "private"
7782
"--show-types" "private"

src/orchard/apropos.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
{:author "Jeff Valk"}
44
(:require
55
[orchard.meta :refer [var-name var-doc] :as m]
6-
[orchard.query :as query]
7-
[orchard.misc :as misc])
6+
[orchard.misc :as misc]
7+
[orchard.query :as query])
88
(:import
99
[clojure.lang MultiFn]))
1010

0 commit comments

Comments
 (0)