Permalink
Browse files

More rebust configuration file opening for agent/-premain.

  • Loading branch information...
aroemers committed Oct 26, 2012
1 parent 41b67ef commit dfde6a21519c9919c8bf43a3b74ead9491321ec6
Showing with 24 additions and 25 deletions.
  1. +24 −25 src/gluer/agent.clj
View
@@ -92,29 +92,28 @@
(if (nil? agent-args)
(do (println "Please supply a configuration file.")
(System/exit 1))
- (try
- (let [config (c/read-config (slurp agent-args))]
- (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 (:glue config))
- erroneous (filter (comp :error :parsed) parsed)]
- (if (not (empty? erroneous))
- (do (doseq [error erroneous]
- (println (format "Error parsing file '%s': %s"
- (:file-name error)
- (:error (:parsed error)))))
- (System/exit 1))
- ;; No parse errors, so build the libraries and initialise the agent.
- (let [association-library (r/build-association-library (map :parsed parsed))
- transformation-library (build-transformation-library association-library)
- adapter-library (r/build-adapter-library)
- transformer (transformer transformation-library)]
- (log-verbose "Transformation library:" transformation-library)
- (log-verbose "Adapter library:" adapter-library)
- (runtime/initialise adapter-library)
- (.addTransformer instrumentation transformer))))))
- (catch java.io.FileNotFoundException fnfe
- (println "Configuration file" agent-args "not found.")
- (System/exit 1)))))
+ (if-let [config (try (c/read-config (slurp agent-args))
+ (catch java.io.IOException ioe))]
+ (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 (:glue config))
+ erroneous (filter (comp :error :parsed) parsed)]
+ (if (not (empty? erroneous))
+ (do (doseq [error erroneous]
+ (println (format "Error parsing file '%s': %s"
+ (:file-name error)
+ (:error (:parsed error)))))
+ (System/exit 1))
+ ;; No parse errors, so build the libraries and initialise the agent.
+ (let [association-library (r/build-association-library (map :parsed parsed))
+ transformation-library (build-transformation-library association-library)
+ adapter-library (r/build-adapter-library)
+ transformer (transformer transformation-library)]
+ (log-verbose "Transformation library:" transformation-library)
+ (log-verbose "Adapter library:" adapter-library)
+ (runtime/initialise adapter-library)
+ (.addTransformer instrumentation transformer)))))
+ (do (println "Could not find or open configuration file:" agent-args)
+ (System/exit 1)))))

0 comments on commit dfde6a2

Please sign in to comment.