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 30017
Collapse All | Expand All

(-)NonGuiMain.java (-12 / +161 lines)
Lines 13-18 Link Here
13
13
14
package org.netbeans.core;
14
package org.netbeans.core;
15
15
16
import java.awt.Component;
17
import java.awt.TextComponent;
18
import javax.swing.text.JTextComponent;
19
16
import java.io.*;
20
import java.io.*;
17
import java.net.URL;
21
import java.net.URL;
18
import java.util.*;
22
import java.util.*;
Lines 51-56 Link Here
51
    public static boolean load = true;
55
    public static boolean load = true;
52
    /** Interactive mode means reading input as individual lines.*/
56
    /** Interactive mode means reading input as individual lines.*/
53
    public static boolean interactiveMode = true;
57
    public static boolean interactiveMode = true;
58
    /** whether we should bring up the GUI windows before running scripts */
59
    public static boolean startGui = false;	
54
    
60
    
55
    /** PROMPT used for prompting the user.*/
61
    /** PROMPT used for prompting the user.*/
56
    public static final String PROMPT = "[localhost]";
62
    public static final String PROMPT = "[localhost]";
Lines 75-80 Link Here
75
    /** Status line is not shown during initialization before the
81
    /** Status line is not shown during initialization before the
76
     * actual script is run.*/
82
     * actual script is run.*/
77
    private static boolean showStatusLine = false;
83
    private static boolean showStatusLine = false;
84
    private static boolean showNotifyText = true;
78
    
85
    
79
        /** Test method to check whether some level of interactivity is enabled.
86
        /** Test method to check whether some level of interactivity is enabled.
80
         * @param il mask composed of the constants of IL_XXXX
87
         * @param il mask composed of the constants of IL_XXXX
Lines 97-104 Link Here
97
    }
104
    }
98
    
105
    
99
    /** Prints help to the System.out. */
106
    /** Prints help to the System.out. */
100
    public static void showHelp() {
107
    public static void showHelp2() {
101
        NonGui.showHelp();
108
        showHelp();
102
        System.out.println(getStringX("CTL_INPUT_option"));
109
        System.out.println(getStringX("CTL_INPUT_option"));
103
        System.out.println(getStringX("CTL_OUTPUT_option"));
110
        System.out.println(getStringX("CTL_OUTPUT_option"));
104
        System.out.println(getStringX("CTL_INFO_option"));
111
        System.out.println(getStringX("CTL_INFO_option"));
Lines 129-134 Link Here
129
                    showInfo = true;
136
                    showInfo = true;
130
                    argNo++;
137
                    argNo++;
131
                }
138
                }
139
                else if (argv.equals("gui")) {  // NOI18N
140
                    startGui = true;
141
                    argNo++;
142
                }
132
                else if (argv.startsWith("t"))	// NOI18N
143
                else if (argv.startsWith("t"))	// NOI18N
133
                {
144
                {
134
                    // There is an optional space
145
                    // There is an optional space
Lines 282-294 Link Here
282
                    
293
                    
283
                    argNo++;
294
                    argNo++;
284
                    
295
                    
285
                    // load property file TODO: should we implement this???
296
                    loadPropertyFile(fname);
286
                    // Fjscript.loadPropertyFile(fname);
287
                }
297
                }
288
                else if (argv.equals("e"))	// NOI18N
298
                else if (argv.equals("e"))	// NOI18N
289
                {
299
                {
290
                    // ignore this. It means "load environment variables"
300
                    // load environment variables from the file
291
                    // and has been handled by the script that loads us.
301
		    // specified by netbeans.osenv
302
                    //
303
                    String  fname;
304
                    fname = System.getProperty("netbeans.osenv");    //NOI18N
305
		    if (fname != null)
306
			loadPropertyFile(fname);
292
                    argNo++;
307
                    argNo++;
293
                }
308
                }
294
                else if (argv.equals("noload")) 	// NOI18N
309
                else if (argv.equals("noload")) 	// NOI18N
Lines 330-336 Link Here
330
                tmpArgs[i] = (String) newArgs.get(i);
345
                tmpArgs[i] = (String) newArgs.get(i);
331
            }
346
            }
332
        }
347
        }
