       (let [less (->> fileset
                       (core/fileset-diff @prev)
                       core/input-files
-                      (core/by-ext [".less"]))]
+                      (core/by-ext [".less"]))
+            warning-meta (atom {})]
         (reset! prev fileset)
         (when (seq less)
           (util/info "Compiling {less}... %d changed files.\n" (count less))

                      (catch Exception e#
                        (let [data# (ex-data e#)]
                          (if (= :less4clj.core/error (:type data#))
                            {:error (.getMessage e#)}
                            (throw e#))) )))]

              ;; minimal stack trace and no data -> shorter message
              (when error
                (throw (Exception. error)))

              (swap! core/*warnings* + (count warnings))
              (doseq [{:keys [message source line char]} warnings]
                (util/warn "WARN: %s %s\n" message
                           (str (if (:uri source)
                                  (str "on file "
                                       (:uri source)
                                       (if line
                                         (str " at line " line " character " char)))))))))))
        (-> fileset
            (core/add-resource output-dir)
            core/commit!))))

  (->> fs
       core/input-files
       (core/by-ext [".main.less"])))

(defn- find-relative-path [dirs filepath]
  (if-let [file (io/file filepath)]
    (let [parent (->> dirs
                      (map io/file)
                      (some (fn [x] (if (file/parent? x file) x))))]
      (if parent (.getPath (file/relative-to parent file))))))

(defn- find-original-path [filepath]
  (let [source-paths (concat (:source-paths pod/env) (:resource-paths pod/env))
        dirs (:directories pod/env)]
    (if-let [rel-path (find-relative-path dirs filepath)]
      (or (some (fn [source-path]
                  (let [f (io/file source-path rel-path)]
                    (if (.exists f)
                      (.getPath f))))
                source-paths)
          rel-path)
      filepath)))

(defn- fixed-message
  "Replaces the tmp-path in formatted error message using path in working dir."
  [message]
  (string/replace message #"(ERROR )(file:[^\s]*)" (fn [[_ prefix wrong-path]]
                                                     (str prefix (find-original-path (.getPath (java.net.URI. wrong-path)))))))

(defn ->warning [{:keys [message source line char]}]
  {:message (some-> message
                    (fixed-message)
                    (string/replace #"\.$" ""))
   :file (if source (find-original-path (.getPath (java.net.URI. (:uri source)))))
   :line line
   :column char})

(core/deftask less
  "{less} CSS compiler.
