/**
*#########################################################################
*
* A component of the Gatherer application, part of the Greenstone digital
* library suite from the New Zealand Digital Library Project at the
* University of Waikato, New Zealand.
*
*
*
* Author: Sam McIntosh, Greenstone Digital Library, University of Waikato
*
*
*
* Copyright (C) 2011 New Zealand Digital Library Project
*
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*########################################################################
*/
package org.greenstone.gatherer.util;
import java.io.File;
/** Class for GS3, for issuing ant commands from GLI */
public class GS3ServerThread extends Thread
{
String _gsdl3_src_path = "";
String _ant_command = "";
public GS3ServerThread(String gsdl3_src_path, String ant_command)
{
_gsdl3_src_path = gsdl3_src_path;
_ant_command = ant_command; // "restart"
}
public void run()
{
try
{
String shellCommand = null;
Process p = null;
if (Utility.isWindows())
{
if(_ant_command.indexOf("start") != -1) { // running an "ant (re)start" command on windows, run start
_ant_command = "start";
}
// The path in quotes, and the entire sequence of commands in quotes as well
// E.g. the following works: cmd /C "cd "C:\path\to\greenstone3" && ant stop"
// and it preserves any spaces in the path to GSDL3SRCHOME (_gsdl3_src_path).
p = Runtime.getRuntime().exec("cmd /C \"cd \"" + _gsdl3_src_path + File.separator + "\" && ant " + _ant_command + "\"");
}
else
{
if(_ant_command.indexOf("start") != -1) { // if running an "ant (re)start" command on non-Windows, run restart
_ant_command = "restart";
}
p = Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "ant " + _ant_command + " -f \"" + _gsdl3_src_path + File.separator + "build.xml\""});
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}