Changeset 13367


Ignore:
Timestamp:
06/29/11 15:35:07 (10 years ago)
Author:
Mark Evenson
Message:

RESOLVE-DEPENDENCIES now working for remote resolution.

Something like

CL-USER> (require :abcl-asdf)
CL-USER> (abcl-asdf:resolve-dependencies "org.slf4j" "slf4j-api" "1.6.1")

should download the required dependencies for the corresponding Maven
artifact, returning the result as a string suitable for inclusion in
the CLASSPATH.

Abandoned strategy of using Maven Ant tasks to directly maniuplating
the Aether API in contemporary version of Maven 3.

Remove MVN package, folding symbols into ABCL-ASDF until clearer API
vision is in place as there is no need to complicate things at this
point.

The ASDF links are not currently working, nor is the ability to find
the Maven location under WIN32 as the resolution mechanism currently
uses UNIX 'which'.

Location:
trunk/abcl/contrib/abcl-asdf
Files:
2 edited

Legend:

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

    r13345 r13367  
    11(defpackage #:abcl-asdf
    22  (:use :cl)
    3   (:export #:package))
     3  (:export
     4   #:satisfy
     5   #:as-classpath
    46
    5 
    6 (defpackage #:mvn
    7   (:use :cl)
    8   (:export #:satisfy
    9            #:as-classpath))
     7   #:resolve-artifact
     8   #:resolve-dependencies))
    109
    1110(in-package :asdf)
    12 (defclass iri (static-class) ())
     11(defclass iri (static-class)
     12  (schema authority path query fragment))
    1313
    1414(defclass mvn (iri) ())
     
    1717(defmethod perform ((op compile-op) (c mvn))
    1818    (let ((version (component-version c)))
    19       (mvn:satisfy (component-name c)
    20                    :version (if version version :latest))))
     19      (abcl-asdf:satisfy (component-name c)
     20                         :version (if version version :latest))))
    2121
    2222(defmethod perform ((operation load-op) (c mvn))
    2323    (let ((version (component-version c)))
    2424      (java:add-to-classpath
    25        (mvn:as-classpath
    26         (mvn:satisfy (component-name c)
     25       (abcl-asdf:as-classpath
     26        (abcl-asdf:satisfy (component-name c)
    2727                     :version (if version version :latest))))))
    2828
    29 (in-package :abcl-asdf)
    30 
    31 (defun decompose (iri)
    32   (declare (ignore iri))
    33   ;;; XXX test
    34   `((:scheme :jvm)
    35     (:authority :mvn)
    36     (:host "log4j")
    37     (:version "1.4.10")))
    38 
    39 (in-package :mvn)
    40 
    41 (defparameter *maven-ant-tasks.jar*
    42   "/export/home/evenson/src/apache-maven-3.0.3/maven-ant-tasks-2.1.1.jar")
    43 
    44 #|
    45 
    46 Ant with Maven tasks would add the following
    47 
    48   <artifact:dependencies pathId="abcl.dynamic.classpath">
    49     <dependency groupId="junit" artifactId="junit" version="3.8.2"/>
    50   </artifact:dependencies>
    51 |#
    52 
    53 (defvar *ant-build-template*
    54   (format nil
    55   "<?xml version='1.0' encoding='UTF-8'?>
    56 <project xmlns='antlib:org.apache.tools.ant'
    57          xmlns:artifact='antlib:org.apache.maven.artifact.ant'
    58          name='abcl-mvn-~A' default='install'>
    59 
    60   <artifact:dependencies pathId='abcl.dynamic.classpath'>
    61     <dependency groupId='~A' artifactId='~A' version='~A'/>
    62   </artifact:dependencies>
    63 
    64   <path id='abcl.jar'>
    65     <pathelement location='/export/home/evenson/work/abcl/dist/abcl.jar'/>
    66   </path>
    67 
    68   <target name='install'>
    69     <java classname='org.armedbear.lisp.Main'>
    70       <classpath refid='abcl.jar'>
    71       <classpath refid='abcl.dynamic.classpath'>
    72     </java>
    73   </target>
    74 </project>
    75 " (symbol-name (gensym)) "junit" "junit" "3.8.2"))
     29(in-package #:abcl-asdf)
    7630
    7731(defun satisfy (name &key (version :latest))
    78   (declare (ignore name version))
    79   (let ((build.xml (ext:make-temp-file)))
    80     (with-open-file (s build.xml :direction :output)
    81       (write-string *ant-build-template* s ))
    82     (ext:run-program
    83      (format nil "ant -find ~A -lib ~A"
    84              build.xml
    85              *maven-ant-tasks.jar*))))
    86 
    87 (defun as-classpath (mvn)
     32  (declare (ignore version))
     33  (resolve-dependencies name))
     34           
     35(defun as-classpath (classpath)
    8836  "For a given MVN entry, return a list of loadable archives
    8937 suitable for addition to the classpath."
    90   (declare (ignore mvn))
    91   (error "unimplemented"))
    92                        
     38  (split-string classpath ":"))
    9339
    94 
    95 
     40(defun split-string (string split-char)
     41  (loop :for i = 0 :then (1+ j)
     42     :as j = (position split-char string :test #'string-equal :start i)
     43     :collect (subseq string i j)
     44     :while j))
  • trunk/abcl/contrib/abcl-asdf/maven-embedder.lisp

    r13364 r13367  
    1212#|
    1313Test:
     14(resolve-dependencies "org.slf4j" "slf4j-api" "1.6.1")
    1415
    15 (resolve "org.slf4j" "slf4j-api" "1.6.1")
     16(resolve-dependencies "org.apache.maven" "maven-aether-provider" "3.0.3")
    1617|#
    1718
    18 (defvar *mavens* '("/opt/local/bin/mvn3" "mvn3" "mvn"))
     19(defvar *mavens* '("/opt/local/bin/mvn3" "mvn3" "mvn" "mvn.bat")
     20  "Locations to search for the Maven executable.")
    1921
    2022(defun find-mvn ()
     
    8385  (setf *init* t))
    8486
     87(defun make-wagon-provider ()
     88  (unless *init* (init))
     89  (java:jinterface-implementation
     90   "org.sonatype.aether.connector.wagon.WagonProvider"
     91   "lookup"
     92   (lambda (role-hint)
     93     (if (string-equal "http" role-hint)
     94       (java:jnew "org.apache.maven.wagon.providers.http.LightweightHttpWagon")
     95       java:+null+))
     96   "release"
     97   (lambda (wagon)
     98     (declare (ignore wagon)))))
     99
    85100(defun repository-system ()
    86101  (unless *init* (init))
    87102  (let ((locator
    88103         (java:jnew "org.apache.maven.repository.internal.DefaultServiceLocator"))
    89         (wagon-class
    90          (java:jclass "org.sonatype.aether.connector.wagon.WagonProvider"))
    91         (wagon-provider
    92          (jss:find-java-class "LightweightHttpWagon"))
    93         (repository-connector-factory-class
    94          (java:jclass "org.sonatype.aether.connector.wagon.WagonRepositoryConnector"))
     104        (repository-connector-factory-class
     105         (java:jclass "org.sonatype.aether.spi.connector.RepositoryConnectorFactory"))
    95106        (wagon-repository-connector-factory-class
    96107         (java:jclass "org.sonatype.aether.connector.wagon.WagonRepositoryConnectorFactory"))
     108        (wagon-provider-class
     109         (java:jclass "org.sonatype.aether.connector.wagon.WagonProvider"))
    97110        (repository-system-class
    98111         (java:jclass "org.sonatype.aether.RepositorySystem")))
    99     (#"setService" locator wagon-class wagon-provider)
    100     (#"addService" locator
    101                    repository-connector-factory-class
     112    (#"addService" locator
     113                   repository-connector-factory-class
    102114                   wagon-repository-connector-factory-class)
    103     (#"getService" locator repository-system-class)))
    104 
    105 #|
    106 private static RepositorySystem newRepositorySystem()
    107 {
    108   DefaultServiceLocator locator = new DefaultServiceLocator();
    109   locator.setServices( WagonProvider.class, new ManualWagonProvider() );
    110   locator.addService( RepositoryConnectorFactory.class, WagonRepositoryConnectorFactory.class );
    111 
    112   return locator.getService( RepositorySystem.class );
    113 }
    114 |#
    115 
     115    (#"setServices" locator
     116                    wagon-provider-class
     117                    (java:jnew-array-from-list
     118                     "org.sonatype.aether.connector.wagon.WagonProvider"
     119                     (list
     120                      (make-wagon-provider))))
     121    (#"getService" locator
     122                   repository-system-class)))
     123       
    116124(defun new-session (repository-system)
    117125  (let ((session
     
    125133     (#"newLocalRepositoryManager" repository-system local-repository))))
    126134
    127 #|
    128 private static RepositorySystemSession newSession( RepositorySystem system )
    129 {
    130   MavenRepositorySystemSession session = new MavenRepositorySystemSession();
     135(defun resolve-artifact (group-id artifact-id version)
     136  (let* ((system
     137          (repository-system))
     138         (session
     139          (new-session system))
     140         (repository
     141          (jss:new "org.sonatype.aether.repository.RemoteRepository"
     142                   "central" "default" "http://repo1.maven.org/maven2/"))
     143         (artifact-string (format nil "~A:~A:~A"
     144                                  group-id artifact-id version))
     145         (artifact
     146          (jss:new "org.sonatype.aether.util.artifact.DefaultArtifact" artifact-string))
     147         (artifact-request
     148          (java:jnew "org.sonatype.aether.resolution.ArtifactRequest")))
     149    (#"setArtifact" artifact-request artifact)
     150    (#"addRepository" artifact-request repository)
     151    (#"resolveArtifact" system session artifact-request)))
    131152
    132   LocalRepository localRepo = new LocalRepository( "target/local-repo" );
    133   session.setLocalRepositoryManager( system.newLocalRepositoryManager( localRepo ) );
    134  
    135   return session;
    136 }
    137 |#
    138 
    139 (defun resolve (group-id artifact-id version)
     153(defun resolve-dependencies (group-id artifact-id version)
    140154  (unless *init* (init))
    141155  (let* ((system
     
    152166         (central
    153167          (java:jnew (jss:find-java-class "RemoteRepository")
    154                      "central" "default"
    155                      "http://repo1.maven.org/maven2/"))
     168                     "central" "default" "http://repo1.maven.org/maven2/"))
    156169         (collect-request (java:jnew (jss:find-java-class "CollectRequest"))))
    157170    (#"setRoot" collect-request dependency)
     
    168181      (#"getClassPath" nlg))))
    169182
    170 #|
    171 public static void main( String[] args )
    172   throws Exception
    173 {
    174   RepositorySystem repoSystem = newRepositorySystem();
    175183
    176   RepositorySystemSession session = newSession( repoSystem );
    177184
    178   Dependency dependency =
    179     new Dependency( new DefaultArtifact( "org.apache.maven:maven-profile:2.2.1" ), "compile" );
    180   RemoteRepository central = new RemoteRepository( "central", "default", "http://repo1.maven.org/maven2/" );
    181185
    182   CollectRequest collectRequest = new CollectRequest();
    183   collectRequest.setRoot( dependency );
    184   collectRequest.addRepository( central );
    185   DependencyNode node = repoSystem.collectDependencies( session, collectRequest ).getRoot();
     186         
    186187
    187   DependencyRequest dependencyRequest = new DependencyRequest( node, null );
    188 
    189   repoSystem.resolveDependencies( session, dependencyRequest  );
    190 
    191   PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
    192   node.accept( nlg );
    193   System.out.println( nlg.getClassPath() );
    194 }
    195 |#
    196 
Note: See TracChangeset for help on using the changeset viewer.