| 1 | (in-package :abcl/build) |
|---|
| 2 | |
|---|
| 3 | (defun maven-zip-uri () |
|---|
| 4 | #p"https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip") |
|---|
| 5 | |
|---|
| 6 | (defun xdg/mvn-executable () |
|---|
| 7 | (xdg/executable (maven-zip-uri) "bin/mvn")) |
|---|
| 8 | |
|---|
| 9 | (defparameter *maven-install-root* nil) |
|---|
| 10 | |
|---|
| 11 | (defun mvn/install () |
|---|
| 12 | "Unless (XDG/MVN-EXECUTABLE) install a version of Maven in the XDG hierarchy |
|---|
| 13 | |
|---|
| 14 | Returns the local path of the resulting mvn executable." |
|---|
| 15 | (unless (xdg/mvn-executable) |
|---|
| 16 | (xdg/install (maven-zip-uri) :type :unzip)) |
|---|
| 17 | (values |
|---|
| 18 | (xdg/mvn-executable) |
|---|
| 19 | (directory (merge-pathnames |
|---|
| 20 | "**/*" (xdg/abcl-install-root (maven-zip-uri)))))) |
|---|
| 21 | |
|---|
| 22 | (defparameter *mvn-home* nil) |
|---|
| 23 | |
|---|
| 24 | (define-condition no-installed-maven (error) |
|---|
| 25 | ((searched :initarg :searched)) |
|---|
| 26 | (:report (lambda (condition stream) |
|---|
| 27 | (declare (ignore condition)) |
|---|
| 28 | (format stream "Unable to introspect local Apache Maven installation.")))) |
|---|
| 29 | |
|---|
| 30 | (defun ensure-maven (&key (mvn-home *mvn-home* mvn-home-p) |
|---|
| 31 | (use-xdg-mvn nil use-xdg-mvn-p)) |
|---|
| 32 | "Ensure that the implementation can find and execute the Maven build tool |
|---|
| 33 | |
|---|
| 34 | If MVN-HOME is specified, attempt to configure use of that directory." |
|---|
| 35 | (declare (ignore use-xdg-mvn use-xdg-mvn-p)) |
|---|
| 36 | (cond |
|---|
| 37 | ((and (null mvn-home) mvn-home-p) |
|---|
| 38 | (warn "Unimplemented explicit auto-configuration run.")) |
|---|
| 39 | ((and mvn-home mvn-home-p) |
|---|
| 40 | (warn "Unimplemented explicit configuration with specified directory directory.")) |
|---|
| 41 | (t |
|---|
| 42 | (if *mvn-home* |
|---|
| 43 | *mvn-home* |
|---|
| 44 | (restart-case |
|---|
| 45 | (let ((mvn-home (some-directory-containing "mvn"))) |
|---|
| 46 | (unless mvn-home |
|---|
| 47 | (signal 'no-installed-maven)) |
|---|
| 48 | (setf *mvn-home* mvn-home)) |
|---|
| 49 | (install-maven () |
|---|
| 50 | (mvn/install))))))) |
|---|
| 51 | |
|---|
| 52 | (defmacro with-ensured-mvn ((maven) &body body) |
|---|
| 53 | `(progn |
|---|
| 54 | (unless ,maven |
|---|
| 55 | (setf ,maven (ensure-maven)) |
|---|
| 56 | ,@body))) |
|---|
| 57 | |
|---|
| 58 | (defun mvn/call (pom-file target-or-targets) |
|---|
| 59 | (let (mvn) |
|---|
| 60 | (with-ensured-mvn (mvn) |
|---|
| 61 | (uiop:run-program |
|---|
| 62 | `(,mvn "--file" ,(stringify pom-file) |
|---|
| 63 | ,@(listify target-or-targets)) |
|---|
| 64 | :output :string)))) |
|---|
| 65 | |
|---|
| 66 | |
|---|