Changeset 31447

Show
Ignore:
Timestamp:
27.02.2017 19:27:59 (3 years ago)
Author:
ak19
Message:

If JAVA_HOME or JRE_HOME set at or if any system Java is found by search4j, Dr Bainbridge wants this to override the bundled JRE, with any system JDK that's found preferred over any system JRE found. The overriding should however only happen if the bitness of the Java found matches that of the GS installation. A recent commit added GNUfile executable to bin\windows, which ports the linux file utility to windows and allows testing the bitness of executables.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/gs3-setup.bat

    r30592 r31447  
    127127set JAVA_MIN_VERSION=1.5.0_00 
    128128set HINT=!CD!\packages\jre 
     129 
    129130::if search4j is present, use it 
    130131set FOUNDJAVAHOME= 
     
    135136) 
    136137 
     138 
     139echo. 
     140echo ******************************************************************** 
     141 
     142rem Check if any Java found matches the bitness of the Greenstone installation's binaries 
     143rem The sort of output we want: 
     144:: Installed GS as 32 bit 
     145:: Detected java is 64 bit 
     146:: Changing to use the GS bundled 32 bit jre 
     147:: We've detected a mismatch, this will only affect MG/MGPP collections for searching and GDBM database collections 
     148 
     149:: 1. What bit-ness are this Greenstone installation's binaries? 
     150:: GNUfile: http://stackoverflow.com/questions/2689168/checking-if-file-is-32bit-or-64bit-on-windows 
     151:: http://gnuwin32.sourceforge.net/packages/file.htm 
     152:: using Cygwin's file utility: 
     153:: http://stackoverflow.com/questions/2062020/how-can-i-tell-if-im-running-in-64-bit-jvm-or-32-bit-jvm-from-within-a-program 
     154:: http://stackoverflow.com/questions/4089641/programatically-determine-if-native-exe-is-32-bit-or-64-bit 
     155:: http://cygwin.com/cgi-bin2/package-grep.cgi?grep=utility 
     156:: https://cygwin.com/licensing.html 
     157:: Messy way: http://superuser.com/questions/358434/how-to-check-if-a-binary-is-32-or-64-bit-on-windows 
     158 
     159:: "%GSDLHOME%\bin\windows\GNUfile\bin\file.exe" "%GSDLHOME%\bin\windows\wvWare.exe" 
     160 
     161:: See https://ss64.com/nt/for_cmd.html for using batch FOR to loop against the results of another command. 
     162:: Running 
     163::      for /f "usebackq delims=" %%G IN (`"gs2build\bin\windows\GNUfile\bin\file.exe" gs2build\bin\windows\wvWare.exe`) do echo %%G 
     164:: prints out the entire output, e.g.: 
     165::      gs2build\bin\windows\wvWare.exe; PE32 executable for MS Windows (console) Intel 80386 32-bit 
     166:: To just get the "PE32" part of that output, set the delimiter char to space and request only the 2nd token: 
     167:: Note: Using call before the command to allow 2 sets of double quotes, see  
     168:: http://stackoverflow.com/questions/6474738/batch-file-for-f-doesnt-work-if-path-has-spaces 
     169:: Could use shortfilenames, see http://stackoverflow.com/questions/10227144/convert-long-filename-to-short-filename-8-3-using-cmd-exe 
     170for /f "usebackq tokens=2 delims= " %%G IN (`call "%GSDLHOME%\bin\windows\GNUfile\bin\file.exe" "%GSDLHOME%\bin\windows\wvWare.exe"`) do set bitness=%%G 
     171 
     172if "%bitness%" == "PE32+" ( 
     173    set bitness=64 
     174    echo The installed Greenstone is 64 bit 
     175) else ( 
     176    if "%bitness%" == "PE32" ( 
     177        set bitness=32 
     178        echo The installed Greenstone is 32 bit 
     179    ) else ( 
     180        echo WARNING: Greenstone installation is of unknown bitness. "%bitness%" is neither 32 nor 64 bit& goto bundledjre 
     181        set bitness=UNKNOWN 
     182    ) 
     183) 
     184 
     185:: 2. What bitness are any JAVA_HOME else JRE_HOME found by search4j? 
     186:: If you run the non-existent program "pinky" from batch or the DOS console, the exit value is 9009 
     187:: The same must be true if java is not installed and therefore not found. echo %errorlevel% produces 9009 
     188:: If java exists and is 32 bit, then running "java -d32 -version" has a return value of 1. echo %errorlevel% (1) 
     189:: If java exists and is 64 bit, then running "java -d32 -version" has a return value of 0. echo %errorlevel% (0) 
     190 
     191:testjavahome 
     192:: http://www.robvanderwoude.com/errorlevel.php 
     193:: https://ss64.com/nt/errorlevel.html 
    137194if DEFINED FOUNDJAVAHOME  ( 
    138   set JAVA_HOME=!FOUNDJAVAHOME! 
    139   set PATH=!FOUNDJAVAHOME!\bin;!PATH! 
    140   set RUNJAVA=!FOUNDJAVAHOME!\bin\java.exe 
    141   goto summaryThenEnd 
    142 ) 
    143  
    144 if DEFINED FOUNDJREHOME ( 
    145   set JRE_HOME=!FOUNDJREHOME! 
    146   set PATH=!FOUNDJREHOME!\bin;!PATH! 
    147   set RUNJAVA=!FOUNDJREHOME!\bin\java.exe 
    148   goto summaryThenEnd 
    149 ) 
    150  
     195    echo *** Testing bitness of JAVA_HOME found at !FOUNDJAVAHOME!: 
     196    "!FOUNDJAVAHOME!\bin\java.exe" -d%bitness% -version 2> nul 
     197    if !ERRORLEVEL! equ 1 echo *** The detected system JDK java is an incompatible bit architecture& goto testjre    
     198    if !ERRORLEVEL! equ 0 ( 
     199        echo *** The detected system JDK java is a matching %bitness% bit 
     200        echo *** Using the system JAVA_HOME detected 
     201        set JAVA_HOME=!FOUNDJAVAHOME! 
     202        set PATH=!FOUNDJAVAHOME!\bin;!PATH! 
     203        set RUNJAVA=!FOUNDJAVAHOME!\bin\java.exe 
     204        goto summaryThenEnd 
     205    )    
     206) 
     207 
     208:testjre 
     209if DEFINED FOUNDJREHOME  ( 
     210    echo *** Testing bitness of JRE_HOME found at !FOUNDJREHOME!: 
     211    "!FOUNDJREHOME!\bin\java.exe" -d%bitness% -version 2> nul 
     212    if !ERRORLEVEL! equ 1 echo *** The detected JRE java is an incompatible bit architecture& goto bundledjre 
     213    if !ERRORLEVEL! equ 0 (  
     214        rem The JRE_HOME found by search4j may be the bundled JRE, overriding any system JRE_HOME, 
     215        rem because the bundled JRE_HOME was provided as HINT to search4j.       
     216        echo *** The detected JRE java is a matching %bitness% bit 
     217        echo *** Using the JRE_HOME detected 
     218        set JRE_HOME=!FOUNDJREHOME! 
     219        set PATH=!FOUNDJREHOME!\bin;!PATH! 
     220        set RUNJAVA=!FOUNDJREHOME!\bin\java.exe 
     221        goto summaryThenEnd 
     222    )    
     223) 
     224 
     225:: 3. Fall back to 32 bit JRE bundled with GS 
     226:bundledjre 
     227:: We bundled a 32 bit JRE, but what if GS was compiled with 64 bit Java? 
     228:: All but MG/MGPP and GDBM should still work with 64 bit java. 
    151229if exist "!HINT!\bin\java.exe" ( 
     230  echo *** Changing to use the GS bundled 32-bit jre. 
    152231  set JAVA_HOME=!HINT! 
    153232  set PATH=!JAVA_HOME!\bin;!PATH! 
     
    156235) 
    157236 
     237:: 4. Last ditch effort: search4j couldn't find any java, but check any Java env vars set anyway 
     238echo *** Search4j could not find an appropriate JAVA or JRE. 
     239echo *** Attempting to use any JAVA_HOME else JRE_HOME in the environment... 
     240     
    158241if exist "!JAVA_HOME!\bin\java.exe" ( 
    159242  set PATH=!JAVA_HOME!\bin;!PATH! 
     
    163246  echo          The source distribution of Greenstone3 requires Java 1.5 or greater 
    164247  echo          SVN users may still use Java 1.4 
     248  echo. 
    165249  goto summaryThenEnd 
    166250) 
     
    170254  set RUNJAVA=!JRE_HOME!\bin\java.exe 
    171255  echo Using Java at !JRE_HOME! 
    172   echo WARNING: Greenstone has not checked the version number of this Java installation 
     256  echo WARNING: Greenstone has not checked the version number of this JRE installation 
    173257  echo          The source distribution of Greenstone3 requires Java 1.5 or greater 
    174258  echo          SVN users may still use Java 1.4 
     259  echo. 
    175260  goto summaryThenEnd 
    176261) 
    177262 
    178263echo ERROR: Failed to locate Java 
    179 echo        Please set JAVA_HOME or JRE_HOME to point to an appropriate Java 
     264echo        Please set JAVA_HOME or JRE_HOME to point to an appropriate %bitness% bit Java 
    180265goto end 
    181266 
    182267:summaryThenEnd 
     268:: Check that the bitness of any Java found is appropriate and warn if it is not. 
     269"!RUNJAVA!" -d%bitness% -version 2> nul 
     270if !ERRORLEVEL! equ 1 ( 
     271    echo *** WARNING: Detected mismatch between the bit-ness of your Greenstone installation ^(%bitness% bit^) and the Java found. 
     272    echo *** Continuing with this Java anyway: 
     273    echo *** This will only affect MG/MGPP collections for searching, and GDBM database collections 
     274    echo *** Else set JAVA_HOME or JRE_HOME to point to an appropriate %bitness%-bit Java 
     275    echo *** Or recompile GS with your system Java: 
     276    if exist "!JAVA_HOME!" ( echo *** JAVA_HOME at !JAVA_HOME! ) else ( echo *** JRE_HOME at !JRE_HOME! ) 
     277) 
     278 
     279echo ******************************************************************** 
     280echo. 
    183281 
    184282echo GSDL3SRCHOME : !GSDL3SRCHOME!