From 1dbbd42862b270a10f6ed9ce071ea247dde3baf8 Mon Sep 17 00:00:00 2001 From: David Tulig Date: Sat, 27 Dec 2014 14:41:34 -0600 Subject: [PATCH] Addresses an issue where marginalia fails to parse a project.clj where the first form in the file isn't "defproject". Instead of reading just the first line, parse-project-form will loop through the full file, stopping when defproject is found and then parse it as it always has. --- src/marginalia/core.clj | 10 +++++++--- test/marginalia/test/core.clj | 6 ++++++ test/marginalia/test/multi-def-project.clj.txt | 10 ++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 test/marginalia/test/core.clj create mode 100644 test/marginalia/test/multi-def-project.clj.txt diff --git a/src/marginalia/core.clj b/src/marginalia/core.clj index 09ffdc2..eaaccda 100644 --- a/src/marginalia/core.clj +++ b/src/marginalia/core.clj @@ -123,9 +123,13 @@ ([path] (try (let [rdr (clojure.lang.LineNumberingPushbackReader. - (java.io.FileReader. - (java.io.File. path)))] - (parse-project-form (read rdr))) + (java.io.FileReader. + (java.io.File. path)))] + (loop [line (read rdr)] + (let [found-project? (= 'defproject (first line))] + (if found-project? + (parse-project-form line) + (recur (read rdr)))))) (catch Exception e (throw (Exception. (str diff --git a/test/marginalia/test/core.clj b/test/marginalia/test/core.clj new file mode 100644 index 0000000..4986954 --- /dev/null +++ b/test/marginalia/test/core.clj @@ -0,0 +1,6 @@ +(ns marginalia.test.core + (:require marginalia.core) + (:use clojure.test)) + +(deftest parse-project-file-simple + (is (= "project-name" (:name (marginalia.core/parse-project-file "test/marginalia/test/multi-def-project.clj.txt"))))) diff --git a/test/marginalia/test/multi-def-project.clj.txt b/test/marginalia/test/multi-def-project.clj.txt new file mode 100644 index 0000000..ff56e65 --- /dev/null +++ b/test/marginalia/test/multi-def-project.clj.txt @@ -0,0 +1,10 @@ +(defn some-other-form + [] + (= 1 1)) + +(defproject project-name "0.1.0-SNAPSHOT" + :description "FIXME: write description" + :url "http://example.com/FIXME" + :license {:name "Eclipse Public License" + :url "http://www.eclipse.org/legal/epl-v10.html"} + :dependencies [[org.clojure/clojure "1.6.0"]])