333
        NonGui.parseCommandLine(tmpArgs);
348
	// if we are starting the GUI (e.g. for running Jemmy tests),
349
	// pass the args to Main.main, rather than NonGui.main.
350
	//
351
	if (startGui)
352
	    startGui(tmpArgs);
353
	else
354
	    NonGui.parseCommandLine(tmpArgs);
334
        
355
        
335
        if (showInfo) {
356
        if (showInfo) {
336
            info();
357
            info();
Lines 338-343 Link Here
338
        return CMD_OK;
359
        return CMD_OK;
339
    }
360
    }
340
    
361
    
362
    /** Starts the GUI TopManager */
363
    static void startGui( String [] args ) {
364
	//
365
        // set the TopManager implementation to the GUI main
366
	// 
367
        System.getProperties().put (
368
            "org.openide.TopManager", // NOI18N
369
            "org.netbeans.core.Main" // NOI18N
370
            );
371
	//
372
	// set the property to skip the Welcome screen & auto-update checks.
373
	// These are modal & will stop batch scripts from running.
374
	// 
375
	System.getProperties().put("netbeans.full.hack", "true");  // NOI18N
376
	    
377
        org.netbeans.core.Main.main(args);	
378
    }
379
380
341
    /** Parses command line arguments and calls runInterpreter. */
381
    /** Parses command line arguments and calls runInterpreter. */
342
    public static void main( String [] args ) {
382
    public static void main( String [] args ) {
343
        final String _methodName = "main";
383
        final String _methodName = "main";
Lines 353-359 Link Here
353
        System.getProperties ().put ("netbeans.design.time", "true"); // NOI18N
393
        System.getProperties ().put ("netbeans.design.time", "true"); // NOI18N
354
        
394
        
355
        if (processArgs(args) == CMD_FAIL) {
395
        if (processArgs(args) == CMD_FAIL) {
356
            showHelp();
396
            showHelp2();
357
            System.exit(0);	// NonGui.doExit(0);
397
            System.exit(0);	// NonGui.doExit(0);
358
        }
398
        }
359
        
399
        
Lines 377-384 Link Here
377
            }
417
            }
378
            
418
            
379
            showStatusLine = true;
419
            showStatusLine = true;
420
            showNotifyText = true;
380
            
421
            
381
            runInterpreter(TopManager.getDefault().getIO(TAB_NAME).getIn());
422
            runInterpreter(new InputStreamReader(in));
382
        }
423
        }
383
        catch (Exception e  /* e.g. bsh.EvalError */ ) {
424
        catch (Exception e  /* e.g. bsh.EvalError */ ) {
384
            printException(_methodName, e);
425
            printException(_methodName, e);
Lines 424-430 Link Here
424
    
465
    
425
    /** Calls TopManager.getDefault().exit(); */
466
    /** Calls TopManager.getDefault().exit(); */
426
    public static void myExit(int status) {
467
    public static void myExit(int status) {
427
        if (load) {
468
	if (TopManager.isInitialized()) {
469
	    
428
            TopManager.getDefault().exit();
470
            TopManager.getDefault().exit();
429
        }
471
        }
430
        System.exit(status);
472
        System.exit(status);
Lines 472-480 Link Here
472
        return inout;
514
        return inout;
473
    }
515
    }
474
    
516
    
517
    public OutputWriter getStdOut () {
518
        return getIO("").getOut();	// NOI18N
519
    }
520
475
    /** Prints the notification to the out.*/
521
    /** Prints the notification to the out.*/
476
    public Object notify(NotifyDescriptor n) {
522
    public Object notify(NotifyDescriptor n) {
477
        out.println("NOTIFICATION: " + n.getMessage());
523
	if (!showNotifyText)
524
	    return NotifyDescriptor.CLOSED_OPTION;
525
526
	Object msg = n.getMessage();
527
	String display = null;
528
529
	if (msg instanceof TextComponent) {
530
	    display = ((TextComponent)msg).getText();
531
	} else if (msg instanceof JTextComponent) {
532
	    display = ((JTextComponent)msg).getText();
533
	} else if (msg instanceof Component) {
534
	    try {
535
		Method getText = msg.getClass().getMethod("getText", null);
536
		Object rval;
537
538
		rval = getText.invoke(msg, null);
539
		if (rval instanceof String) {
540
		    display = (String) rval;
541
		} else if (rval instanceof String[]) {
542
		    String[] arr = (String[])rval;
543
544
		    //
545
		    // The EJB code returns this.
546
		    //
547
		    out.println("NOTIFICATION:");
548
		    for (int i = 0; i < arr.length; i++) {
549
			out.println("\t" + arr[i]);
550
		    }
551
		    return NotifyDescriptor.CLOSED_OPTION;
552
		}
553
	    } catch (Throwable t) {
554
		display = msg.toString();
555
	    }
556
	} else {
557
	    display = msg.toString();
558
	}
559
        out.println("NOTIFICATION: " + display);
478
        return NotifyDescriptor.CLOSED_OPTION;
560
        return NotifyDescriptor.CLOSED_OPTION;
479
    }
561
    }
480
    
562
    
Lines 484-489 Link Here
484
            out.println("STATUS LINE : " + text);
566
            out.println("STATUS LINE : " + text);
485
    }
567
    }
