Changeset 13284


Ignore:
Timestamp:
05/22/11 01:35:30 (10 years ago)
Author:
Mark Evenson
Message:

Fix compilation from last commit if 'jscheme.jar' isn't present.

Enlarge exported API with useful looking functions.

Location:
trunk/abcl/contrib/jss
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/contrib/jss/invoke.lisp

    r13283 r13284  
    135135;; function you care about.
    136136
    137 (defvar *max-java-method-args* 20 "Increase if you call java methods with more than 20 arguments")
    138 
    139 (defun argvs ()
    140   (let ((get (load-time-value (jmethod (jclass "java.lang.ThreadLocal") "get")))
    141   (argvs (load-time-value (jnew (jconstructor "java.lang.ThreadLocal"))))
    142   (null (load-time-value (make-immediate-object nil :ref))))
    143     (let ((res (jcall-raw get argvs)))
    144       (if (equal res null)
    145     (let ((it (jnew-array "java.lang.Object" *max-java-method-args*)))
    146       (dotimes (i *max-java-method-args*)
    147         (setf (jarray-ref it i) (jnew-array "java.lang.Object" i)))
    148       (jcall (jmethod (jclass "java.lang.ThreadLocal") "set" "java.lang.Object")
    149        argvs it)
    150       it)
    151     res))))
    152 
    153 
    154137(eval-when (:compile-toplevel :load-toplevel :execute)
    155138  (defvar *do-auto-imports* t))
     
    157140(defvar *imports-resolved-classes* (make-hash-table :test 'equal))
    158141
    159 
    160142(defun find-java-class (name)
    161143  (jclass (maybe-resolve-class-against-imports name)))
    162144
    163145(defmacro invoke-add-imports (&rest imports)
    164   "push these imports onto the search path. If multiple, earlier in list take precedence"
     146  "Push these imports onto the search path. If multiple, earlier in list take precedence"
    165147  `(eval-when (:compile-toplevel :load-toplevel :execute)
    166148     (clrhash *imports-resolved-classes*)
     
    183165(defvar *class-name-to-full-case-insensitive* (make-hash-table :test 'equalp))
    184166
    185 ;; This is the function that calls invoke to call your java method. The first argument is the
    186 ;; method name or 'new. The second is the object you are calling it on, followed by the rest of the
    187 ;; arguments. If the "object" is a symbol, then that symbol is assumed to be a java class, and
    188 ;; a static method on the class is called, otherwise a regular method is called.
     167;; This is the function that calls invoke to call your java
     168;; method. The first argument is the method name or 'new. The second
     169;; is the object you are calling it on, followed by the rest of the
     170;; arguments. If the "object" is a symbol, then that symbol is assumed
     171;; to be a java class, and a static method on the class is called,
     172;; otherwise a regular method is called.
    189173
    190174(defun invoke (method object &rest args)
    191175    (invoke-restargs method object args))
    192 
    193 (eval-when (:compile-toplevel :load-toplevel :execute)
    194   (defvar *invoke-methods*
    195     (load-time-value (jcall (jmethod "java.lang.Class" "getMethods" ) (jclass "jsint.Invoke")))))
    196176
    197177(defun invoke-restargs (method object args &optional (raw? nil))
     
    210190                (apply #'jcall method object args))))))
    211191
    212 ;;; Method name --> Object --> jmethod
    213 ;;;
     192;;; Method name as String --> String  | Symbol --> jmethod
    214193(defvar *methods-cache* (make-hash-table :test #'equal))
    215194
     
    423402        ((file-directory-p s) )
    424403        ((equal (pathname-type s) "jar")
    425          (jar-import (merge-pathnames (jcall "toString" s) (format nil "~a/" (jstatic "getProperty" "java.lang.System" "user.dir")))))))
    426    
    427     (jcall "split" cp (string (jstatic "peekStatic" '|jsint.Invoke| (jclass "java.io.File") "pathSeparatorChar")))
    428     )))
     404         (jar-import (merge-pathnames (jcall "toString" s)
     405                                                  (format nil "~a/" (jstatic "getProperty" "java.lang.System" "user.dir")))))))
     406    (jcall "split" cp
     407                       (string (jfield (jclass "java.io.File") "pathSeparatorChar"))))))
    429408    (import-class-path (jcall "getClassPath" (jstatic "getRuntimeMXBean" '|java.lang.management.ManagementFactory|)))
    430409    (import-class-path (jcall "getBootClassPath" (jstatic "getRuntimeMXBean" '|java.lang.management.ManagementFactory|)))
     
    487466      collect (#"getName" (#"elementAt" classesv i))))))
    488467   
    489 
    490 ;; Modifiy this from Java.java to add a lisp defined classloader.
    491 ;;     private static Class classForName(String className) throws ClassNotFoundException
    492 ;;     {
    493 ;;         try {
    494 ;;             return Class.forName(className);
    495 ;;         }
    496 ;;         catch (ClassNotFoundException e) {
    497 ;;             return Class.forName(className, true, JavaClassLoader.getPersistentInstance());
    498 ;;         }
    499 ;;     }
    500 ;; http://www.javaworld.com/javaworld/jw-10-1996/jw-10-indepth-p2.html
    501 
    502468(defvar *added-to-classpath* nil)
    503469
     
    525491
    526492(defun get-dynamic-class-path ()
    527   (dump-classpath)
    528 #+nil
    529   (map 'list (lambda(el)
    530          (let ((path (#"toString" el)))
    531      (if (eql (search "file:/" path) 0)
    532          (subseq path 5)
    533          path)))
    534        (#"getPathComponents" (#"getClassPath" *classpath-manager*))))
    535 
    536 #+nil
    537 (eval-when (:load-toplevel :execute)
    538   (maybe-install-bsh-classloader))
    539 
    540 
    541 
    542 ; http://java.sun.com/j2se/1.5.0/docs/api/java/lang/management/MemoryMXBean.html
    543 ; http://java.sun.com/docs/hotspot/gc/
    544 ; http://www.javaworld.com/javaworld/jw-01-2002/jw-0111-hotspotgc-p2.html
    545 ; http://java.sun.com/docs/hotspot/VMOptions.html
    546 ; http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html
    547 ; http://java.sun.com/docs/hotspot/gc1.4.2/faq.html
    548 ; http://java.sun.com/developer/technicalArticles/Programming/turbo/
    549 ;-XX:MinFreeHeapRatio=
    550 ;-XX:MaxHeapFreeRatio=
    551 ;-XX:NewRatio=
    552 ;-XX:SurvivorRatio=
    553 ;-XX:SoftRefLRUPolicyMSPerMB=10000
    554 ;-XX:+PrintTenuringDistribution
    555 ;-XX:MaxLiveObjectEvacuationRatio
    556 
     493  (rest
     494   (find-if (lambda (loader)
     495              (string= "org.armedbear.lisp.JavaClassLoader"
     496                       (jclass-name (jobject-class loader))))
     497            (dump-classpath)
     498            :key #'car)))
    557499
    558500(defun java-gc ()
     
    699641
    700642   For missing methods, a dummy implementation is provided that
    701    calls the method on DISPATCH-TO"
     643   calls the method on DISPATCH-TO."
    702644  (let ((implemented-methods
    703645         (loop for m in method-names-and-defs
     
    725667
    726668
    727 (defun java-exception-report (condition)
    728   (if (and (typep condition 'java-exception)
    729      (java-exception-cause condition)
    730      (equal (jclass-name (jobject-class (java-exception-cause condition)))
    731       "jsint.BacktraceException"))
    732       (with-output-to-string (s)
    733   (let ((writer (new 'stringwriter)))
    734     (#"printStackTrace" (#"getBaseException"(java-exception-cause condition)) (new 'printwriter writer))
    735     (write-string (#"replaceFirst" (#"toString" writer) "(?s)\\s*at sun.reflect.*" "") s))
    736   )
    737       (#"replaceFirst" (princ-to-string condition) "(?s)\\\\s*at jsint.E.*" "")))
    738 
  • trunk/abcl/contrib/jss/packages.lisp

    r13283 r13284  
    55   #:*inhibit-add-to-classpath*
    66   #:*added-to-classpath*
     7   #:*do-auto-imports*
     8
     9   #:add-directory-jars-to-class-path
    710   #:add-to-classpath
    8    #:new
     11   #:find-java-class
    912   #:need-to-add-directory-jar?
    10    #:add-directory-jars-to-class-path
    1113
    12 ;;; compatibility
    13    #:ensure-compatiblity #:*cl-user-compatibility*
    14    #:get-java-field)
     14;;; deprecated
     15   #:new ; use JAVA:NEW
     16   #:get-java-field ; use JAVA:JFIELD
     17
     18;;; Move to JAVA?
     19   #:jclass-all-interfaces
     20
     21;;; Useful utilities to convert common Java items to Lisp counterparts
     22   #:hashmap-to-hashtable
     23   #:iterable-to-list
     24   #:list-to-list
     25   #:set-to-list
     26   #:vector-to-list
     27
     28;;; Enable compatibility with jss-1.0 by placing symbols in CL-USER
     29   #:ensure-compatiblity #:*cl-user-compatibility*)
    1530   (:shadow #:add-to-classpath))
    1631
Note: See TracChangeset for help on using the changeset viewer.