/*
* Name: SetupActionGenerateScript
* Author: Richard Rodger
* Release: 0.3
*
* Copyright (c) 2001-2003 Richard Rodger
*
* 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
package org.jostraca.setup;
/* Import << */
import org.jostraca.util.FileUtil;
import org.jostraca.transform.ReplaceTransform;
/* Import >> */
/** <b>Description:</b><br>
* Generate the batch or shell script that executes Jostraca.
*/
public class SetupActionGenerateScript extends SetupActionSupport {
public static final String CN = "SetupActionGenerateScript";
private String iScriptSource = "";
private String iTemplatePrefix = "";
public void doSetupImpl() throws SetupException {
String[] args = getArray( CONF_Arguments );
// REVIEW: hack - better way to handle args please!
if( 2 <= args.length && "src".equals( args[1] ) ) {
iTemplatePrefix = "src-";
}
doOperatingSystem();
}
public void doWindows() throws SetupException {
String scriptTemplatePath = "bin/"+iTemplatePrefix+"jostraca.bat.orig";
if( isYes( CONF_IsWindows9x ) ) {
scriptTemplatePath = "bin/"+iTemplatePrefix+"jostraca.bat.win9x.orig";
}
generateScript( scriptTemplatePath );
}
public void doUnix() throws SetupException {
String scriptTemplatePath = "bin/"+iTemplatePrefix+"jostraca.orig";
generateScript( scriptTemplatePath );
}
public void generateScript( String pScriptTemplatePath ) throws SetupException {
String MN = ".generateScript: ";
try {
iScriptSource = FileUtil.readFile( pScriptTemplatePath );
ReplaceTransform rt = new ReplaceTransform();
rt.addReplacement( "JOSTRACA_HOME", get( CONF_HomeFolder ) );
iScriptSource = rt.transform( iScriptSource );
iDonePhrase = "Generated "+getScriptFileDisplayName();
}
catch( Exception e ) {
throw new SetupException( CN+MN+":", EX_FIND_SCRIPT_FAILURE, e );
}
put( CONF_ScriptSource, iScriptSource );
}
public void undoSetup() throws SetupException {
// do nothing
}
public String getName() {
return CN;
}
public String getDonePhrase() {
return iDonePhrase;
}
}