Changeset 15041


Ignore:
Timestamp:
06/07/17 10:48:58 (6 months ago)
Author:
mevenson
Message:

Restore compilation on Java 6

JSR-223 is always present so usage in <file:build.xml> is deprecated.

Fix compilation for SYS:RUN-PROGRAM on Java 6. Not expected to be
working very well. The general strategy is to undeprecate
SYS:RUN-SHELL-COMMAND is some manner that uses the Java 6 NIO plus
thread pools to drain IO.

Conditionalize on runtime platform of parts of our RUN-PROGRAM
implementation.

Stub implementation of NIO async processor to drain queue.

TODO: figure out how why "cat /etc/passwd" doesn't ever give output?

Location:
trunk/abcl
Files:
4 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/abcl.asd

    r15013 r15041  
    6060                         (:file "package-local-nicknames-tests")))))
    6161
     62;;; FIXME Currently requires ACBL-CONTRIB and QUICKLISP-ABCL to be
     63;;; loaded, but can't seem to put in the :defsystem-depends-on stanza
    6264(defsystem abcl/t
    6365  :description "Tests for ABCL via PROVE."
     
    7072                        :pathname "t/"
    7173                        :components ((:file "package")))
     74               (:module java6
     75                        :depends-on (package)
     76                        :pathname "t/"
     77                        :components ((:test-file "run-program")))
    7278               (:module build
    7379                        :depends-on (package)
  • trunk/abcl/build.xml

    r15009 r15041  
    4949              value="${abcl.jar.path}"/>
    5050
     51    <!-- TODO verify me -->
    5152    <fail message="Please build using Ant 1.7.1 or higher.">
    5253        <condition>
     
    5758    </fail>
    5859
    59     <!-- Checks if JSR-223 support is available - thanks to Mark Evenson -->
     60    <!-- Deprecated.  Checks if JSR-223 support is available.  Should always be true.  Unused.  D -->
    6061    <available property="abcl.jsr-223.p"
    6162               classname="javax.script.ScriptEngine"/>
     
    6667      <include name="org/armedbear/lisp/protocol/*.java"/>
    6768      <include name="org/armedbear/lisp/java/**/*.java"/>
    68       <include if="abcl.jsr-223.p"
    69                name="org/armedbear/lisp/scripting/*.java" />
    70       <include if="abcl.jsr-223.p"
    71                name="org/armedbear/lisp/scripting/util/*.java" />
     69      <include name="org/armedbear/lisp/scripting/*.java" />
     70      <include name="org/armedbear/lisp/scripting/util/*.java" />
    7271      <include name="org/armedbear/Main.java"/>
     72      <include name="org/abcl/**/*.java"/>
    7373    </patternset>
    7474
     
    7878      <include name="org/armedbear/lisp/tests/*.lisp"/>
    7979      <exclude name="org/armedbear/lisp/j.lisp"/>
    80       <include if="abcl.jsr-223.p" name="org/armedbear/lisp/scripting/lisp/*.lisp"/>
     80      <include name="org/armedbear/lisp/scripting/lisp/*.lisp"/>
    8181    </patternset>
    8282   
     
    8484    <patternset id="abcl.source.lisp.dist">
    8585      <include name="org/armedbear/lisp/boot.lisp"/>
    86       <include if="abcl.jsr-223.p"
    87                name="org/armedbear/lisp/scripting/lisp/*.lisp" />
     86      <include name="org/armedbear/lisp/scripting/lisp/*.lisp" />
    8887      <include if="abcl.compile.lisp.skip"
    8988               name="**/*.lisp" />
     
    9695      <include name="org/armedbear/lisp/**/*.cls"/>
    9796      <include name="org/armedbear/lisp/**/*.abcl"/>
     97      <include name="org/abcl/util/*.class"/>
    9898      <include name="org/armedbear/lisp/version"/>
    99       <include if="abcl.jsr-223.p"
    100                name="org/armedbear/lisp/scripting/*.class"/>
    101       <include if="abcl.jsr-223.p"
    102                name="org/armedbear/lisp/scripting/util/*.class"/>
     99      <include name="org/armedbear/lisp/scripting/*.class"/>
     100      <include name="org/armedbear/lisp/scripting/util/*.class"/>
    103101      <patternset refid="abcl.source.lisp.dist"/>
    104102      <include name="abcl.rdf"/>
     
    161159      <echo>java.version: ${java.version}</echo>
    162160      <condition property="abcl.java.version.p">
    163         <or>
     161        <!-- Unsupported as of abcl-1.5.0 due to lack of open jdk
    164162          <matches string="${java.version}"
    165163                   pattern="1\.5"/>
     164          -->
     165          <or>
    166166          <!-- Don't use 1.6.0_09 or earlier. -->
    167167          <matches string="${java.version}"
     
    182182      <echo>WARNING: Use of Java version ${java.version} not recommended.</echo>
    183183    </target>
    184        
     184
     185    <!-- Deprecated.  JSR-223 is always present -->
    185186    <target name="abcl.jsr-223.notice"
    186187            depends="abcl.init"
     
    194195
    195196    <target name="abcl.compile.java"
    196             depends="abcl.init,abcl.java.warning,abcl.jsr-223.notice">
     197            depends="abcl.init,abcl.java.warning">
    197198      <mkdir dir="${build.dir}"/>
    198199      <mkdir dir="${build.classes.dir}"/>
     
    504505        </manifest>
    505506        <metainf dir="${src.dir}/META-INF">
    506           <exclude name="services/javax.script.ScriptEngineFactory"
    507                    unless="abcl.jsr-223.p"/>
    508507        </metainf>
    509508      </jar>
     
    556555        </manifest>
    557556        <metainf dir="${src.dir}/META-INF">
    558           <exclude name="services/javax.script.ScriptEngineFactory"
    559                    unless="abcl.jsr-223.p"/>
    560557        </metainf>
    561558      </jar>
  • trunk/abcl/src/org/armedbear/lisp/run-program.lisp

    r14879 r15041  
    2929;;; obligated to do so.  If you do not wish to do so, delete this
    3030;;; exception statement from your version.
    31 
    32 (in-package "SYSTEM")
    33 
    34 (require "JAVA")
     31(in-package :system)
     32
     33(require :java)
     34
     35(defparameter *implementations*
     36  '(:java-1.6 :java-1.7 :java-1.8)) ;; UNUSED
     37(defun not-java-6 ()
     38  (not (find :java-1.6 *features*)))
    3539
    3640(export '(run-program process process-p process-input process-output
     
    144148    (let ((input-stream-p (eq input :stream))
    145149          (output-stream-p (eq output :stream))
    146           (error-stream-p (eq error :stream)))
     150          (error-stream-p (eq error :stream))
     151          output-redirection
     152          input-redirection
     153          error-redirection)
    147154      (unless output-stream-p
    148         (unless (setup-output-redirection process-builder output NIL if-output-exists)
     155        (unless (setf output-redirection
     156                      (setup-output-redirection process-builder output NIL if-output-exists))
    149157          (return-from run-program)))
    150158      (if (eq error :output)
    151159          (java:jcall "redirectErrorStream" process-builder T)
    152160          (unless error-stream-p
    153             (unless (setup-output-redirection process-builder error T if-error-exists)
     161            (unless (setf error-redirection
     162                          (setup-output-redirection process-builder error T if-error-exists))
    154163              (return-from run-program))))
    155164      (unless input-stream-p
    156         (unless (setup-input-redirection process-builder input if-input-does-not-exist)
     165        (unless (setf input-redirection
     166                      (setup-input-redirection process-builder input if-input-does-not-exist))
    157167          (return-from run-program)))
    158168      (when directory
    159169        (java:jcall "directory" process-builder (java:jnew "java.io.File" (namestring directory))))
    160       (let ((process (make-process (%process-builder-start process-builder)
    161                                    input-stream-p output-stream-p error-stream-p)))
    162         (when wait (process-wait process))
    163         process))))
     170      (let ((process
     171             (if (not-java-6)
     172                 (make-process (%process-builder-start process-builder)
     173                               input-stream-p output-stream-p error-stream-p)
     174                 (make-process (%process-builder-start process-builder)
     175                               t t t))))
     176        (when (find :java-1.6 *features*)
     177          (when input-redirection
     178            (let ((input (process-input process)))
     179              (threads:make-thread (lambda () (from-file input-redirection input)))))
     180          (when output-redirection
     181            (let ((output (process-output process))
     182                  (file (first output-redirection))
     183                  (appendp (second output-redirection)))
     184              (threads:make-thread (lambda () (to-file output file :append appendp)))))
     185          (when error-redirection
     186            (let ((error (process-error process))
     187                  (file (first output-redirection))
     188                  (appendp (second output-redirection)))
     189              (threads:make-thread (lambda () (to-file error file :append appendp))))))
     190        (when (or wait
     191                  (not-java-6)
     192                  (process-wait process))
     193          process)))))
    164194
    165195(defconstant +inherit+
    166   (java:jfield "java.lang.ProcessBuilder$Redirect" "INHERIT"))
     196  (ignore-errors
     197    (java:jfield "java.lang.ProcessBuilder$Redirect" "INHERIT")))
    167198
    168199(defun coerce-to-file (value)
     
    179210          (error "Don't know how to set up null stream on this platform."))))))
    180211
     212(define-condition implementation-not-available (error)
     213  ((missing :initarg :missing
     214            :reader missing))
     215  (:report (lambda (condition stream)
     216             (format stream "This JVM is missing the ~a implementation." (missing condition)))))
     217
    181218(defun setup-input-redirection (process-builder value if-does-not-exist)
     219  "Returns boolean truth when input redirections has been successfully set up.
     220
     221As a second value, returns either nil if input should inherit from the
     222parent process, or a java.io.File reference to the file to read input from."
    182223  (let ((redirect (if (eq value T)
    183                       +inherit+
     224                      ;; Either inherit stdio or fail
     225                      (if (not-java-6)
     226                          +inherit+
     227                          (signal 'implementation-not-available
     228                                  :missing "Inheritance for subprocess of standard input"))
     229                      ;; or read from a file
    184230                      (let ((file (coerce-to-file value)))
    185231                        (when value
     
    188234                              (unless (probe-file value)
    189235                                (ecase if-does-not-exist
    190                                   (:error (error "Input file ~S does not exist." value))
    191                                   ((NIL) (return-from setup-input-redirection))))))
    192                         (java:jstatic "from" "java.lang.ProcessBuilder$Redirect" file)))))
    193     (java:jcall "redirectInput" process-builder redirect))
    194   T)
    195 
     236                                  (:error
     237                                   (error "Input file ~S does not already exist." value))
     238                                  ((NIL)
     239                                   (return-from setup-input-redirection))))))
     240                        (if (not-java-6)
     241                            (java:jstatic "from" "java.lang.ProcessBuilder$Redirect" file)
     242                            file)))))
     243    (when (not-java-6)
     244      (java:jcall "redirectInput" process-builder redirect))
     245    redirect))
     246
     247#|
     248value
     249  t   inherit from
     250|#
    196251(defun setup-output-redirection (process-builder value errorp if-does-exist)
    197252  (let ((redirect (if (eq value T)
    198                       +inherit+
     253                      (if (not-java-6)
     254                          +inherit+
     255                          (if errorp
     256                              (signal 'implementation-not-available
     257                                      :missing "Inheritance for subprocess of standard error")
     258                              (signal 'implementation-not-available
     259                                      :missing "Inheritance for subprocess of standard output")))
    199260                      (let ((file (coerce-to-file value))
    200261                            appendp)
     
    208269                            (:append (setf appendp T))
    209270                            ((NIL) (return-from setup-output-redirection))))
    210                         (if appendp
    211                             (java:jstatic "appendTo" "java.lang.ProcessBuilder$Redirect" file)
    212                             (java:jstatic "to" "java.lang.ProcessBuilder$Redirect" file))))))
    213     (if errorp
    214         (java:jcall "redirectError" process-builder redirect)
    215         (java:jcall "redirectOutput" process-builder redirect)))
    216   T)
     271      (if (not-java-6)
     272        (if appendp
     273            (java:jstatic "appendTo" "java.lang.ProcessBuilder$Redirect" file)
     274            (java:jstatic "to" "java.lang.ProcessBuilder$Redirect" file))
     275        (list file appendp))))))
     276    (when (not-java-6)
     277      (if errorp
     278    (java:jcall "redirectError" process-builder redirect)
     279    (java:jcall "redirectOutput" process-builder redirect)))
     280    redirect))
    217281
    218282;;; The process structure.
     
    313377(defun %process-kill (jprocess)
    314378  (java:jcall "destroy" jprocess))
     379
     380(defun to-file (input java.io.file &key (append nil))
     381  (declare (ignore append)) ;; FIXME
     382  (let ((file (java:jcall "toString" java.io.file)))
     383    (with-open-file (s file
     384                       :direction :output
     385                       :element-type (stream-element-type input))
     386      (let ((buffer (make-array 8192 :element-type (stream-element-type input))))
     387        (loop
     388           :for bytes-read = (read-sequence buffer input)
     389           :while (plusp bytes-read)
     390           :do (write-sequence buffer s :end bytes-read)))))
     391  (close input))
     392
     393(defun from-file (java.io.file output)
     394  (let ((file (java:jcall "toString" java.io.file)))
     395    (with-open-file (s file
     396                       :direction :input
     397                       :element-type (stream-element-type output))
     398      (let ((buffer (make-array 8192 :element-type (stream-element-type output))))
     399        (loop
     400           :for bytes-read = (read-sequence buffer s)
     401           :while (plusp bytes-read)
     402           :do (write-sequence buffer output :end bytes-read))))
     403    (close output)))
     404 
     405#|
     406tests
     407
     408(uiop:run-program "uname -a" :output :string)
     409
     410(uiop:run-program "cat /etc/passwd" :output :string)
     411
     412|#
Note: See TracChangeset for help on using the changeset viewer.