Index: NonGuiMain.java =================================================================== RCS file: /cvs/core/src/org/netbeans/core/NonGuiMain.java,v retrieving revision 1.3 diff -u -r1.3 NonGuiMain.java --- NonGuiMain.java 2000/11/22 10:34:10 1.3 +++ NonGuiMain.java 2001/03/02 18:34:43 @@ -13,6 +13,10 @@ package org.netbeans.core; +import java.awt.Component; +import java.awt.TextComponent; +import javax.swing.text.JTextComponent; + import java.io.*; import java.net.URL; import java.util.*; @@ -51,6 +55,8 @@ public static boolean load = true; /** Interactive mode means reading input as individual lines.*/ public static boolean interactiveMode = true; + /** whether we should bring up the GUI windows before running scripts */ + public static boolean startGui = false; /** PROMPT used for prompting the user.*/ public static final String PROMPT = "[localhost]"; @@ -75,6 +81,7 @@ /** Status line is not shown during initialization before the * actual script is run.*/ private static boolean showStatusLine = false; + private static boolean showNotifyText = true; /** Test method to check whether some level of interactivity is enabled. * @param il mask composed of the constants of IL_XXXX @@ -97,8 +104,8 @@ } /** Prints help to the System.out. */ - public static void showHelp() { - NonGui.showHelp(); + public static void showHelp2() { + showHelp(); System.out.println(getStringX("CTL_INPUT_option")); System.out.println(getStringX("CTL_OUTPUT_option")); System.out.println(getStringX("CTL_INFO_option")); @@ -129,6 +136,10 @@ showInfo = true; argNo++; } + else if (argv.equals("gui")) { // NOI18N + startGui = true; + argNo++; + } else if (argv.startsWith("t")) // NOI18N { // There is an optional space @@ -282,13 +293,17 @@ argNo++; - // load property file TODO: should we implement this??? - // Fjscript.loadPropertyFile(fname); + loadPropertyFile(fname); } else if (argv.equals("e")) // NOI18N { - // ignore this. It means "load environment variables" - // and has been handled by the script that loads us. + // load environment variables from the file + // specified by netbeans.osenv + // + String fname; + fname = System.getProperty("netbeans.osenv"); //NOI18N + if (fname != null) + loadPropertyFile(fname); argNo++; } else if (argv.equals("noload")) // NOI18N @@ -330,7 +345,13 @@ tmpArgs[i] = (String) newArgs.get(i); } } - NonGui.parseCommandLine(tmpArgs); + // if we are starting the GUI (e.g. for running Jemmy tests), + // pass the args to Main.main, rather than NonGui.main. + // + if (startGui) + startGui(tmpArgs); + else + NonGui.parseCommandLine(tmpArgs); if (showInfo) { info(); @@ -338,6 +359,25 @@ return CMD_OK; } + /** Starts the GUI TopManager */ + static void startGui( String [] args ) { + // + // set the TopManager implementation to the GUI main + // + System.getProperties().put ( + "org.openide.TopManager", // NOI18N + "org.netbeans.core.Main" // NOI18N + ); + // + // set the property to skip the Welcome screen & auto-update checks. + // These are modal & will stop batch scripts from running. + // + System.getProperties().put("netbeans.full.hack", "true"); // NOI18N + + org.netbeans.core.Main.main(args); + } + + /** Parses command line arguments and calls runInterpreter. */ public static void main( String [] args ) { final String _methodName = "main"; @@ -353,7 +393,7 @@ System.getProperties ().put ("netbeans.design.time", "true"); // NOI18N if (processArgs(args) == CMD_FAIL) { - showHelp(); + showHelp2(); System.exit(0); // NonGui.doExit(0); } @@ -377,8 +417,9 @@ } showStatusLine = true; + showNotifyText = true; - runInterpreter(TopManager.getDefault().getIO(TAB_NAME).getIn()); + runInterpreter(new InputStreamReader(in)); } catch (Exception e /* e.g. bsh.EvalError */ ) { printException(_methodName, e); @@ -424,7 +465,8 @@ /** Calls TopManager.getDefault().exit(); */ public static void myExit(int status) { - if (load) { + if (TopManager.isInitialized()) { + TopManager.getDefault().exit(); } System.exit(status); @@ -472,9 +514,49 @@ return inout; } + public OutputWriter getStdOut () { + return getIO("").getOut(); // NOI18N + } + /** Prints the notification to the out.*/ public Object notify(NotifyDescriptor n) { - out.println("NOTIFICATION: " + n.getMessage()); + if (!showNotifyText) + return NotifyDescriptor.CLOSED_OPTION; + + Object msg = n.getMessage(); + String display = null; + + if (msg instanceof TextComponent) { + display = ((TextComponent)msg).getText(); + } else if (msg instanceof JTextComponent) { + display = ((JTextComponent)msg).getText(); + } else if (msg instanceof Component) { + try { + Method getText = msg.getClass().getMethod("getText", null); + Object rval; + + rval = getText.invoke(msg, null); + if (rval instanceof String) { + display = (String) rval; + } else if (rval instanceof String[]) { + String[] arr = (String[])rval; + + // + // The EJB code returns this. + // + out.println("NOTIFICATION:"); + for (int i = 0; i < arr.length; i++) { + out.println("\t" + arr[i]); + } + return NotifyDescriptor.CLOSED_OPTION; + } + } catch (Throwable t) { + display = msg.toString(); + } + } else { + display = msg.toString(); + } + out.println("NOTIFICATION: " + display); return NotifyDescriptor.CLOSED_OPTION; } @@ -484,6 +566,20 @@ out.println("STATUS LINE : " + text); } + /** Controls display of the status line text.*/ + public static boolean showStatusLine(boolean val) { + boolean oldVal = showStatusLine; + showStatusLine = val; + return oldVal; + } + + /** Controls display of the notify text.*/ + public static boolean showNotifyText(boolean val) { + boolean oldVal = showNotifyText; + showNotifyText = val; + return oldVal; + } + /** Browse a document over HTTP. * @param url URL of WWW document to be shown */ @@ -510,14 +606,67 @@ return compEngine; } + public static void setCompileSync(boolean sync) { + compileSync = sync; + } + + static boolean compileSync = true; + /** */ private class NonGuiCompilationEngine extends CompilationEngineImpl { protected CompilerTask start(CompilerJob job) { CompilerTask rval; rval = super.start(job); - rval.waitFinished(); + if (compileSync) { + rval.waitFinished(); + } return rval; } + } + + public static int loadPropertyFile (String fileName) { + final String methodName = "NonGuiMain.loadPropertyFile"; // NOI18N + + // If we want to keep the properties loaded here + // SEPARATE from the system properties, we could + // create our own Property object here OR use the + // one in scripting/.../NavigationSupport. (Or we + // could have the one in NavigationSupport use one + // from here instead of its own, in order to share + // the loaded properties & make them available for + // NavigationSupport.expandVars().) + // + + Exception exc = null; + + if (fileName != null) { + try { + FileInputStream fis = null; + fis = new FileInputStream(fileName); + System.getProperties().load(fis); + } + catch (FileNotFoundException e) { + exc = e; + out.println( + getString("MSG_NoPropFile", fileName)); + printException(methodName, e); + } + catch (IOException e) { + exc = e; + out.println( + getString("MSG_IOPropFile", fileName)); + printException(methodName, e); + } + catch (IllegalArgumentException e) { + exc = e; + out.println( + getString("MSG_ErrPropFile", fileName)); + printException(methodName, e); + } + if (exc != null) + return CMD_FAIL; + } + return CMD_OK; } }