source: main/trunk/gli/src/org/greenstone/gatherer/util/GS3ServerThread.java@ 29356

Last change on this file since 29356 was 29356, checked in by ak19, 10 years ago

Non-crucial commit, but I believe it may still be better to waitFor() the ant stop/start Process to finish before continuing to call other code.

File size: 3.0 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: Sam McIntosh, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 2011 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37
38package org.greenstone.gatherer.util;
39import java.io.File;
40
41/** Class for GS3, for issuing ant commands from GLI */
42public class GS3ServerThread extends Thread
43{
44 String _gsdl3_src_path = "";
45 String _ant_command = "";
46
47 public GS3ServerThread(String gsdl3_src_path, String ant_command)
48 {
49 _gsdl3_src_path = gsdl3_src_path;
50 _ant_command = ant_command; // "restart"
51 }
52
53 public void run()
54 {
55 try
56 {
57 ///System.err.println("**** GS3 server : " + _ant_command);
58
59 String shellCommand = null;
60 Process p = null;
61 if (Utility.isWindows())
62 {
63 if(_ant_command.indexOf("start") != -1) { // running an "ant (re)start" command on windows, run start
64 _ant_command = "start";
65 }
66 // The path in quotes, and the entire sequence of commands in quotes as well
67 // E.g. the following works: cmd /C "cd "C:\path\to\greenstone3" && ant stop"
68 // and it preserves any spaces in the path to GSDL3SRCHOME (_gsdl3_src_path).
69 p = Runtime.getRuntime().exec("cmd /C \"cd \"" + _gsdl3_src_path + File.separator + "\" && ant " + _ant_command + "\"");
70 }
71 else
72 {
73 if(_ant_command.indexOf("start") != -1) { // if running an "ant (re)start" command on non-Windows, run restart
74 _ant_command = "restart";
75 }
76 p = Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "ant " + _ant_command + " -f \"" + _gsdl3_src_path + File.separator + "build.xml\""});
77 }
78
79 if (p != null) {
80 int result = p.waitFor();
81 if(result != 0) {
82 System.err.println("**** Failed to successfully " + _ant_command + " the GS3 server.");
83 }
84 } else {
85 System.err.println("**** Could not start the Process to " + _ant_command + " the GS3 server.");
86 }
87
88 }
89 catch(Exception ex)
90 {
91 ex.printStackTrace();
92 }
93 }
94}
Note: See TracBrowser for help on using the repository browser.