Index: StartTomcat.java =================================================================== RCS file: /cvs/tomcatint/tomcat5/src/org/netbeans/modules/tomcat5/ide/StartTomcat.java,v retrieving revision 1.64 diff -u -r1.64 StartTomcat.java --- StartTomcat.java 22 Sep 2004 12:25:47 -0000 1.64 +++ StartTomcat.java 22 Sep 2004 20:49:06 -0000 @@ -70,6 +70,8 @@ //public static final String TAG_SHUTDOWN_CMD = "shutdown"; // NOI18N /** Debug startup/shutdown tag */ public static final String TAG_DEBUG_CMD = "catalina"; // NOI18N + //Special characters which need to be escaped in OpenvMS file spec + public static final String OPENVMS_EFS_SPECIAL_CHARS = ".,;[]%^& "; private static NbProcessDescriptor defaultExecDesc(String command, String argCommand, String option) { return new NbProcessDescriptor ( @@ -361,16 +363,23 @@ try { fireCmdExecProgressEvent(command == CommandType.START ? "MSG_startProcess" : "MSG_stopProcess", StateType.RUNNING); - Process p = pd.exec ( - new TomcatFormat (homeDir.getAbsolutePath ()), - new String[] { - "JAVA_HOME="+System.getProperty ("jdk.home"), // NOI18N - "CATALINA_HOME="+homeDir.getAbsolutePath (), // NOI18N - "CATALINA_BASE="+baseDir.getAbsolutePath () // NOI18N + Process p = null; + //on OpenVMS, we construct a special command file to run tomcat + if (org.openide.util.Utilities.getOperatingSystem() == org.openide.util.Utilities.OS_VMS) { + File runFile = constructVMSArgs(command, homeDir,baseDir); + p = Runtime.getRuntime().exec(unixPathToOpenVMSPath(runFile.getAbsolutePath(),false)); + } else { + p = pd.exec( + new TomcatFormat(homeDir.getAbsolutePath()), + new String[] { + "JAVA_HOME="+System.getProperty("jdk.home"), // NOI18N + "CATALINA_HOME="+homeDir.getAbsolutePath(), // NOI18N + "CATALINA_BASE="+baseDir.getAbsolutePath() // NOI18N }, true, - new File (homeDir, "bin") - ); + new File(homeDir, "bin") + ); + } if (command == CommandType.START) { tm.setTomcatProcess(p); tm.logManager().closeServerLog(); @@ -435,6 +444,228 @@ isRunning = isRunning(); } return true; + } + + /* @param c the character to test if it is in hex format + * @return true if c is in hex format + */ + private boolean isHex(char c) { + return ((c >= '0' && c <= '9') + || (c >= 'A' && c <= 'F') + || (c >= 'a' && c <= 'f')); + } + + /* @param c the character to test if it is in octal format + * @return true if c is in octal format + */ + private boolean isOct(char c) { + return (c >= '0' && c <= '7'); + } + + /* Escape the special characters in VMS path + * @param fileName file name to escape + * @return the fileName with special characters escaped + */ + private String handleEscape(String fileName) { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < fileName.length(); i++) { + char curChar = fileName.charAt(i); + + //Escape unicode and octal escape sequences + //into OpenVMS stlye unicode and hex escape characters + // + if (curChar == '\\' ) { //if in the form of \\xxx or \\uxxxx + if (((i + 5) < fileName.length()) + && fileName.charAt(i + 1) == 'u' + && isHex(fileName.charAt(i + 2)) + && isHex(fileName.charAt(i + 3)) + && isHex(fileName.charAt(i + 4)) + && isHex(fileName.charAt(i + 5))) { + sb.append("^U" + fileName.substring(i + 2, i + 6).toUpperCase()); + i += 5; + } else if (((i + 3) < fileName.length()) + && isOct(fileName.charAt(i + 1)) + && isOct(fileName.charAt(i + 2)) + && isOct(fileName.charAt(i + 3))) { + + //Convert octal to hex + // + String octNumStr = fileName.substring(i + 1, i + 4); + int octNum = Integer.parseInt(octNumStr, 8); + String hexNumStr = Integer.toString(octNum, 16); + sb.append("^" + hexNumStr); + i += 3; + } else { + sb.append(curChar); + } + } else if (OPENVMS_EFS_SPECIAL_CHARS.indexOf(curChar) >= 0) { + + //Escape OpenVMS EFS special characters + // + sb.append("^" + curChar); + } else { + sb.append(curChar); + } + } + return sb.toString(); + } + + /* Converts the file path from Unix style to VMS style + * @param unixPath Unix file path to convert + * @param isDir true if Unix file path is directory + */ + private String unixPathToOpenVMSPath(String unixPath, boolean isDir) { + if (unixPath.length() == 0) + return ""; + + StringTokenizer stoken = new StringTokenizer(unixPath, "/"); + java.util.List tokenList = new LinkedList(); + StringBuffer dirPath = new StringBuffer(); + String deviceName = new String(); + String fileName = new String(); + int tokenIndex = 0; + boolean rootExist = false; + boolean relativePath = false; + + // Tokenize the file path + // + while (stoken.hasMoreTokens()) { + String token = stoken.nextToken(); + tokenList.add(token); + } + + if (unixPath.charAt(0) == '/') { //we have a root + rootExist = true; + } + + // If the file path is "/", + // return sys$login: + // + if (tokenList.isEmpty()) { + return ("sys$login:"); + } + + //if /dir or /file + // + if ((tokenList.size() == 1) && rootExist) { + if (isDir) { + return (handleEscape((String)tokenList.get(tokenIndex++)) + ":"); + } else { + deviceName = "sys$login:"; + } + } + else if(rootExist) { + deviceName = handleEscape((String)tokenList.get(tokenIndex++)) + ":"; + } + + // Construct the VMS style directory tree + // (e.g., dir.dir2.dir3). + // + int endTokenIndex = isDir ? tokenList.size() : tokenList.size() - 1; + for (int i = tokenIndex; i < endTokenIndex; i++) { + String curToken = (String)tokenList.get(i); + if (curToken.equals("..")) { + dirPath.append("-"); + } else if (curToken.equals(".")) { + if (i == tokenIndex && !rootExist) { + relativePath = true; + } + continue; + } else { + dirPath.append(handleEscape(curToken)); + } + dirPath.append('.'); + } + if (dirPath.length() > 0) { //removes the trailing . + dirPath.deleteCharAt(dirPath.length() - 1); + } + + // Construct the complete VMS file path + // + if (isDir) { + + // Put the file name inside the [...] + // + dirPath.insert(0, '['); + + // If relative path, add "." right after "[" + // + if ((deviceName.length() == 0) && (dirPath.length() > 1)) { + dirPath.insert(1, '.'); + } + dirPath.append(']'); + return (deviceName + dirPath); + } else { + + // Get the file name. + // + fileName = (String)tokenList.get(tokenList.size()-1); + fileName = handleEscape(fileName); + if (fileName.indexOf('.') < 0) { + + // If no dot in the file name, add the dot at the end + // + fileName = fileName + "."; + } else { + + // Remove the ^ from the last dot, since it is a + // file extension delimeter + // + StringBuffer sb = new StringBuffer(fileName); + sb.deleteCharAt(fileName.lastIndexOf('^')); + fileName = sb.toString(); + } + + if (dirPath.length() > 0 ) { + + // Append the file name after the [...] + // + dirPath.insert(0, '['); + if (relativePath) { + dirPath.insert(1, '.'); + } + dirPath.append(']'); + } else { + if (relativePath) { + dirPath.append("[]"); + } + } + return (deviceName + dirPath + fileName); + } + } + + /* Construct the command file which contains the VMS commands to launch/stop + * the bundled tomcat + * @param command command type flag either to start or stop tomcat + * @param homeDir catalina home directory + * @param baseDir catalina base directory + * @return the command file to execute + */ + private File constructVMSArgs(CommandType command, File homeDir, File baseDir) { + File tmpFile = null; + try { + tmpFile = File.createTempFile("nbcmd","tomcat.com", new File(baseDir,"temp")); + tmpFile.deleteOnExit(); + String args[] = new String[8]; + args[0] = "$@" + unixPathToOpenVMSPath(homeDir.getAbsolutePath() + "/bin/catalina.com", false); + args[1] = "\"" + homeDir.getAbsolutePath() + "\""; + args[2] = "\"" + baseDir.getAbsolutePath() + "\""; + args[3] = "\"" + System.getProperty("jdk.home") + "\""; + args[4] = "\"\""; + args[5] = "\"\""; + args[6] = "\"\""; + args[7] = (command == CommandType.START) ? "\"run\"" : "\"stop\""; + + PrintWriter bw = new PrintWriter(new BufferedWriter(new FileWriter(tmpFile))); + for (int i=0; i