Changeset 24883


Ignore:
Timestamp:
2011-12-13T09:53:03+13:00 (12 years ago)
Author:
sjm84
Message:

Some updates for running Perl from Greenstone 3

Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/build
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/build/CollectionConstructor.java

    r5148 r24883  
    11package org.greenstone.gsdl3.build;
     2
     3import java.io.File;
    24
    35import org.greenstone.gsdl3.util.*;
     
    1214    /** the site in which building is to take place */
    1315    protected String site_home = null;
     16    /** the name of the site*/
     17    protected String site_name = null;
    1418    /** the name of the collection */
    1519    protected String collection_name = null;
     
    4246    public void setSiteHome(String site_home) {
    4347    this.site_home = site_home;
     48   
     49    File siteHomeFile = new File(site_home);
     50    this.site_name = siteHomeFile.getName();
    4451    }
    4552    public void setCollectionName(String coll_name) {
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/build/GS2PerlConstructor.java

    r24816 r24883  
    33// greenstome classes
    44import org.greenstone.gsdl3.util.*;
     5import org.greenstone.util.GlobalProperties;
    56
    67// xml classes
     
    1011//general java classes
    1112import java.io.BufferedReader;
     13import java.io.BufferedWriter;
     14import java.io.FileWriter;
    1215import java.io.InputStreamReader;
    1316import java.io.File;
     17import java.util.ArrayList;
    1418import java.util.Vector;
    1519
     
    4751    {
    4852        // try to get the environment variables
    49         this.gsdl2home = System.getProperty("GSDLHOME");
    50         this.gsdl3home = System.getProperty("GSDL3HOME");
    51         this.gsdlos = System.getProperty("GSDLOS");
    52         this.path = System.getProperty("PATH");
     53        this.gsdl3home = GlobalProperties.getGSDL3Home();
     54        this.gsdl2home = this.gsdl3home + File.separator + ".." + File.separator + "gs2build";
     55        this.gsdlos = System.getProperty("os.name").startsWith("Windows") ? "Windows" : "Linux";
     56        this.path = System.getenv("PATH");
     57
    5358        if (this.gsdl2home == null)
    5459        {
    55             System.err.println("You must have greenstone2 installed, and GSDLHOME set for GS2Perl building to work!!");
     60            System.err.println("You must have gs2build installed, and GSDLHOME set for GS2Perl building to work!!");
    5661            return false;
    5762        }
     
    162167        sendMessage(new ConstructionEvent(this, GSStatus.INFO, "Collection construction: build collection."));
    163168        Vector command = new Vector();
    164         command.add("buildcol.pl");
     169        command.add(GlobalProperties.getProperty("perl.path", "perl"));
     170        command.add("-S");
     171        command.add(GlobalProperties.getGS2Build() + File.separator + "bin" + File.separator + "script" + File.separator + "buildcol.pl");
     172        command.add("-site");
     173        command.add(this.site_name);
    165174        command.add("-collectdir");
    166175        command.add(GSFile.collectDir(this.site_home));
    167176        command.addAll(extractParameters(this.process_params));
    168177        command.add(this.collection_name);
     178
    169179        String[] command_str = {};
    170180        command_str = (String[]) command.toArray(command_str);
     
    175185            sendProcessComplete(new ConstructionEvent(this, GSStatus.COMPLETED, ""));
    176186        }// else an error message has already been sent, do nothing
    177             //         
    178 
    179187    }
    180188
     
    196204        {
    197205            sendMessage(new ConstructionEvent(this, GSStatus.INFO, "deleting index directory"));
    198             index_dir.delete();
     206            GSFile.deleteFile(index_dir);
    199207            if (index_dir.exists())
    200208            {
    201                 sendMessage(new ConstructionEvent(this, GSStatus.INFO, "index directory still exists!"));
     209                sendMessage(new ConstructionEvent(this, GSStatus.ERROR, "index directory still exists!"));
     210                return;
    202211            }
    203212        }
     
    207216        {
    208217            sendMessage(new ConstructionEvent(this, GSStatus.ERROR, "index dir wasn't created!"));
    209         }
    210 
    211         // run the convert coll script to convert the gs2 coll to gs3
    212         Vector command = new Vector();
    213         command.add("convert_coll_from_gs2.pl");
    214         command.add("-collectdir");
    215         command.add(GSFile.collectDir(this.site_home));
    216         command.addAll(extractParameters(this.process_params));
    217         command.add(this.collection_name);
    218         String[] command_str = {};
    219         command_str = (String[]) command.toArray(command_str);
    220 
    221         if (!runPerlCommand(command_str))
    222         {
    223             // an error has occurred, dont carry on
    224             return;
    225218        }
    226219
     
    264257        ConstructionEvent evt;
    265258
    266         String args[] = { "GSDLHOME=" + this.gsdl2home, "GSDL3HOME=" + this.gsdl3home, "GSDLOS=" + this.gsdlos, "PATH=" + this.path };
     259        ArrayList<String> args = new ArrayList<String>();
     260        args.add("GSDLHOME=" + this.gsdl2home);
     261        args.add("GSDL3HOME=" + this.gsdl3home);
     262        args.add("GSDLOS=" + this.gsdlos);
     263        args.add("GSDL-RUN-SETUP=true");
     264
     265        for (String a : System.getenv().keySet())
     266        {
     267            args.add(a + "=" + System.getenv(a));
     268        }
     269
    267270        String command_str = "";
    268271        for (int i = 0; i < command.length; i++)
     
    270273            command_str = command_str + command[i] + " ";
    271274        }
     275
    272276        sendMessage(new ConstructionEvent(this, GSStatus.INFO, "command = " + command_str));
    273277        try
     
    275279            Runtime rt = Runtime.getRuntime();
    276280            sendProcessBegun(new ConstructionEvent(this, GSStatus.ACCEPTED, "starting"));
    277             Process prcs = rt.exec(command, args);
     281            Process prcs = rt.exec(command, args.toArray(new String[args.size()]));
    278282
    279283            InputStreamReader eisr = new InputStreamReader(prcs.getErrorStream());
     
    283287            // Captures the std err of a program and pipes it into
    284288            // std in of java
     289
     290            BufferedWriter bw = new BufferedWriter(new FileWriter(GSFile.collectDir(this.site_home) + File.separator + this.collection_name + File.separator + "log" + File.separator + "build_log." + (System.currentTimeMillis()) + ".txt"));
     291            bw.write("Document Editor Build\n");
     292
    285293            String eline = null;
    286294            String stdinline = null;
     
    289297                if (eline != null)
    290298                {
     299                    //System.err.println("ERROR: " + eline);
     300                    bw.write(eline + "\n");
    291301                    sendProcessStatus(new ConstructionEvent(this, GSStatus.CONTINUING, eline));
    292302                }
    293303                if (stdinline != null)
    294304                {
     305                    //System.err.println("OUT: " + stdinline);
     306                    bw.write(stdinline + "\n");
    295307                    sendProcessStatus(new ConstructionEvent(this, GSStatus.CONTINUING, stdinline));
    296308                }
    297309            }
     310            bw.close();
     311
    298312            if (!this.cancel)
    299313            {
Note: See TracChangeset for help on using the changeset viewer.