Changeset 14908


Ignore:
Timestamp:
11/16/16 12:47:36 (7 years ago)
Author:
Mark Evenson
Message:

aio: use jar manifest to declare location of packaged entities

A Jar manifest may have sections which we use to declare locations
within the Jar for packaged entities. The key 'name' denotes the
relative path within the jar. The key 'Implementation-Title' uniquely
defines an id for the packaged entity. We define 'org.abcl-contrib'
to be the key that identifies the location of ABCL-CONTRIB, and we
modify the search strategy defined by SYS:FIND-CONTRIB and friends
accordingly.

<http://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html>

Location:
trunk/abcl
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/build.xml

    r14907 r14908  
    4141    <property name="abcl.jar.path"
    4242              value="${dist.dir}/abcl.jar"/>
    43     <property name="abcl.aio.jar.path"
     43    <property name="abcl-aio.jar.path"
    4444              value="${dist.dir}/abcl-aio.jar"/>
    4545    <property name="abcl.ext.dir"
     
    493493    </target>
    494494
    495     <target name="abcl.aio" depends="abcl.compile,abcl.stamp">
     495    <target name="abcl-aio.jar" depends="abcl.compile,abcl.version">
    496496      <mkdir dir="${dist.dir}"/>
    497       <jar destfile="${abcl.aio.jar.path}"
     497      <jar destfile="${abcl-aio.jar.path}"
    498498           compress="true"
    499499           update="true"
     
    507507    <patternset refid="abcl.contrib.source"/>
    508508  </fileset>
     509        <!-- According to <http://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html>
     510             any attributes not specified are ignored, so we are free to make up new attributes if necessary.  For now we just overload Implementation-Title and Implementation-Version.
     511            -->
    509512        <manifest>
    510513          <attribute name="Main-Class" value="org.armedbear.lisp.Main"/>
     
    517520                       value="${build}"/>
    518521          </section>
     522          <section name="contrib">
     523            <attribute name="Implementation-Title"
     524                       value="org.abcl-contrib"/>
     525            <!-- FIXME: declare separate abcl-contrib version? -->
     526            <attribute name="Implementation-Version" 
     527                       value="${abcl.implementation.version}"/>
     528          </section>
     529          <section name="tools">
     530            <attribute name="Implementation-Title"
     531                       value="org.abcl-tools"/>
     532          </section>
     533          <section name="src">
     534            <attribute name="Implementation-Title"
     535                       value="org.abcl-source"/>
     536            <attribute name="Implementation-Version" 
     537                       value="${abcl.implementation.version}"/>
     538          </section>
    519539        </manifest>
    520540        <metainf dir="${src.dir}/META-INF">
     
    529549            depends="abcl.jar,abcl.contrib,abcl.wrapper.unix,abcl.wrapper.windows">
    530550      <description>
    531         Creates in-place executable shell wrapper in '${abcl.wrapper.file}'
     551        Creates in-place executable shell wrapper in
     552        '${abcl.wrapper.file}'
    532553      </description>
    533554      <!-- Set from commandline or in 'build.properties' -->
     
    11731194    <import file="build-snapshot.xml" optional="true"/>
    11741195
    1175     <import file="build-maven.xml" optional="true"/>
    1176 </project>
    1177 
    1178 
    1179 
    1180 
     1196    <import file="build-maven.xml" optional="true"/> </project>
  • trunk/abcl/src/org/armedbear/lisp/abcl-contrib.lisp

    r14907 r14908  
    3434
    3535(defun find-system ()
    36   "Find the location of the system.
     36  "Find the location of the Armed Bear system implementation
    3737
    3838Used to determine relative pathname to find 'abcl-contrib.jar'."
     
    7272(defparameter *verbose* t)
    7373
    74 (defun add-contrib (abcl-contrib-jar &optional relative)
    75   "Introspects ABCL-CONTRIB-JAR for asdf systems to add to ASDF:*CENTRAL-REGISTRY*"
    76   (when abcl-contrib-jar
     74;;; FIXME: stop using the obsolete ASDF:*CENTRAL-REGISTRY*
     75(defun add-contrib (abcl-contrib-jar)
     76  "Introspects a abcl-contrib-jar path whose immediate sub-directories
     77  contain asdf definitions, adding those found to asdf."
     78  (let ((jar-path (if (ext:pathname-jar-p abcl-contrib-jar)
     79                      abcl-contrib-jar
     80                      (make-pathname :device (list abcl-contrib-jar)))))
    7781    (dolist (asdf-file
    78              (directory (make-pathname :device (list abcl-contrib-jar)
    79                                        :directory (if relative `(:absolute ,relative :wild) '(:absolute :wild))
    80                                        :name :wild
    81                                        :type "asd")))
     82             (directory (merge-pathnames "*/*.asd" jar-path)))
    8283      (let ((asdf-directory (make-pathname :defaults asdf-file :name nil :type nil)))
    8384        (unless (find asdf-directory asdf:*central-registry* :test #'equal)
     
    8788(defun find-and-add-contrib (&key (verbose nil))
    8889  "Attempt to find the ABCL contrib jar and add its contents to ASDF.
    89 Returns the pathname of the contrib if it can be found."
    90   (if *abcl-contrib*
    91       (format verbose "~&Using already initialized value of abcl-contrib:~&'~A'.~%"
    92               *abcl-contrib*)
    93       (progn
    94   (setf *abcl-contrib* (find-contrib))
    95   (format verbose "~&Using probed value of abcl-contrib:~&'~A'.~%"
    96     *abcl-contrib*)))
    97   (add-contrib *abcl-contrib*
    98          (and (equalp *abcl-contrib* (find-system-jar))
    99         "contrib"))
    100   )
     90returns the pathname of the contrib if it can be found."
     91   (if *abcl-contrib*
     92       (format verbose "~&Using already initialized value of abcl-contrib:~&'~A'.~%"
     93               *abcl-contrib*)
     94       (progn
     95         (let ((contrib (find-contrib)))
     96           (when contrib
     97             (format verbose "~&Using probed value of abcl-contrib:~&'~A'.~%"
     98                     contrib)
     99             (setf *abcl-contrib* contrib)))))
     100   (when *abcl-contrib*  ;; For bootstrap compile there will be no contrib
     101     (add-contrib *abcl-contrib*)))
     102
     103(defun find-name-for-implementation-title (file id)
     104  "For a jar FILE containing a manifest, return the name of the
     105  section which annotates 'Implementation-Title' whose string value is
     106  ID."
     107  (declare (type pathname file))
     108  (let* ((jar (java:jnew "java.util.jar.JarFile" (namestring file)))
     109         (manifest (java:jcall "getManifest" jar))
     110         (entries (java:jcall "toArray"
     111                              (java:jcall "entrySet"
     112                                          (java:jcall "getEntries" manifest)))))
     113    (dolist (entry
     114              (loop :for entry :across entries
     115                 :collecting entry))
     116      (let ((title (java:jcall "getValue"
     117                               (java:jcall "getValue" entry)
     118                               "Implementation-Title")))
     119        (when (string-equal title id)
     120          (return-from find-name-for-implementation-title
     121            (java:jcall "getKey" entry))))
     122    nil)))
    101123
    102124(defun find-contrib ()
    103   "Introspect runtime classpaths to find a loadable ABCL-CONTRIB."
    104   (or (ignore-errors
    105        (let ((system-jar (find-system-jar)))
    106    (and
    107     (probe-file (make-pathname
    108       :device (list system-jar)
    109       :directory '(:absolute "contrib")
    110       :name "README" :type "markdown" ))
    111     system-jar)))
    112       (ignore-errors
    113        (find-contrib-jar))
    114       (ignore-errors
    115         (let ((system-jar (find-system-jar)))
    116           (when system-jar
    117             (probe-file (make-pathname
    118                          :defaults system-jar
    119                          :name (concatenate 'string
    120                                             "abcl-contrib"
    121                                             (subseq (pathname-name system-jar) 4)))))))
    122       (some
    123        (lambda (u)
     125  "Introspect runtime classpaths to return a pathname containing
     126  subdirectories containing ASDF definitions."
     127
     128  (or
     129   ;; We identify the location of the directory within a jar file
     130   ;; containing abcl-contrib ASDF definitions by looking for a section
     131   ;; which contains the Implementation-Title "org.abcl-contrib".  The
     132   ;; name of that section then identifies the relative pathname to the
     133   ;; top-most directory in the Jar
     134   ;;
     135   ;; e.g. for an entry of the form
     136   ;;
     137   ;;     Name: contrib
     138   ;;     Implementation-Title: org.abcl-contrib
     139   ;;
     140   ;; the directory 'contrib' would be searched for ASDF definitions.
     141   (ignore-errors
     142        (let* ((system-jar
     143                (find-system-jar))
     144               (relative-pathname
     145                (find-name-for-implementation-title system-jar "org.abcl-contrib")))
     146          (when (and system-jar relative-pathname)
     147            (merge-pathnames (pathname (concatenate 'string
     148                                                   relative-pathname "/"))
     149                            (make-pathname
     150                             :device (list system-jar))))))
     151   (ignore-errors
     152     (find-contrib-jar))
     153   (ignore-errors
     154     (let ((system-jar (find-system-jar)))
     155       (when system-jar
    124156         (probe-file (make-pathname
    125                       :defaults (java:jcall "toString" u)
    126                       :name "abcl-contrib")))
    127        (java:jcall "getURLs" (boot-classloader)))))
     157                      :defaults system-jar
     158                      :name (concatenate 'string
     159                                         "abcl-contrib"
     160                                         (subseq (pathname-name system-jar) 4)))))))
     161   (some
     162    (lambda (u)
     163      (probe-file (make-pathname
     164                   :defaults (java:jcall "toString" u)
     165                   :name "abcl-contrib")))
     166    (java:jcall "getURLs" (boot-classloader)))))
    128167
    129168(export `(find-system
Note: See TracChangeset for help on using the changeset viewer.