486
    
568
    
569
    /** Controls display of the status line text.*/
570
    public static boolean showStatusLine(boolean val) {
571
        boolean oldVal = showStatusLine;
572
        showStatusLine = val;
573
        return oldVal;
574
    }
575
576
    /** Controls display of the notify text.*/
577
    public static boolean showNotifyText(boolean val) {
578
        boolean oldVal = showNotifyText;
579
        showNotifyText = val;
580
        return oldVal;
581
    }
582
487
    /** Browse a document over HTTP.
583
    /** Browse a document over HTTP.
488
     * @param url URL of WWW document to be shown
584
     * @param url URL of WWW document to be shown
489
     */
585
     */
Lines 510-523 Link Here
510
        return compEngine;
606
        return compEngine;
511
    }
607
    }
512
    
608
    
609
    public static void setCompileSync(boolean sync) {
610
        compileSync = sync;
611
    }
612
613
    static boolean compileSync = true;
614
513
    /** */
615
    /** */
514
    private class NonGuiCompilationEngine extends CompilationEngineImpl {
616
    private class NonGuiCompilationEngine extends CompilationEngineImpl {
515
        protected CompilerTask start(CompilerJob job) {
617
        protected CompilerTask start(CompilerJob job) {
516
            CompilerTask rval;
618
            CompilerTask rval;
517
            
619
            
518
            rval = super.start(job);
620
            rval = super.start(job);
519
            rval.waitFinished();
621
	    if (compileSync) {
622
		rval.waitFinished();
623
	    }
520
            return rval;
624
            return rval;
521
        }
625
        }
626
    }
627
628
    public static int loadPropertyFile (String fileName) {
629
        final String methodName = "NonGuiMain.loadPropertyFile"; // NOI18N
630
631
	// If we want to keep the properties loaded here
632
	// SEPARATE from the system properties, we could
633
	// create our own Property object here OR use the
634
	// one in scripting/.../NavigationSupport. (Or we
635
	// could have the one in NavigationSupport use one
636
	// from here instead of its own, in order to share
637
	// the loaded properties & make them available for
638
	// NavigationSupport.expandVars().)
639
	//
640
641
        Exception exc = null;
642
643
        if (fileName != null) {
644
            try {
645
                FileInputStream fis = null;
646
                fis = new FileInputStream(fileName);
647
                System.getProperties().load(fis);
648
            }
649
            catch (FileNotFoundException e) {
650
                exc = e;
651
                out.println(
652
                    getString("MSG_NoPropFile", fileName));
653
                printException(methodName, e);
654
            }
655
            catch (IOException e) {
656
                exc = e;
657
                out.println(
658
                    getString("MSG_IOPropFile", fileName));
659
                printException(methodName, e);
660
            }
661
            catch (IllegalArgumentException e) {
662
                exc = e;
663
                out.println(
664
                    getString("MSG_ErrPropFile", fileName));
665
                printException(methodName, e);
666
            }
667
            if (exc != null)
668
                return CMD_FAIL;
669
        }
670
        return CMD_OK;
522
    }
671
    }
523
}
672
}

Return to bug 30017