Michael,

Inspired by recurring postings about failed Java package installations, I wrote the attached pre-install.m script.

It merely checks for proper setting of the JAVA_HOME environment variable and aborts pkg.m if it seems to be wrong. From the messages I saw in the mailing lists, improper setting of JAVA_HOME is the most common cause for Java package installation failures. The check revolves around presence of a libjvm.so (*nix) or jvm.cfg (on Windows systems). I wouldn't know how to check on Mac OSX, but AFAIK there are no success stories anyway for recent versions of the Java package on OSX. (IIRC on FINK or MacPorts I saw a very old Java package version, like 1.2.4 or so.)

Do you agree to add this to the Java package?


In addition, I patched the dialog functions contributed by Martin Hepperle (warndlg.m, listdlg.m, etc) to accept cellstr arrays too, so that multi-line messages can be displayed (a ML compatibility improvement).

If you agree to adding pre_install.m, I can make a new release of the Java package next week or so.

Philip
## Copyright (C) 2012 Philip Nienhuis <prnienh...@users.sf.net>
## 
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
## 
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
## 
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <http://www.gnu.org/licenses/>.

## Check for JAVA_HOME setting and JDK presence before attempting to
## install the Java package

## Author: Philip Nienhuis
## Created: 2012-06-24

function [ ret ] = pre_install ()

  jdk_ok = false;
  ## Get JAVA_HOME contents
  jh = getenv ("JAVA_HOME");
  
  ## Check if has been set at all
  if (isempty (jh))
    printf ("\nError while trying to install Java package:\n");
    printf ("environment variable 'JAVA_HOME' has not been set.\n");
    printf ("  use 'setenv (\"JAVA_HOME\", \"/full/path/to/javaJDK\")'\n");
  else
  
    ## Check if JAVA_HOME points to a jvm (that is, given the variety of
    ## Java installations in the wild, merely check JAVA_HOME/jre/lib)
    jhd = dir ([jh filesep "jre" filesep "lib"]);

    if (! isempty (jhd))
      ## Search for a subdir (hopefully <arch>/) containing a
      ## subdir client/ (*nix) or a file jvm.cfg (Windows)
      ijhd = find (cell2mat ({jhd.isdir}));
      ii = 3;                    # Ignore current and parent dirs
      while ii < numel (ijhd)
        jhsd = dir ([jh filesep "jre" filesep "lib" filesep jhd(ijhd(ii)).name]);
        ## Check if client is a subdir (hopefully of <arch>/)
        id = strmatch ("client", {jhsd.name});
        if ((! isempty (id)) && jhsd(id).isdir)
          cl_dir = [jh filesep "jre" filesep "lib" filesep jhd(ijhd(ii)).name filesep "client"];
          jhcsd = dir (cl_dir);
          ## Check for a libjvm* file inside. Should work if it's a link too.
          jdk_ok = ! isempty (strmatch ("libjvm", {jhcsd.name}));
          if (! jdk_ok); 
            printf ("  No libjvm library found in %s\n", cl_dir); 
          endif
        endif
        ## Below line especially for Windows installations
        jdk_ok = jdk_ok || (! isempty (strmatch ("JVM.CFG", upper ({jhsd.name}))));
        if (jdk_ok);  ii += numel (ijhd); endif
        ++ii;
      endwhile
    endif
    if (! jdk_ok);
      printf ("\nError while trying to install Java package:\n");
      printf ("JAVA_HOME environment variable does not properly point to a JDK\n");
    endif
  endif

  if (! jdk_ok);
    printf ("  Hint:\n");
    printf ("  JAVA_HOME should usually be set such that either:\n");
    printf ("  (on *nix:)\n");
    printf ("    <JAVA_HOME>/jre/lib/<arch>/client/ contains libjvm.so (file or symlink)\n");
    printf ("  (on Windows:) \n");
    printf ("    <JAVA_HOME>/jre/lib/<arch>/ contains a file jvm.cfg\n");
    printf ("  (<arch> depends on your system hardware, can be i386, x86_64, alpha, arm, ...)\n\n");
    error  ("Aborting pkg install");
  endif
  
endfunction
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to