001: /**
002: * Creates startup scripts.
003: */package ant;
004:
005: import java.io.BufferedOutputStream;
006: import java.io.File;
007: import java.io.FileOutputStream;
008: import java.io.OutputStream;
009:
010: public class StartupScript {
011:
012: public static void main(String[] args) throws Exception {
013: System.out.println();
014: System.out
015: .println("Startup scripts writer. Use 'StartupScript libDir destDir'");
016:
017: String fromDir;
018: String destDir;
019: if (args.length == 0) {
020: fromDir = "build/dist/lib";
021: destDir = "build/dist";
022: } else {
023: fromDir = args[0];
024: destDir = args[1];
025: }
026:
027: StringBuffer libpathWin = new StringBuffer();
028: StringBuffer libpathNix = new StringBuffer();
029:
030: File libdir = new File(fromDir);
031: System.out.println("Reading libraries from: "
032: + libdir.getAbsolutePath());
033:
034: int count = 0;
035: File[] files = libdir.listFiles();
036: for (File f : files) {
037: if (f.isDirectory())
038: continue;
039: libpathWin.append("lib/").append(f.getName()).append(";");
040: libpathNix.append("lib/").append(f.getName()).append(":");
041: count++;
042: }
043: System.out.println("Read " + count + " files");
044:
045: File distdir = new File(destDir);
046: System.out.println("Creating startup scripts in: "
047: + distdir.getAbsolutePath());
048:
049: StringBuffer text = new StringBuffer();
050: text.append("@echo off").append("\r\n");
051: text.append("\r\n");
052: text.append(
053: "rem You can set JAVA_HOME and JAVA_OPTS variables:")
054: .append("\r\n");
055: text.append("rem JAVA_HOME points to JVM").append("\r\n");
056: text.append("rem JAVA_OPTS sets JVM options").append("\r\n");
057: text.append("\r\n");
058: text.append("set JAVA_CMD=java").append("\r\n");
059: text
060: .append(
061: "if NOT \"%JAVA_HOME%\"==\"\" set JAVA_CMD=%JAVA_HOME%\\bin\\java")
062: .append("\r\n");
063: text.append("set CONF=conf").append("\r\n");
064: text.append("set LIBS=").append(libpathWin).append("\r\n");
065: text
066: .append(
067: "echo \"%JAVA_CMD%\" %JAVA_OPTS% -cp \"%CONF%;%LIBS%\" Launcher")
068: .append("\r\n");
069: text
070: .append(
071: "\"%JAVA_CMD%\" %JAVA_OPTS% -cp \"%CONF%;%LIBS%\" Launcher")
072: .append("\r\n");
073: text.append("@pause").append("\r\n");
074:
075: OutputStream out = null;
076: try {
077: out = new BufferedOutputStream(new FileOutputStream(
078: new File(distdir, "start.bat")));
079: out.write(text.toString().getBytes());
080: } finally {
081: try {
082: out.close();
083: } catch (Exception e) {
084: }
085: }
086:
087: text = new StringBuffer();
088: text.append("#!/bin/sh").append("\n");
089: text.append("\n");
090: text.append("# You can set JAVA_HOME and JAVA_OPTS variables:")
091: .append("\n");
092: text.append("# JAVA_HOME points to JVM").append("\n");
093: text.append("# JAVA_OPTS sets JVM options").append("\n");
094: text.append("\n");
095: text.append("JAVA_CMD=java").append("\n");
096: text.append("if [ ! -z \"$JAVA_HOME\" ] ; then ").append("\n");
097: text.append(" JAVA_CMD=$JAVA_HOME/bin/java").append("\n");
098: text.append("fi").append("\n");
099: text.append("CONF=conf").append("\n");
100: text.append("LIBS=").append(libpathNix).append("\n");
101: text
102: .append(
103: "echo \"$JAVA_CMD\" $JAVA_OPTS -cp \"$CONF:$LIBS\" Launcher")
104: .append("\n");
105: text
106: .append(
107: "\"$JAVA_CMD\" $JAVA_OPTS -cp \"$CONF:$LIBS\" Launcher")
108: .append("\n");
109:
110: try {
111: out = new BufferedOutputStream(new FileOutputStream(
112: new File(distdir, "start.sh")));
113: out.write(text.toString().getBytes());
114: } finally {
115: try {
116: out.close();
117: } catch (Exception e) {
118: }
119: }
120:
121: System.out.println("Startup scripts created");
122: }
123: }
|