Skip to content

Commit

Permalink
orchard.classpath: don't fail on directories ending on .jar
Browse files Browse the repository at this point in the history
  • Loading branch information
vemv committed Apr 16, 2021
1 parent c918422 commit cec3c97
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ autodoc.sh
pom.xml
pom.xml.asc
*.jar
!not-a.jar
*.class
.cljs_nashorn_repl/
nashorn_code_cache/
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bugs Fixed

* Directories in the classpath having a file extension (such as .jar) will not confuse Orchard anymore, which had the potential to cause errors.

## 0.7.0 (2021-04-13)

### New features
Expand Down
Empty file added not-a.jar/.keep
Empty file.
6 changes: 4 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
:password :env/clojars_password
:sign-releases false}]]

:jvm-opts ["-Dorchard.use-dynapath=true"]
:jvm-opts ["-Dorchard.use-dynapath=true"
"-Dclojure.main.report=stderr"]

:profiles {
;; Clojure versions matrix
Expand All @@ -101,7 +102,8 @@
[org.clojure/clojure "1.11.0-master-SNAPSHOT" :classifier "sources"]]}

:test {:dependencies [[org.clojure/java.classpath "1.0.0"]]
:resource-paths ["test-resources"]
:resource-paths ["test-resources"
"not-a.jar"]
;; Initialize the cache verbosely, as usual, so that possible issues can be more easily diagnosed:
:jvm-opts ["-Dorchard.initialize-cache.silent=false"]}

Expand Down
11 changes: 7 additions & 4 deletions src/orchard/misc.clj
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@
file extensions"
[f & exts]
(when-let [file (if (url? f)
(when (= (.getProtocol ^java.net.URL f) "file")
(when (= (.getProtocol ^java.net.URL f) "file")
(io/as-file f))
(io/as-file f))]
(some (fn [ext]
(.endsWith (.. file getName toLowerCase) ext))
exts)))
(and
;; Check for file-ness because having a specific extension implies we assume `f` is a file:
(not (directory? f))
(some (fn [ext]
(.endsWith (.. file getName toLowerCase) ext))
exts))))

(defn clj-file? [f] (file-ext? f ".clj" ".cljc"))
(defn java-file? [f] (file-ext? f ".java"))
Expand Down
29 changes: 19 additions & 10 deletions test/orchard/java/classpath_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,29 @@
(deftest classpath-test
(testing "Classpath"
(testing "URLs are absolute file paths"
(is (every? #(.isAbsolute (File. (.getPath %)))
(cp/classpath))))
(doseq [entry (cp/classpath)]
(is (-> entry .getPath File. .isAbsolute)
(pr-str entry))))
(testing "directory paths have a trailing slash"
(is (->> (cp/classpath)
(filter misc/directory?)
(every? #(.endsWith (.getPath %) "/")))))
(doseq [entry (->> (cp/classpath)
(filter misc/directory?))]
(is (-> entry .getPath (.endsWith "/")))))
(testing "contains expected entries"
(let [project-root (System/getProperty "user.dir")]
(let [project-root (System/getProperty "user.dir")
directory-with-jar-extension (some #(re-find #"not-a\.jar" (.getPath %))
(cp/classpath))]
(is (some #(= (str (io/file project-root "src")) %)
(map trim-trailing-slash (cp/classpath))))
(is (some #(= (str (io/file project-root "test")) %)
(map trim-trailing-slash (cp/classpath))))
(is (some #(re-find #".*/clojure-.*\.jar" (.getPath %))
(cp/classpath)))
(is (some #(re-find #".*/clojure-.*-sources\.jar" (.getPath %))
(cp/classpath))))))
(cp/classpath)))
(testing "Directories with .jar extension"
(assert (-> directory-with-jar-extension io/file .isDirectory))
(is (some? directory-with-jar-extension)
"Is present in the classpath")))))
(testing "System classpath"
(testing "is set correctly"
(is (= (set (map trim-trailing-slash (cp/system-classpath)))
Expand All @@ -53,10 +60,12 @@
(deftest classpath-resources-test
(testing "Iterating classpath resources"
(testing "returns non-empty lists"
(is (every? seq (map cp/classpath-seq (cp/classpath)))))
(doseq [entry (map cp/classpath-seq (cp/classpath))]
(is (seq entry)
(pr-str entry))))
(testing "returns relative paths"
(is (every? #(not (.isAbsolute (File. %)))
(mapcat cp/classpath-seq (cp/classpath))))))))
(doseq [entry (mapcat cp/classpath-seq (cp/classpath))]
(is (not (-> entry File. .isAbsolute))))))))

(when orchard.java/add-java-sources-via-dynapath?
(deftest classloader-test
Expand Down

0 comments on commit cec3c97

Please sign in to comment.