Changeset 24600 for main/trunk/gli


Ignore:
Timestamp:
2011-09-15T16:31:11+12:00 (13 years ago)
Author:
ak19
Message:

Added gs-magick.pl script which will set the environment for ImageMagick (including LD_LIBRARY_PATH) before launching the requested ImageMagick command and arguments. By setting the Imagemagick environment from this script we ensure that the modified env variables don't create conflicts with libraries needed for normal linux execution. All the Greenstone files in the *binary* that made direct calls to imagemagick now go through this script. The affected files are perl files in bin/script and perllib and Gatherer.java of GLI. (wvware has files that test for imagemagick during compilation stage, which is independent of our changs which are only for users running imagemagick from a GS binary.) The final problems were related to how different perl files made use of the return values and the output of running their imagemagick command: they would query the 127 and/or and/or run the command with backtick operators to get the output printed to STDOUT. By inserting an intermediate gs-magick.pl file, needed to ensure that the exit code stored in 127 would at least be passed on correctly, as is necessary when testing the exit code against non-zero values or greater/less than zero (instead of comparing them with equals/not equal to 0). To get the correct exit code as emitted by imagemagick, calling code needs to shift bits in 127 and converting it to a signed value.

File:
1 edited

Legend:

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

    r24388 r24600  
    439439            }
    440440
    441             // Check for ImageMagick
    442             if (Gatherer.isGsdlRemote) {
    443                 DebugStream.println("Not checking for ImageMagick.");
    444             }
    445             else if (!(new ImageMagickTest()).found()) {
    446                 // Time for a warning message
    447                 missingImageMagick();
    448             }
    449            
    450             // Check for PDFBox
    451             if (Gatherer.isGsdlRemote) {
    452                 DebugStream.println("Not checking for PDFBox.");
    453             }
    454             else {
    455                 String gs_dir = GS3 ? gsdl3_src_path : gsdl_path;
    456                 File pdfboxExtensionFolder = new File(gs_dir+File.separator+"ext"+File.separator+"pdf-box");
    457                 if (!(pdfboxExtensionFolder.exists() && pdfboxExtensionFolder.isDirectory())) {
    458                 // The user doesn't have PDFBox, inform them of it
    459                 String zipExtension = Utility.isWindows() ? "zip" : "tar.gz";
    460                 missingPDFBox(zipExtension, pdfboxExtensionFolder.getParent());
    461                 }
    462             }
    463 
    464441
    465442            if (Gatherer.isGsdlRemote) {
     
    490467                    missingPERL();
    491468                }
     469            }
     470
     471
     472            // Check for ImageMagick - dependent on perl_path
     473            if (Gatherer.isGsdlRemote) {
     474                DebugStream.println("Not checking for ImageMagick.");
     475            }
     476            else if (!(new ImageMagickTest()).found()) {
     477                // Time for a warning message
     478                missingImageMagick();
     479            }
     480           
     481            // Check for PDFBox
     482            if (Gatherer.isGsdlRemote) {
     483                DebugStream.println("Not checking for PDFBox.");
     484            }
     485            else {
     486                String gs_dir = GS3 ? gsdl3_src_path : gsdl_path;
     487                File pdfboxExtensionFolder = new File(gs_dir+File.separator+"ext"+File.separator+"pdf-box");
     488                if (!(pdfboxExtensionFolder.exists() && pdfboxExtensionFolder.isDirectory())) {
     489                // The user doesn't have PDFBox, inform them of it
     490                String zipExtension = Utility.isWindows() ? "zip" : "tar.gz";
     491                missingPDFBox(zipExtension, pdfboxExtensionFolder.getParent());
     492                }
    492493            }
    493494
     
    15631564        public boolean found()
    15641565        {
     1566            // at this stage, GLI has already sourced setup.bash, and the necessary
     1567            // env variables will be available to the perl process we're about to launch
     1568            boolean found = false;
     1569
    15651570            try {
    1566                 String[] command = new String[2];
    1567                 command[0] = (Utility.isWindows() ? "identify.exe" : "identify");
    1568                 command[1] = "-version";
    1569                 Process image_magick_process = Runtime.getRuntime().exec(command);
     1571                // run the command `/path/to/perl -S gs-magick.pl identify -version`
     1572                ArrayList cmd_list = new ArrayList();
     1573                if (!Gatherer.isGsdlRemote) {
     1574                if(Configuration.perl_path != null) {
     1575                    cmd_list.add(Configuration.perl_path);
     1576                } else {
     1577                    System.err.println("***** ImageMagickTest Warning: Perl_path not set, calling 'perl' instead.");
     1578                    cmd_list.add("perl");
     1579                }
     1580                cmd_list.add("-S");
     1581                }
     1582                cmd_list.add("gs-magick.pl");
     1583                if(Utility.isWindows()) {
     1584                cmd_list.add("identify.exe");
     1585                } else {
     1586                cmd_list.add("identify");
     1587                }
     1588                cmd_list.add("-version");
     1589
     1590                String[] command_parts = (String[]) cmd_list.toArray(new String[0]);
     1591
     1592                String cmd_str = "";
     1593                for(int i = 0; i < command_parts.length; i++) {
     1594                    cmd_str += command_parts[i] + " ";
     1595                }
     1596                DebugStream.println("***** Running ImageMagickTest command: " + cmd_str);
     1597
     1598                Process image_magick_process = Runtime.getRuntime().exec(command_parts);
    15701599                image_magick_process.waitFor();
    15711600
     
    15741603
    15751604                BufferedReader br = new BufferedReader(isr);
    1576                 // Capture the standard output stream and seach for two particular occurances: Version and ImageMagick.
     1605                // Capture the standard output stream and seach for two particular occurrences: Version and ImageMagick.
    15771606
    15781607                String line = br.readLine();
    1579                 if (line == null) {
    1580                     return false;
    1581                 }
    1582                 String lc_line = line.toLowerCase();
    1583                 if (lc_line.indexOf("version") != -1 || lc_line.indexOf("imagemagick") != -1) {
    1584                     return true;
    1585                 } else {
    1586                     return false;
    1587                 }
    1588 
     1608                if (line != null) {
     1609                    String lc_line = line.toLowerCase();
     1610                    if (lc_line.indexOf("version") != -1 || lc_line.indexOf("imagemagick") != -1) {
     1611                    //System.err.println("*** ImageMagickTest Line: " + line);
     1612                    found = true;
     1613                    } // else found var remains false
     1614                }
     1615
     1616                // Maybe put the close in a finally (but note that it can throw and IOex too)? See
     1617                // http://download.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
     1618                br.close();
     1619                return found;
    15891620                //return (image_magick_process.exitValue() == 0);
    15901621            }
    1591             catch (IOException exception) {
    1592                 return false;
    1593             }
    1594             catch (InterruptedException exception) {
    1595                 return false;
     1622            catch (Exception exception) {   
     1623                exception.printStackTrace();
     1624                return found;
    15961625            }
    15971626        }
Note: See TracChangeset for help on using the changeset viewer.