Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
[l.droid] Check for missing SDK modules early
Browse files Browse the repository at this point in the history
This should prevent confusions like in #130.
  • Loading branch information
alexander-yakushev committed Aug 28, 2015
1 parent 79531c8 commit 01ef849
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/leiningen/droid.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
[deploy :only [install run forward-port repl deploy local-repo]]
[new :only [new init]]
[test :only [local-test]]
[utils :only [proj wrong-usage android-parameters ensure-paths
[utils :only [proj wrong-usage android-parameters sdk-sanity-check
dev-build?]]]))

(defn help
Expand Down Expand Up @@ -61,8 +61,8 @@
(init-hooks)
(when (and (nil? project) (not (#{"new" "help" "init"} cmd)))
(abort "Subtask" cmd "should be run from the project folder."))
(ensure-paths (-> project :android :sdk-path))
(doto project
sdk-sanity-check
extract-aar-dependencies
(execute-subtask cmd args))))

Expand Down
41 changes: 31 additions & 10 deletions src/leiningen/droid/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,22 @@
"Merges project's `:android` map with default Android parameters and
absolutizes paths in the `:android` map."
[{:keys [android root] :as project}]
(let [android-params (merge (get-default-android-params project) android)
sdk-path (absolutize root (:sdk-path android-params))
p (fn [& path] {:url (str "file://" (apply file sdk-path path))})]
(-> project
(update-in [:java-source-paths] conj (:gen-path android-params))
(update-in [:repositories] concat
[["android-support" (p "extras" "android" "m2repository")]
["android-play-services" (p "extras" "google" "m2repository")]])
(assoc :android android-params)
absolutize-android-paths)))
(if-not (:sdk-path android)
;; :sdk-path might be nil when this function is called from middleware
;; before the :sdk-path is merged from some external profile. In this case
;; just do nothing to project map.
project
(let [android-params (merge (get-default-android-params project) android)
sdk-path (absolutize root (:sdk-path android))
support-repo (file sdk-path "extras" "android" "m2repository")
ps-repo (file sdk-path "extras" "google" "m2repository")]
(-> project
(update-in [:java-source-paths] conj (:gen-path android-params))
(update-in [:repositories] concat
[["android-support" {:url (str "file://" support-repo)}]
["android-play-services" {:url (str "file://" ps-repo)}]])
(assoc :android android-params)
absolutize-android-paths))))

;; ### General utilities

Expand Down Expand Up @@ -208,6 +214,21 @@
(with-hooks-disabled resolve-dependencies
(resolve-dependencies :dependencies mod-proj))))

(defn sdk-sanity-check
"Ensures that :sdk-path is present in the project, and necessary modules are
installed."
[{{:keys [sdk-path target-version]} :android :as project}]
(ensure-paths sdk-path)
(let [check (fn [name file] (when-not (.exists file)
(abort name "is not installed.
Please install it from your Android SDK manager.")))]
(when-not target-version
(abort ":target-version is not specified. Abort execution."))
(check (str "SDK platform " target-version)
(file (get-sdk-platform-path sdk-path target-version)))
(check "Android Support Repository"
(file sdk-path "extras" "android" "m2repository"))))

(def ^:dynamic *sh-print-output*
"If true, print the output of the shell command regardless of *debug*."
false)
Expand Down

0 comments on commit 01ef849

Please sign in to comment.