Ignore:
Timestamp:
06/22/11 14:33:55 (10 years ago)
Author:
Mark Evenson
Message:

Dynamically find location of mvn libraries based on 'mvn' in PATH.

Will not work under win32 without an analog for UNIX 'which'.

Require maven-3.0.3 or greater as the Aether API for maven-3.0.2 does
not seem to have the same classes (ugh!).

Still does not seem to resolve dependencies that are not already
present in the local repository.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/contrib/abcl-asdf/maven-embedder.lisp

    r13355 r13362  
    1010(require :jss)
    1111
    12 (defparameter *mvn-directory*
    13   "/export/home/evenson/work/apache-maven-3.0.3/lib/"
     12#|
     13Test:
     14
     15(resolve "org.slf4j" "slf4j-api" "1.6.1")
     16|#
     17
     18(defvar *mavens* '("/opt/local/bin/mvn3" "mvn3" "mvn"))
     19
     20(defun find-mvn ()
     21  (dolist (mvn-path *mavens*)
     22    (let ((mvn
     23           (handler-case
     24               (truename (read-line (sys::process-output
     25                                     (sys::run-program "which" `(,mvn-path)))))
     26             ('end-of-file ()
     27               nil))))
     28      (when mvn
     29        (return-from find-mvn mvn)))))
     30
     31(defun find-mvn-libs ()
     32  (let ((mvn (find-mvn)))
     33    (unless mvn
     34      (warn "Failed to find Maven3 libraries.")
     35      (return-from find-mvn-libs))
     36    (truename (make-pathname
     37               :defaults (merge-pathnames "../lib/" mvn)
     38               :name nil :type nil))))
     39
     40(defparameter *mvn-libs-directory*
     41  nil
    1442  "Location of 'maven-core-3.<m>.<p>.jar', 'maven-embedder-3.<m>.<p>.jar' etc.")
    1543
    16 (defun init ()
    17   (unless (probe-file *mvn-directory*)
    18     (error "You must download Maven 3 from http://maven.apache.org/download.html, then set ABCL-ASDF:*MVN-DIRECTORY* appropiately."))
    19   (jss:add-directory-jars-to-class-path *mvn-directory* nil))
     44(defun mvn-version ()
     45  (let ((line
     46         (read-line (sys::process-output (sys::run-program
     47                                          (namestring (find-mvn)) '("-version")))))
     48        (prefix "Apache Maven "))
     49
     50    (unless (eql (search prefix line) 0)
     51      (return-from mvn-version nil))
     52    (let ((version (subseq line (length prefix))))
     53      version)))
     54
     55;;; XXX will break with release of Maven 3.1.x
     56(defun ensure-mvn-version ()
     57  "Return t if Maven version is 3.0.3 or greater."
     58  (let ((version-string (mvn-version)))
     59    (and (search "3.0" version-string)
     60         (>= (parse-integer (subseq version-string
     61                                    4 (search " (" version-string)))
     62             3))))
     63
     64(defparameter *init* nil)
     65
     66(defun init ()
     67  (unless *mvn-libs-directory*
     68    (setf *mvn-libs-directory* (find-mvn-libs)))
     69  (unless (probe-file *mvn-libs-directory*)
     70    (error "You must download maven-3.0.3 from http://maven.apache.org/download.html, then set ABCL-ASDF:*MVN-DIRECTORY* appropiately."))
     71  (unless (ensure-mvn-version)
     72    (error "We need maven-3.0.3 or later."))
     73  (jss:add-directory-jars-to-class-path *mvn-libs-directory* nil)
     74  (setf *init* t))
    2075
    2176(defun repository-system ()
     77  (unless *init* (init))
    2278  (let ((locator
    2379         (java:jnew "org.apache.maven.repository.internal.DefaultServiceLocator"))
     
    72128|#
    73129
    74 ;;; XXX make-immediate-object is deprecated
    75 (defconstant +null+ (java:make-immediate-object nil :ref))
    76 
    77130(defun resolve (group-id artifact-id version)
     131  (unless *init* (init))
    78132  (let* ((system
    79133          (repository-system))
     
    98152           (dependency-request
    99153            (java:jnew (jss:find-java-class "DependencyRequest")
    100                        node +null+))
     154                       node java:+null+))
    101155           (nlg
    102156            (java:jnew (jss:find-java-class "PreorderNodeListGenerator"))))
     
    132186|#
    133187
    134 #|
    135 
    136 Test:
    137 
    138 (init)
    139 (resolve "org.slf4j" "slf4j-api" "1.6.1")
    140 |#
Note: See TracChangeset for help on using the changeset viewer.