Permalink
Browse files

Improved resolving files from config.

If a resolved file is still relative from the current working directory, a relative path will be returned. This greatly improves error messages for files that are relative to the current working directory.
  • Loading branch information...
1 parent 5cff9b6 commit 0d53c06b940b19e40bdd2287b21970b01480bccf @aroemers committed Nov 1, 2012
Showing with 12 additions and 7 deletions.
  1. +1 −1 src/gluer/agent.clj
  2. +11 −6 src/gluer/core.clj
View
@@ -98,7 +98,7 @@
(with-redefs [*verbose* (:verbose config)]
(log-verbose "Parsing .gluer files and searching for Adapters...")
;; Parse the files and check for parse errors.
- (let [parsed (r/parse-gluer-files (core/absolutise agent-args (:glue config)))
+ (let [parsed (r/parse-gluer-files (core/resolve-file-paths agent-args (:glue config)))
erroneous (filter (comp :error :parsed) parsed)]
(if (not (empty? erroneous))
(do (doseq [error erroneous]
View
@@ -95,11 +95,16 @@
;;; Helper functions.
-(defn absolutise ;--- Move this to a utility namespace?
- [root-file file-names]
- (let [root-url (java.net.URL. (str "file:" root-file))]
- (for [file-name file-names]
- (.getFile (java.net.URL. root-url file-name)))))
+(defn resolve-file-paths ;--- Move this to a utility namespace?
+ "Given a root file name and a collection of file paths, this function returns
+ the paths to the file, as resolved from the specified root. If the resulting
+ path is relative to the current working directory, that relative path is
+ returned. Otherwise, an absolute path is returned."
+ [root paths]
+ (let [root-uri (.toURI (java.io.File. root))
+ pwd-uri (.toURI (java.io.File. "."))]
+ (for [path paths]
+ (.getPath (.relativize pwd-uri (.resolve root-uri path))))))
;;; The main entry point.
@@ -114,6 +119,6 @@
(if-let [config (try (c/read-config (slurp config-file-name))
(catch java.io.IOException ioe))]
(with-redefs [*verbose* (or verbose (and (nil? verbose) (:verbose config)))]
- (check (absolutise config-file-name (:glue config))))
+ (check (resolve-file-paths config-file-name (:glue config))))
(println "Could not find or open file:" config-file-name))
(display-help-text banner)))))

0 comments on commit 0d53c06

Please sign in to comment.