1 | (in-package :abcl/build) |
---|
2 | |
---|
3 | (defun maven-zip-uri () |
---|
4 | #p"http://www-eu.apache.org/dist/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-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) |
---|
13 | (xdg/install (maven-zip-uri) :type :unzip)) |
---|
14 | (values |
---|
15 | (xdg/mvn-executable) |
---|
16 | (directory (merge-pathnames |
---|
17 | "**/*" (xdg/abcl-install-root (maven-zip-uri)))))) |
---|
18 | |
---|
19 | (defparameter *mvn-home* nil) |
---|
20 | |
---|
21 | (define-condition no-installed-maven (error) |
---|
22 | ((searched :initarg :searched)) |
---|
23 | (:report (lambda (condition stream) |
---|
24 | (declare (ignore condition)) |
---|
25 | (format stream "Unable to introspect local Apache Maven installation.")))) |
---|
26 | |
---|
27 | (defun ensure-maven (&key (mvn-home *mvn-home* mvn-home-p)) |
---|
28 | (cond |
---|
29 | ((and (null mvn-home) mvn-home-p) |
---|
30 | (warn "Unimplemented explicit auto-configuration run.")) |
---|
31 | ((and mvn-home mvn-home-p) |
---|
32 | (warn "Unimplemented explicit configuration with specified directory directory.")) |
---|
33 | (t |
---|
34 | (if *mvn-home* |
---|
35 | *mvn-home* |
---|
36 | (restart-case |
---|
37 | (let ((mvn-home (some-directory-containing "mvn"))) |
---|
38 | (unless mvn-home |
---|
39 | (signal 'no-installed-maven)) |
---|
40 | (setf *mvn-home* mvn-home)) |
---|
41 | (install-maven () |
---|
42 | (mvn/install))))))) |
---|
43 | |
---|
44 | (defmacro with-ensured-mvn ((maven) &body body) |
---|
45 | `(progn |
---|
46 | (unless ,maven |
---|
47 | (setf ,maven (ensure-maven)) |
---|
48 | ,@body))) |
---|
49 | |
---|
50 | (defun mvn/call (pom-file target-or-targets) |
---|
51 | (let (mvn) |
---|
52 | (with-ensured-mvn (mvn) |
---|
53 | (uiop:run-program |
---|
54 | `(,mvn "--file" ,(stringify pom-file) |
---|
55 | ,@(listify target-or-targets)) |
---|
56 | :output :string)))) |
---|
57 | |
---|
58 | |
---|