This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 49420
Collapse All | Expand All

(-)StartTomcat.java (-8 / +239 lines)
Lines 70-75 Link Here
70
    //public static final String TAG_SHUTDOWN_CMD   = "shutdown"; // NOI18N
70
    //public static final String TAG_SHUTDOWN_CMD   = "shutdown"; // NOI18N
71
    /** Debug startup/shutdown tag */
71
    /** Debug startup/shutdown tag */
72
    public static final String TAG_DEBUG_CMD   = "catalina"; // NOI18N
72
    public static final String TAG_DEBUG_CMD   = "catalina"; // NOI18N
73
    //Special characters which need to be escaped in OpenvMS file spec
74
    public static final String OPENVMS_EFS_SPECIAL_CHARS = ".,;[]%^& ";
73
75
74
    private static NbProcessDescriptor defaultExecDesc(String command, String argCommand, String option) {
76
    private static NbProcessDescriptor defaultExecDesc(String command, String argCommand, String option) {
75
        return new NbProcessDescriptor (
77
        return new NbProcessDescriptor (
Lines 361-376 Link Here
361
                try {
363
                try {
362
                    fireCmdExecProgressEvent(command == CommandType.START ? "MSG_startProcess" : "MSG_stopProcess",
364
                    fireCmdExecProgressEvent(command == CommandType.START ? "MSG_startProcess" : "MSG_stopProcess",
363
                            StateType.RUNNING);
365
                            StateType.RUNNING);
364
                    Process p = pd.exec (
366
                    Process p = null;
365
                        new TomcatFormat (homeDir.getAbsolutePath ()), 
367
                    //on OpenVMS, we construct a special command file to run tomcat
366
                        new String[] { 
368
                    if (org.openide.util.Utilities.getOperatingSystem() == org.openide.util.Utilities.OS_VMS) {
367
                            "JAVA_HOME="+System.getProperty ("jdk.home"),  // NOI18N 
369
                        File runFile = constructVMSArgs(command, homeDir,baseDir);
368
                            "CATALINA_HOME="+homeDir.getAbsolutePath (),   // NOI18N
370
                        p = Runtime.getRuntime().exec(unixPathToOpenVMSPath(runFile.getAbsolutePath(),false));
369
                            "CATALINA_BASE="+baseDir.getAbsolutePath ()    // NOI18N
371
                    } else {
372
                        p = pd.exec(
373
                        new TomcatFormat(homeDir.getAbsolutePath()),
374
                        new String[] {
375
                            "JAVA_HOME="+System.getProperty("jdk.home"),  // NOI18N
376
                            "CATALINA_HOME="+homeDir.getAbsolutePath(),   // NOI18N
377
                            "CATALINA_BASE="+baseDir.getAbsolutePath()    // NOI18N
370
                        },
378
                        },
371
                        true,
379
                        true,
372
                        new File (homeDir, "bin")
380
                        new File(homeDir, "bin")
373
                    );
381
                        );
382
                    }
374
                    if (command == CommandType.START) {
383
                    if (command == CommandType.START) {
375
                        tm.setTomcatProcess(p);
384
                        tm.setTomcatProcess(p);
376
                        tm.logManager().closeServerLog();
385
                        tm.logManager().closeServerLog();
Lines 435-440 Link Here
435
                isRunning = isRunning();
444
                isRunning = isRunning();
436
            }
445
            }
437
            return true;
446
            return true;
447
        }
448
        
449
        /* @param c the character to test if it is in hex format
450
         *  @return true if c is in hex format
451
         */
452
        private  boolean isHex(char c) {
453
            return ((c >= '0' && c <= '9')
454
            || (c >= 'A' && c <= 'F')
455
            || (c >= 'a' && c <= 'f'));
456
        }
457
        
458
        /* @param c the character to test if it is in octal format
459
         *  @return true if c is in octal format
460
         */
461
        private  boolean isOct(char c) {
462
            return (c >= '0' && c <= '7');
463
        }
464
        
465
        /* Escape the special characters in VMS path
466
         *  @param fileName file name to escape
467
         *  @return the fileName with special characters escaped
468
         */
469
        private  String handleEscape(String fileName) {
470
            StringBuffer sb = new StringBuffer();
471
            for (int i = 0; i < fileName.length(); i++) {
472
                char curChar = fileName.charAt(i);
473
                
474
                //Escape unicode and octal escape sequences
475
                //into OpenVMS stlye unicode and hex escape characters
476
                //
477
                if (curChar == '\\'  ) {      //if in the form of \\xxx or \\uxxxx
478
                    if (((i + 5) < fileName.length())
479
                    && fileName.charAt(i + 1) == 'u'
480
                    && isHex(fileName.charAt(i + 2))
481
                    && isHex(fileName.charAt(i + 3))
482
                    && isHex(fileName.charAt(i + 4))
483
                    && isHex(fileName.charAt(i + 5))) {
484
                        sb.append("^U" + fileName.substring(i + 2, i + 6).toUpperCase());
485
                        i += 5;
486
                    } else if (((i + 3) < fileName.length())
487
                    && isOct(fileName.charAt(i + 1))
488
                    && isOct(fileName.charAt(i + 2))
489
                    && isOct(fileName.charAt(i + 3))) {
490
                        
491
                        //Convert octal to hex
492
                        //
493
                        String octNumStr = fileName.substring(i + 1, i + 4);
494
                        int octNum = Integer.parseInt(octNumStr, 8);
495
                        String hexNumStr = Integer.toString(octNum, 16);
496
                        sb.append("^" + hexNumStr);
497
                        i += 3;
498
                    } else {
499
                        sb.append(curChar);
500
                    }
501
                } else if (OPENVMS_EFS_SPECIAL_CHARS.indexOf(curChar) >= 0) {
502
                    
503
                    //Escape OpenVMS EFS special characters
504
                    //
505
                    sb.append("^" + curChar);
506
                } else {
507
                    sb.append(curChar);
508
                }
509
            }
510
            return sb.toString();
511
        }
512
        
513
        /* Converts the file path from Unix style to VMS style
514
         * @param unixPath Unix file path to convert
515
         * @param isDir true if Unix file path is directory
516
         */
517
        private  String unixPathToOpenVMSPath(String unixPath, boolean isDir) {
518
            if (unixPath.length() == 0)
519
                return "";
520
            
521
            StringTokenizer stoken   = new StringTokenizer(unixPath, "/");
522
            java.util.List tokenList = new LinkedList();
523
            StringBuffer dirPath     = new StringBuffer();
524
            String deviceName        = new String();
525
            String fileName          = new String();
526
            int tokenIndex = 0;
527
            boolean rootExist = false;
528
            boolean relativePath = false;
529
            
530
            // Tokenize the file path
531
            //
532
            while (stoken.hasMoreTokens()) {
533
                String token = stoken.nextToken();
534
                tokenList.add(token);
535
            }
536
            
537
            if (unixPath.charAt(0) == '/') {        //we have a root
538
                rootExist = true;
539
            }
540
            
541
            // If the file path is "/",
542
            // return sys$login:
543
            //
544
            if (tokenList.isEmpty()) {
545
                return ("sys$login:");
546
            }
547
            
548
            //if /dir or /file
549
            //
550
            if ((tokenList.size() == 1) && rootExist) {
551
                if (isDir) {
552
                    return (handleEscape((String)tokenList.get(tokenIndex++)) + ":");
553
                } else {
554
                    deviceName = "sys$login:";
555
                }
556
            }
557
            else if(rootExist) {
558
                deviceName = handleEscape((String)tokenList.get(tokenIndex++)) + ":";
559
            }
560
            
561
            // Construct the VMS style directory tree
562
            // (e.g., dir.dir2.dir3).
563
            //
564
            int endTokenIndex = isDir ? tokenList.size() : tokenList.size() - 1;
565
            for (int i = tokenIndex; i < endTokenIndex; i++) {
566
                String curToken = (String)tokenList.get(i);
567
                if (curToken.equals("..")) {
568
                    dirPath.append("-");
569
                } else if (curToken.equals(".")) {
570
                    if (i == tokenIndex && !rootExist) {
571
                        relativePath = true;
572
                    }
573
                    continue;
574
                } else {
575
                    dirPath.append(handleEscape(curToken));
576
                }
577
                dirPath.append('.');
578
            }
579
            if (dirPath.length() > 0) {         //removes the trailing .
580
                dirPath.deleteCharAt(dirPath.length() - 1);
581
            }
582
            
583
            // Construct the complete VMS file path
584
            //
585
            if (isDir) {
586
                
587
                // Put the file name inside the [...]
588
                //
589
                dirPath.insert(0, '[');
590
                
591
                // If relative path, add "." right after "["
592
                //
593
                if ((deviceName.length() == 0) && (dirPath.length() > 1)) {
594
                    dirPath.insert(1, '.');
595
                }
596
                dirPath.append(']');
597
                return (deviceName + dirPath);
598
            } else {
599
                
600
                // Get the file name.
601
                //
602
                fileName = (String)tokenList.get(tokenList.size()-1);
603
                fileName = handleEscape(fileName);
604
                if (fileName.indexOf('.') < 0) {
605
                    
606
                    // If no dot in the file name, add the dot at the end
607
                    //
608
                    fileName = fileName + ".";
609
                } else {
610
                    
611
                    // Remove the ^ from the last dot, since it is a
612
                    // file extension delimeter
613
                    //
614
                    StringBuffer sb = new StringBuffer(fileName);
615
                    sb.deleteCharAt(fileName.lastIndexOf('^'));
616
                    fileName = sb.toString();
617
                }
618
                
619
                if (dirPath.length() > 0 ) {
620
                    
621
                    // Append the file name after the [...]
622
                    //
623
                    dirPath.insert(0, '[');
624
                    if (relativePath) {
625
                        dirPath.insert(1, '.');
626
                    }
627
                    dirPath.append(']');
628
                } else {
629
                    if (relativePath) {
630
                        dirPath.append("[]");
631
                    }
632
                }
633
                return (deviceName + dirPath + fileName);
634
            }
635
        }
636
        
637
        /* Construct the command file which contains the VMS commands to launch/stop
638
        * the bundled tomcat
639
        * @param command command type flag either to start or stop tomcat
640
        * @param homeDir catalina home directory
641
        * @param baseDir catalina base directory
642
        * @return the command file to execute
643
        */
644
        private File constructVMSArgs(CommandType command, File homeDir, File baseDir) {
645
            File tmpFile = null;
646
            try {
647
                tmpFile = File.createTempFile("nbcmd","tomcat.com", new File(baseDir,"temp"));
648
                tmpFile.deleteOnExit();
649
                String args[] = new String[8];
650
                args[0] = "$@" + unixPathToOpenVMSPath(homeDir.getAbsolutePath() + "/bin/catalina.com", false);
651
                args[1] = "\"" + homeDir.getAbsolutePath() + "\"";
652
                args[2] = "\"" + baseDir.getAbsolutePath() + "\"";
653
                args[3] = "\"" + System.getProperty("jdk.home") + "\"";
654
                args[4] = "\"\"";
655
                args[5] = "\"\"";
656
                args[6] = "\"\"";
657
                args[7] = (command == CommandType.START) ? "\"run\"" : "\"stop\"";
658
                
659
                PrintWriter bw = new PrintWriter(new BufferedWriter(new FileWriter(tmpFile)));
660
                for (int i=0; i<args.length; i++) {
661
                    bw.print(args[i] + " ");
662
                }
663
                bw.print('\n');
664
                bw.close();
665
            } catch (IOException e) {
666
                
667
            }
668
            return tmpFile;
438
        }
669
        }
439
    }
670
    }
440
    
671
    

Return to bug 49420