Skip to content

Commit

Permalink
Disable the extensions performed by fs (#356)
Browse files Browse the repository at this point in the history
These could affect end-users.

Fixes #355
  • Loading branch information
vemv authored Dec 14, 2021
1 parent da81035 commit 0e7d45d
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

* [#355](https://github.com/clojure-emacs/refactor-nrepl/issues/355): Disable the side-effects (as protocol extensions) performed by the `fs` library.

## 3.1.0 (2021-11-09)

### Changes
Expand Down
6 changes: 3 additions & 3 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
^:inline-dep [org.clojure/tools.reader "1.3.6"]
^:inline-dep [cider/orchard "0.7.3"]
^:inline-dep [cljfmt "0.8.0" :exclusions [rewrite-clj rewrite-cljs]]
^:inline-dep [clj-commons/fs "1.6.307"]
^:inline-dep [clj-commons/fs "1.6.310"]
^:inline-dep [rewrite-clj "1.0.699-alpha"]
^:inline-dep [version-clj "1.0.0"]]
:exclusions [org.clojure/clojure] ; see versions matrix below
Expand Down Expand Up @@ -66,15 +66,15 @@
with-debug-bindings [[:inner 0]]
merge-meta [[:inner 0]]
try-if-let [[:block 1]]}}}]
:eastwood {:plugins [[jonase/eastwood "0.9.9"]]
:eastwood {:plugins [[jonase/eastwood "1.0.0"]]
:eastwood {;; :implicit-dependencies would fail spuriously when the CI matrix runs for Clojure < 1.10,
;; because :implicit-dependencies can only work for a certain corner case starting from 1.10.
:exclude-linters [:implicit-dependencies]
:exclude-namespaces [refactor-nrepl.plugin]
:add-linters [:performance :boxed-math]
:config-files ["eastwood.clj"]}}
:clj-kondo [:test
{:dependencies [[clj-kondo "2021.10.19"]]}]}
{:dependencies [[clj-kondo "2021.12.01"]]}]}

:jvm-opts ~(cond-> []
(System/getenv "CI")
Expand Down
5 changes: 4 additions & 1 deletion src/refactor_nrepl/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[clojure.string :as str]
[clojure.tools.namespace.parse :as parse]
[clojure.tools.reader.reader-types :as readers]
[me.raynes.fs :as fs]
[orchard.java.classpath :as cp]
[orchard.misc :as misc]
[refactor-nrepl.config :as config]
Expand All @@ -13,6 +12,10 @@
(:import
(java.io File FileReader PushbackReader StringReader)))

;; Require our `fs` customizations before `fs` is loaded:
(require '[refactor-nrepl.fs])
(require '[me.raynes.fs :as fs])

(defn version []
(let [v (-> (or (io/resource "refactor-nrepl/refactor-nrepl/project.clj")
"project.clj")
Expand Down
7 changes: 7 additions & 0 deletions src/refactor_nrepl/fs.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(ns refactor-nrepl.fs
"Sets the compile-time feature-flags from the `fs` library.
This ns should be `require`d before any other `fs` ns."
(:require
[me.raynes.fs.feature-flags]))

(alter-var-root #'me.raynes.fs.feature-flags/extend-coercions? (constantly false))
5 changes: 4 additions & 1 deletion src/refactor_nrepl/rename_file_or_dir.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns refactor-nrepl.rename-file-or-dir
(:require
[clojure.string :as str]
[me.raynes.fs :as fs]
[refactor-nrepl.core :as core]
[refactor-nrepl.ns.ns-parser :as ns-parser]
[refactor-nrepl.ns.pprint :refer [pprint-ns]]
Expand All @@ -13,6 +12,10 @@
(java.nio.file Files)
(java.util.regex Pattern)))

;; Require our `fs` customizations before `fs` is loaded:
(require '[refactor-nrepl.fs])
(require '[me.raynes.fs :as fs])

(declare -rename-file-or-dir)

(defn- chop-src-dir-prefix
Expand Down
18 changes: 18 additions & 0 deletions test/refactor_nrepl/fs_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(ns refactor-nrepl.fs-test
(:require
[clojure.java.io :as io]
[clojure.test :refer [deftest is]])
(:import
(java.io File)))

(require '[refactor-nrepl.fs])

(deftest extensions-are-disabled
(is (try
(-> "project.clj" File. .toPath io/file)
false
(catch Exception e
(assert (-> e
.getMessage
#{"No implementation of method: :as-file of protocol: #'clojure.java.io/Coercions found for class: sun.nio.fs.UnixPath"}))
true))))
15 changes: 12 additions & 3 deletions test/refactor_nrepl/ns/class_search_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@
;; see `#'acceptable-error-messages`.
;; They don't have to do with classpath parsing so there's nothing to be fixed:
(contains? acceptable-error-messages (.getMessage e))
;; Other internal classes introduced with JDK9:
(some (fn [prefix]
(-> e
.getMessage
(string/includes? prefix)))
["org.graalvm"
[;; Other internal classes introduced with JDK9:
"org.graalvm"
"sun."
"jdk."]))
"jdk."
;; Odd stuff brought in by the `fs` dependency:
"Implementing class"
"class org.apache.commons.compress.harmony.pack200.Segment can not implement org.objectweb.asm.ClassVisitor"])
(do
(.printStackTrace e)
false))
(-> e (.getMessage)))
e)

Expand All @@ -38,6 +44,8 @@
(-> (Thread/currentThread) .getContextClassLoader))
(catch NoClassDefFoundError e
(handle e))
(catch IncompatibleClassChangeError e
(handle e))
(catch ClassNotFoundException e
(handle e))
(catch UnsupportedClassVersionError e
Expand All @@ -48,6 +56,7 @@
(instance? NoClassDefFoundError v)
(instance? ClassNotFoundException v)
(instance? UnsupportedClassVersionError v)
(instance? IncompatibleClassChangeError v)
(contains? non-initializable-classes v)))

(defn ok []
Expand Down

0 comments on commit 0e7d45d

Please sign in to comment.