{
in = getClass().getResourceAsStream( resourcePrefix + platformName + "BinTemplate" );
if ( in == null )
{
throw new DaemonGeneratorException(
"Internal error: could not find template for platform '" + platformName + "'." );
}
InputStreamReader reader = new InputStreamReader( in );
Map context = new HashMap( extraVars );
context.put( "MAINCLASS", daemon.getMainClass() );
context.put( "CLASSPATH", platform.getClassPath( daemon ) );
context.put( "EXTRA_JVM_ARGUMENTS", platform.getExtraJvmArguments( daemon.getJvmSettings() ) );
context.put( "APP_NAME", daemon.getId() );
context.put( "ENV_SETUP", platform.getEnvSetup( daemon ) );
context.put( "REPO", daemon.getRepositoryName() );
if ( platform.isShowConsoleWindow( daemon ) )
{
context.put( "JAVA_BINARY", "java" );
}
else
{
context.put( "JAVA_BINARY", "start /min javaw" );
}
String appArguments = platform.getAppArguments( daemon );
if ( appArguments != null )
{
context.put( "APP_ARGUMENTS", appArguments + " " );
}
else
{
context.put( "APP_ARGUMENTS", "" );
}
String interpolationToken = platform.getInterpolationToken();
InterpolationFilterReader interpolationFilterReader =
new InterpolationFilterReader( reader, context, interpolationToken, interpolationToken );
// Set the name of the bin file
String programName = "";
if ( daemon.getId() == null || daemon.getId().trim().equals( "" ) )
{
// Get class name and use it as the filename
StringTokenizer tokenizer = new StringTokenizer( daemon.getMainClass(), "." );
while ( tokenizer.hasMoreElements() )
{
programName = tokenizer.nextToken();
}
programName = programName.toLowerCase();
}
else
{
programName = daemon.getId();
}
File binDir = new File( outputDirectory, "bin" );
FileUtils.forceMkdir( binDir );
File binFile = new File( binDir, programName + platform.getBinFileExtension() );
out = new FileWriter( binFile );
getLogger().debug( "Writing shell file for platform '" + platform.getName() + "' to '"
+ binFile.getAbsolutePath() + "'." );
IOUtil.copy( interpolationFilterReader, out );
binFile.setExecutable(true);
}
catch ( FileNotFoundException e )
{
throw new DaemonGeneratorException( "Failed to get template for bin file.", e );
}
catch ( IOException e )
{
throw new DaemonGeneratorException( "Failed to write bin file.", e );
}
finally
{
IOUtil.close( out );
IOUtil.close( in );