Changeset 35661 for main


Ignore:
Timestamp:
2021-10-21T18:58:59+13:00 (3 years ago)
Author:
davidb
Message:

Adjusted solution to how -noclasspath is explicitly set by Greenstone3 so we don't get the ant vs ant.jar cross-contamination problem. Previously it had been dealt with inside the GLI GS3ServerThread.java code (explicitly adding it in). In this update, the ANT_ARGS environment variable is set in gs3-setup.bash, thereby triggering the same outcome, but only needs to be done in one place.

Location:
main/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/util/GS3ServerThread.java

    r35637 r35661  
    6363    {
    6464    ///System.err.println("**** GS3 server : " + _ant_command);
    65 
    66     // NOTE on the use of 'noclasspath'
    67     //
    68     // The inclusion of the '-noclasspath' flag is to avoid the ant bash/bat script finding the ant.jar in
    69     // Greenstone's web/WEB-INF area which ends up on CLASSPATH as a consequence of gs3-setup being run,
    70     // which -- because that ant.jar file was produced by an older JDK -- then messes up our build.xml test for
    71     // the version of java being using.  The test ends up being told the java version is 1.7, even if we are
    72     // running a JDK8 or above!
    73     //
    74     // In more detail ...
    75     // The ant.jar file we have in web/WEB-INF is from an ant v1.8.2 install make with a JDK7, and has the
    76     // undesirable side affect of changing the Java properties for 'ant.version' and 'ant.java.version'.  In the
    77     // case of the latter (ant.java.version = 1.7), this then means that when -- in our top-level build.xml
    78     // file -- we test to make sure we are running a JDK8 or better, we get the answer 1.7 and so fail-out at that
    79     // point (even though our JDK is newer than this).
    80     //
    81     // We get the problem in gli because gs3-setup.sh is run before the Java code is launched, which then goes
    82     // on to run 'ant'.  By this point CLASSPATH has been set, containing ant.jar.  You don't necessarily see the
    83     // problem running things like 'ant start' and 'ant stop' on the command line, as 'ant' is already running
    84     // before build.xml triggers the sourcing of gs3-setup.bash.
    85    
    8665   
    8766    SafeProcess p = null;
     
    9372        // The path in quotes, and the entire sequence of commands in quotes as well
    9473        // E.g. the following works in a Runtime.exec() call:
    95         // cmd /C "cd "C:\path\to\greenstone3" && ant -noclasspath stop"
     74        // cmd /C "cd "C:\path\to\greenstone3" && ant stop"
    9675        // and it preserves any spaces in the path to GSDL3SRCHOME (_gsdl3_src_path).
    97         p = new SafeProcess("cmd /C \"cd \"" + _gsdl3_src_path + File.separator + "\" && ant -noclasspath " + _ant_command + "\"");
     76        p = new SafeProcess("cmd /C \"cd \"" + _gsdl3_src_path + File.separator + "\" && ant " + _ant_command + "\"");
    9877    }
    9978    else {
     
    10180        _ant_command = "restart";
    10281        }
    103         p = new SafeProcess(new String[]{"/bin/bash", "-c", "ant -noclasspath " + _ant_command + " -f \"" + _gsdl3_src_path + File.separator + "build.xml\""});
     82        p = new SafeProcess(new String[]{"/bin/bash", "-c", "ant " + _ant_command + " -f \"" + _gsdl3_src_path + File.separator + "build.xml\""});
    10483    }
    10584   
     
    142121    SafeProcess p = null;
    143122    if (Utility.isWindows()) {
    144         // cmd /C "cd "C:\path\to\greenstone3" && ant -noclasspath stop"
    145         p = new SafeProcess("cmd /C \"cd \"" + Configuration.gsdl3_src_path + File.separator + "\" && ant -noclasspath stop\"");   
     123        // cmd /C "cd "C:\path\to\greenstone3" && ant stop"
     124        p = new SafeProcess("cmd /C \"cd \"" + Configuration.gsdl3_src_path + File.separator + "\" && ant stop\"");
    146125    } else {
    147         p = new SafeProcess(new String[]{"/bin/bash", "-c", "ant -noclasspath stop -f \"" + Configuration.gsdl3_src_path + File.separator + "build.xml\""});
     126        p = new SafeProcess(new String[]{"/bin/bash", "-c", "ant stop -f \"" + Configuration.gsdl3_src_path + File.separator + "build.xml\""});
    148127    }
    149128
     
    171150
    172151    public static boolean isServerRunning() {
    173     String antCmd = "ant -noclasspath verbose-check-tomcat-running";
     152    String antCmd = "ant verbose-check-tomcat-running";
    174153   
    175154    SafeProcess p = null;
  • main/trunk/greenstone3/gs3-setup.sh

    r35418 r35661  
    573573# Ant
    574574echo "Checking for Ant"
    575 #Note: No longer need to print out info about minimum version of Ant needed
    576 #  for Greenstone3 (v1.7.1 at the time of writing this comment!), as this is
    577 #  now explicitly tested for in the build.xml file, and an error message generated
    578 #  if not new enough
     575
     576# Note 1: No longer need to print out info about minimum version of
     577#  Ant needed for Greenstone3 (v1.8.2 at the time of updating this
     578#  comment!), as this is now explicitly tested for in the build.xml
     579#  file, and an error message generated if not new enough
     580
     581# Note 2: The setting of ANT_ARGS to '-noclasspath' flag below is to
     582#   void "cross-contamination' between this setup file -- which sets
     583#   CLASSPATH to include all the jars in <gsdl3srchome>web/WEB-INF,
     584#   including an ant.jar -- and what is needed to cleanly run the
     585#   'ant' script and have it find the matching 'ant.jar' that goes
     586#   with it (i.e. is the same version).  For example we want the
     587#   system installed /usr/bin/ant to find /usr/share/ant/lib/ant.jar
     588#
     589#   Undesirable behaviour can occur, however, when the 'ant' that is
     590#   run is the one found on PATH, and a different ant.jar is found (as
     591#   can occur when CLASSPATH is set).  For this pattern of running the
     592#   'ant' script the 'ant.jar' that is in Greenstone's web/WEB-INF
     593#   area is found.  This Greenstone ant.jar file (at the time of
     594#   writing) is for ant v.1.8.2, and causes some of the Java
     595#   properities ant uses to changed.  Even if your installed 'ant' is
     596#   (say v1.10.9) and the JDK you are running is JDK11, as a
     597#   consequence of finding the older ant.jar file, ant.version is set
     598#   to 1.8.2 and ant.java.version to 1.7.  As a consequence of this,
     599#   the Greenstone3 build.xml fails to run as its minimum Java version
     600#   needs to be >=1.8
     601#
     602#   In looking at how to address this issue, updating the version of ant.jar
     603#   was considered.  However, taking this approach means there will aways be
     604#   a risk of a version mismatch between a system installed 'ant' and
     605#   the version of ant.jar Greenstone includes.
     606#
     607#   The approach taken here, then, is to more carefully control the
     608#   launching of ant.  By setting ANT_ARGS to -noclasspath, the 'ant'
     609#   script is directed not to use CLASSPATH, thereby avoidig the
     610#   cross-contamination problem.
     611#
     612#   Of further note, in the event ANT_HONE is set, then the situation
     613#   we are in is much simpler, as the cross-contamination problem
     614#   doesn't arise.  This is because the 'ant' script explicitly sets
     615#   ANT_LIB, based on ANT_HOME, to explicitly pick out ant.jar file
     616#   that goes along with the script.
     617#
    579618
    580619if [ -x "$GSDL3SRCHOME/packages/ant/bin/ant" ] ; then
     
    587626    addtopath PATH "$ANT_HOME/bin"
    588627    echo "  - `ant -version`"
    589   else
    590     which ant &> /dev/null
     628  else
     629    # which ant &> /dev/null
     630    # Posix friendly way to determine if a program exists:
     631    #   https://stackoverflow.com/questions/592620/how-can-i-check-if-a-program-exists-from-a-bash-script
     632    command -v ant &> /dev/null
     633     
    591634    if [ "$?" = "0" ] ; then
    592635      echo "  - System install ant detected"
     636
     637      if [ "x$ANT_ARGS" = "x" ] ; then
     638      ANT_ARGS="-noclasspath"
     639      else
     640      ANT_ARGS="-noclasspath $ANT_ARGS"
     641      fi
     642      export ANT_ARGS
     643
    593644      echo "  - `ant -version`"
     645
    594646    else
    595647      echo "  - WARNING: Failed to find 'ant'"
Note: See TracChangeset for help on using the changeset viewer.