Refactor out initialization pattern for Maven as WITH-AETHER to be

used by external consumers/manipulators of the Maven Aether libraries.

Unfinished, but can be used now to guarantee that ABCL-ASDF has
located Maven, which will be retrofitted compatible with current
usage.


TODO Introduce toplevel handler for finding Maven.
parent 4f8ef31e
;;;; The ABCL specific overrides in ASDF. ;;;; The ABCL specific overrides in ASDF.
;;;; ;;;;
;;;; Done separately from asdf.lisp for stability. ;;;; Extensions to ASDF for use by ABCL
(require :asdf) (require :asdf)
(in-package :asdf) (in-package :asdf)
...@@ -21,11 +21,6 @@ ...@@ -21,11 +21,6 @@
;; inherited from ASDF:COMPONENT ??? what are the CL semantics on overriding -- ME 2012-04-01 ;; inherited from ASDF:COMPONENT ??? what are the CL semantics on overriding -- ME 2012-04-01
#+nil (version :initform nil))) #+nil (version :initform nil)))
#+nil
(defmethod find-component ((component iri) path)
component)
;;; We intercept compilation to ensure that load-op will succeed ;;; We intercept compilation to ensure that load-op will succeed
(defmethod perform ((op compile-op) (c mvn)) (defmethod perform ((op compile-op) (c mvn))
(unless (resolved-classpath c) (unless (resolved-classpath c)
......
;;;; Use the Aether system in a localy installed Maven3 distribution to download ;;;; Use the Aether system in a localy installed Maven3 distribution to download
;;;; and install JVM artifact dependencies. ;;;; and install JVM artifact dependencies.
;;; TODO refactor out aether.lisp
#| #|
# Implementation # Implementation
...@@ -110,19 +112,23 @@ Emits warnings if not able to find a suitable executable." ...@@ -110,19 +112,23 @@ Emits warnings if not able to find a suitable executable."
(defun find-mvn-libs () (defun find-mvn-libs ()
(unless (find-mvn) (unless (find-mvn)
(warn "Failed to find Maven executable to determine Aether library location.")) (warn "Failed to find Maven executable to determine Aether library location. Continuing anyways."))
(some (some
(lambda (d) (lambda (d)
(when (directory (merge-pathnames "maven-core*.jar" d)) (when (and
(pathnamep d)
(directory (merge-pathnames "maven-core*.jar" d)))
(truename d))) (truename d)))
(list (make-pathname :defaults (merge-pathnames "../lib/" (find-mvn)) (list (ignore-errors
:name nil :type nil) (make-pathname :defaults (merge-pathnames "../lib/" (find-mvn))
:name nil :type nil))
(ignore-errors (ignore-errors
(make-pathname :defaults (merge-pathnames "lib/" (mvn-home)) (make-pathname :defaults (merge-pathnames "lib/" (mvn-home))
:name nil :type nil)) :name nil :type nil))
;; library location for homebrew maven package on OS X ;; library location for homebrew maven package on OS X
(make-pathname :defaults (merge-pathnames "../libexec/lib/" (find-mvn)) (ignore-errors
:name nil :type nil) (make-pathname :defaults (merge-pathnames "../libexec/lib/" (find-mvn))
:name nil :type nil))
#p"/usr/local/share/java/maven3/lib/" ;; FreeBSD ports #p"/usr/local/share/java/maven3/lib/" ;; FreeBSD ports
#p"/usr/local/maven/lib/"))) ;; OpenBSD location suggested by Timo Myyrä #p"/usr/local/maven/lib/"))) ;; OpenBSD location suggested by Timo Myyrä
...@@ -184,7 +190,8 @@ Signals a simple-error with additional information if this attempt fails." ...@@ -184,7 +190,8 @@ Signals a simple-error with additional information if this attempt fails."
((or (not line) (eq line :eof)) nil) ((or (not line) (eq line :eof)) nil)
(let ((matcher (#"matcher" pattern line))) (let ((matcher (#"matcher" pattern line)))
(when (#"find" matcher) (when (#"find" matcher)
(return-from mvn-home (uiop/pathname:ensure-directory-pathname (#"group" matcher 1))))))))) (return-from mvn-home
(uiop/pathname:ensure-directory-pathname (#"group" matcher 1)))))))))
(subprocess-error (e) (subprocess-error (e)
(error "Failed to invoke Maven executable to introspect library locations: ~a." e)))) (error "Failed to invoke Maven executable to introspect library locations: ~a." e))))
...@@ -203,6 +210,14 @@ Signals a simple-error with additional information if this attempt fails." ...@@ -203,6 +210,14 @@ Signals a simple-error with additional information if this attempt fails."
(>= patch 3))) (>= patch 3)))
(list major minor patch)))) (list major minor patch))))
(define-condition no-aether-maven-libs (error)
((locations :initarg :locations
:initform nil
:reader locations))
(:report (lambda (condition stream)
(format stream "No Maven Aether libraries found locally in '~a'."
(locations condition)))))
(defparameter *init* nil) (defparameter *init* nil)
(defun init (&optional &key (force nil)) (defun init (&optional &key (force nil))
...@@ -218,10 +233,22 @@ of the mvn executable with an explicit value." ...@@ -218,10 +233,22 @@ of the mvn executable with an explicit value."
(setf *mvn-libs-directory* (find-mvn-libs))) (setf *mvn-libs-directory* (find-mvn-libs)))
(unless (and *mvn-libs-directory* (unless (and *mvn-libs-directory*
(probe-file *mvn-libs-directory*)) (probe-file *mvn-libs-directory*))
(error "Please obtain and install maven-3.0.3 or later locally from <http://maven.apache.org/download.html>, then set ABCL-ASDF:*MVN-LIBS-DIRECTORY* to the directory containing maven-core-3.*.jar et. al.")) ;; FIXME Remove warning; put message in restart
(warn "Please obtain and install maven-3.0.3 or later locally from <http://maven.apache.org/download.html>, then set ABCL-ASDF:*MVN-LIBS-DIRECTORY* to the directory containing maven-core-3.*.jar et. al.")
(error (make-condition 'abcl-asdf::no-aether-maven-libs
:locations (list *mvn-libs-directory*))))
(unless (ensure-mvn-version) (unless (ensure-mvn-version)
(error "We need maven-3.0.3 or later.")) (add-directory-jars-to-class-path *mvn-libs-directory* nil) (error "We need maven-3.0.3 or later."))
(setf *init* t)) (add-directory-jars-to-class-path *mvn-libs-directory* nil)
(setf *init* t))
(defmacro with-aether ((&optional aether-directory) &body body)
"Ensure that the code in BODY is executed with the Maven Aether libraries on the classpath."
`(progn
(declare (ignore aether-directory)) ;;; FIXME
(unless abcl-asdf::*init*
(abcl-asdf::init))
,@body))
(defun find-http-wagon () (defun find-http-wagon ()
"Find an implementation of the object that provides access to http and https resources. "Find an implementation of the object that provides access to http and https resources.
...@@ -259,7 +286,8 @@ hint." ...@@ -259,7 +286,8 @@ hint."
(t (t
(progn (progn
(format cl:*load-verbose* (format cl:*load-verbose*
"~&; abcl-asdf; WagonProvider stub passed '~A' as a hint it couldn't satisfy.~%" role-hint) "~&; abcl-asdf; WagonProvider stub passed '~A' as a hint it couldn't satisfy.~%"
role-hint)
java:+null+)))) java:+null+))))
"release" "release"
(lambda (wagon) (lambda (wagon)
...@@ -267,13 +295,16 @@ hint." ...@@ -267,13 +295,16 @@ hint."
(defun find-service-locator () (defun find-service-locator ()
(or (or
(ignore-errors
(#"newServiceLocator" 'org.apache.maven.repository.internal.MavenRepositorySystemUtils)) ;; maven-3.1.0
(ignore-errors (ignore-errors
(java:jnew "org.apache.maven.repository.internal.MavenServiceLocator")) ;; maven-3.0.4 ;; maven-3.1.0
(#"newServiceLocator" 'org.apache.maven.repository.internal.MavenRepositorySystemUtils))
(ignore-errors
;; maven-3.0.4
(java:jnew "org.apache.maven.repository.internal.MavenServiceLocator"))
(ignore-errors (ignore-errors
(java:jnew "org.apache.maven.repository.internal.DefaultServiceLocator")) (java:jnew "org.apache.maven.repository.internal.DefaultServiceLocator"))
(ignore-errors ;; maven-3.1.0 using org.eclipse.aether... (ignore-errors
;; maven-3.1.0 using org.eclipse.aether...
(jss:find-java-class 'aether.impl.DefaultServiceLocator)))) (jss:find-java-class 'aether.impl.DefaultServiceLocator))))
(defun make-repository-system () (defun make-repository-system ()
...@@ -337,7 +368,8 @@ hint." ...@@ -337,7 +368,8 @@ hint."
"Construct a new aether.RepositorySystemSession from the specified REPOSITORY-SYSTEM." "Construct a new aether.RepositorySystemSession from the specified REPOSITORY-SYSTEM."
(let ((session (let ((session
(or (or
(ignore-errors (#"newSession" 'org.apache.maven.repository.internal.MavenRepositorySystemUtils)) (ignore-errors (#"newSession"
'org.apache.maven.repository.internal.MavenRepositorySystemUtils))
(ignore-errors (java:jnew (jss:find-java-class "MavenRepositorySystemSession"))))) (ignore-errors (java:jnew (jss:find-java-class "MavenRepositorySystemSession")))))
(local-repository (local-repository
(java:jnew (jss:find-java-class "LocalRepository") (java:jnew (jss:find-java-class "LocalRepository")
...@@ -472,7 +504,6 @@ Returns the Maven specific string for the artifact " ...@@ -472,7 +504,6 @@ Returns the Maven specific string for the artifact "
(setf *maven-remote-repository* r))) (setf *maven-remote-repository* r)))
*maven-remote-repository*) *maven-remote-repository*)
(defun resolve-dependencies (group-id artifact-id (defun resolve-dependencies (group-id artifact-id
&key &key
(version "LATEST" versionp) (version "LATEST" versionp)
...@@ -563,7 +594,6 @@ in Java CLASSPATH representation." ...@@ -563,7 +594,6 @@ in Java CLASSPATH representation."
"metadataResolving" "metadataResolving"
#'log))) #'log)))
(defmethod resolve ((string string)) (defmethod resolve ((string string))
"Resolve a colon separated GROUP-ID:ARTIFACT-ID[:VERSION] reference to a Maven artifact. "Resolve a colon separated GROUP-ID:ARTIFACT-ID[:VERSION] reference to a Maven artifact.
......
...@@ -8,8 +8,13 @@ ...@@ -8,8 +8,13 @@
;;; Public API ;;; Public API
#:resolve #:resolve
#:ensure-mvn-version
;; Configuring Maven
#:with-aether
#:ensure-mvn-version
#:find-mvn #:find-mvn
#:*mvn-directory* #:*mvn-directory*
......
...@@ -6,4 +6,8 @@ ...@@ -6,4 +6,8 @@
(defpackage abcl/test (defpackage abcl/test
(:use :cl :prove)) (:use :cl :prove))
(defpackage abcl/test/t/maven
(:use :cl))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment