Index: core/bootstrap/src/org/netbeans/CLIHandler.java =================================================================== RCS file: /cvs/core/bootstrap/src/org/netbeans/CLIHandler.java,v retrieving revision 1.10 diff -u -r1.10 CLIHandler.java --- core/bootstrap/src/org/netbeans/CLIHandler.java 12 Dec 2003 16:39:04 -0000 1.10 +++ core/bootstrap/src/org/netbeans/CLIHandler.java 7 Jan 2004 12:49:04 -0000 @@ -86,9 +86,7 @@ protected abstract int cli(Args args); private static void showHelp(PrintWriter w, List handlers) { - w.println("-?"); - w.println("--help"); - w.println(" Show this help information."); +// w.println(" -? or --help Show this help information."); Iterator it = handlers.iterator(); while (it.hasNext()) { ((CLIHandler)it.next()).usage(w); @@ -128,16 +126,14 @@ private static int notifyHandlers(Args args, List handlers, int when, boolean failOnUnknownOptions, boolean consume) { try { //System.err.println("notifyHandlers: handlers=" + handlers + " when=" + when + " args=" + Arrays.asList(args.getArguments())); - if (failOnUnknownOptions) { - String[] argv = args.getArguments(); - for (int i = 0; i < argv.length; i++) { - assert argv[i] != null; - if (argv[i].equals("-?") || argv[i].equals("--help") || argv[i].equals ("-help")) { // NOI18N - PrintWriter w = new PrintWriter(args.getOutputStream()); - showHelp(w, handlers); - w.flush(); - return 2; - } + String[] argv = args.getArguments(); + for (int i = 0; i < argv.length; i++) { + assert argv[i] != null; + if (argv[i].equals("-?") || argv[i].equals("--help") || argv[i].equals ("-help")) { // NOI18N + PrintWriter w = new PrintWriter(args.getOutputStream()); + showHelp(w, handlers); + w.flush(); + return 2; } } int r = 0; @@ -153,7 +149,7 @@ } } if (failOnUnknownOptions) { - String[] argv = args.getArguments(); + argv = args.getArguments(); for (int i = 0; i < argv.length; i++) { if (argv[i] != null) { // Unhandled option. @@ -240,8 +236,8 @@ * @param cleanLockFile removes lock file if it appears to be dead * @return the file to be used as lock file or null parsing of args failed */ - static Status initialize(String[] args, ClassLoader loader, boolean failOnUnknownOptions, boolean cleanLockFile) { - return initialize(new Args(args, System.in, System.err, System.getProperty ("user.dir")), (Integer)null, allCLIs(loader), failOnUnknownOptions, cleanLockFile); + static Status initialize(String[] args, InputStream is, OutputStream os, ClassLoader loader, boolean failOnUnknownOptions, boolean cleanLockFile) { + return initialize(new Args(args, is, os, System.getProperty ("user.dir")), (Integer)null, allCLIs(loader), failOnUnknownOptions, cleanLockFile); } /** Index: core/bootstrap/src/org/netbeans/Main.java =================================================================== RCS file: /cvs/core/bootstrap/src/org/netbeans/Main.java,v retrieving revision 1.15 diff -u -r1.15 Main.java --- core/bootstrap/src/org/netbeans/Main.java 12 Dec 2003 16:39:04 -0000 1.15 +++ core/bootstrap/src/org/netbeans/Main.java 7 Jan 2004 12:49:04 -0000 @@ -29,6 +29,48 @@ * @throws Exception for lots of reasons */ public static void main (String args[]) throws Exception { + java.lang.reflect.Method[] m = new java.lang.reflect.Method[1]; + int res = execute (args, System.in, System.err, m); + if (res == -1) { + // Connected to another running NB instance and succeeded in making a call. + System.exit(0); + } else if (res != 0) { + // Some CLIHandler refused the invocation + System.exit(res); + } + + m[0].invoke (null, new Object[] { args }); + } + + /** Returns string describing usage of the system. Does that by talking to + * all registered handlers and asking them to show their usage. + * + * @return the usage string for the system + */ + public static String usage () throws Exception { + java.io.ByteArrayOutputStream os = new java.io.ByteArrayOutputStream (); + + String[] newArgs = { "--help" }; + + int res = execute (newArgs, System.in, os, null); + return new String (os.toByteArray ()); + } + + /** Constructs the correct ClassLoader, finds main method to execute + * and invokes all registered CLIHandlers. + * + * @param args the arguments to pass to the handlers + * @param reader the input stream reader for the handlers + * @param writer the output stream for the handlers + * @param methodToCall null or array with one item that will be set to + * a method that shall be executed as the main application + */ + private static int execute ( + String[] args, + java.io.InputStream reader, + java.io.OutputStream writer, + java.lang.reflect.Method[] methodToCall + ) throws Exception { ArrayList list = new ArrayList (); String home = System.getProperty ("netbeans.home"); // NOI18N @@ -98,7 +140,7 @@ // CLIHandler.Status result; - result = CLIHandler.initialize(args, loader, true, false); + result = CLIHandler.initialize(args, reader, writer, loader, true, false); if (result.getExitCode () == CLIHandler.Status.CANNOT_CONNECT) { int value = javax.swing.JOptionPane.showConfirmDialog ( null, @@ -108,20 +150,16 @@ javax.swing.JOptionPane.WARNING_MESSAGE ); if (value == javax.swing.JOptionPane.OK_OPTION) { - result = CLIHandler.initialize(args, loader, true, true); + result = CLIHandler.initialize(args, reader, writer, loader, true, true); } } - int res = result.getExitCode(); - if (res == -1) { - // Connected to another running NB instance and succeeded in making a call. - System.exit(0); - } else if (res != 0) { - // Some CLIHandler refused the invocation - System.exit(res); + + if (methodToCall != null) { + methodToCall[0] = m; } - m.invoke (null, new Object[] { args }); + return result.getExitCode (); } /** Index: core/release/bin/runide.sh =================================================================== RCS file: /cvs/core/release/bin/runide.sh,v retrieving revision 1.50 diff -u -r1.50 runide.sh --- core/release/bin/runide.sh 11 Sep 2003 17:46:50 -0000 1.50 +++ core/release/bin/runide.sh 7 Jan 2004 12:49:05 -0000 @@ -95,39 +95,23 @@ while [ $# -gt 0 ] ; do # echo "Processing arg: '$1'" case "$1" in - -h|-help) cat >&2 <&2 < - path to JDK (could also be just JRE but some modules may not work!) - -userdir - specifies user settings directory (${userdir} by default) - -J - passes to JVM -Classpath options (normally you should NOT use these except to support -ui): - -cp:p - prepends to IDE's classpath - -cp:a - appends to IDE's classpath - -All other options and arguments are passed to the IDE, so try -? for more. -Any options found in $HOME/ide.cfg or else $idehome/bin/ide.cfg -are treated as defaults (may be overridden). -See documentation for details. +General options: + --help show this help + --jdkhome path to JDK (could also be just JRE but some modules may not work!) + -J passes to JVM +Classpath options: + --cp:p prepends to classpath + --cp:a appends to classpath EOF -exit 2 -;; - -jdkhome) shift; if [ $# -gt 0 ] ; then jdkhome=$1; fi;; - -userdir) shift; if [ $# -gt 0 ] ; then userdir=$1; fi;; + # go on and print IDE options as well + args="$args --help" ;; + -jdkhome|--jdkhome) shift; if [ $# -gt 0 ] ; then jdkhome=$1; fi;; # For compatibility only: -mainclass) shift; if [ $# -gt 0 ] ; then ide_class_option=-Dnetbeans.mainclass=$1; fi;; - -cp|-cp:a) + -cp|-cp:a|--cp|--cp:a) shift; if [ $# -gt 0 ] ; then if [ ! -z "$postfixcp" ] ; then postfixcp="$postfixcp:" ; fi @@ -135,7 +119,7 @@ fi ;; - -cp:p) + -cp:p|--cp:p) shift; if [ $# -gt 0 ] ; then if [ ! -z "$prefixcp" ] ; then prefixcp="$prefixcp:" ; fi @@ -174,14 +158,14 @@ if [ -z "$jdkhome" ] ; then echo "Cannot find JDK. Please set the JDK_HOME environment variable to point" >&2 - echo "to your JDK installation directory, or use the -jdkhome switch" >&2 + echo "to your JDK installation directory, or use the --jdkhome switch" >&2 exit 2 fi if [ ! -x "${jdkhome}/bin/java" ] ; then echo "Cannot find JDK at ${jdkhome}. Please set the JDK_HOME" >&2 echo "environment variable to point to your JDK installation directory," >&2 - echo "or use the -jdkhome switch" >&2 + echo "or use the --jdkhome switch" >&2 exit 2 fi @@ -190,7 +174,7 @@ # if [ ! -z "$userdir" ] ; then - jargs="-Dnetbeans.user=\"${userdir}\" $jargs" + args="--userdir \"${userdir}\" $args" fi # Index: core/src/org/netbeans/core/Bundle.properties =================================================================== RCS file: /cvs/core/src/org/netbeans/core/Bundle.properties,v retrieving revision 1.375 diff -u -r1.375 Bundle.properties --- core/src/org/netbeans/core/Bundle.properties 20 Nov 2003 10:37:33 -0000 1.375 +++ core/src/org/netbeans/core/Bundle.properties 7 Jan 2004 12:49:16 -0000 @@ -150,21 +150,21 @@ # NonGui TEXT_help=\ Command-line options:\n\ - \ -? show this help\n\ - \ -h (or -help) show launcher-specific options\n\ - \ -ui use given UI class as the IDE's Look & Feel\n\ - \ -fontsize use given number as the base font size of the\n\ + \ --ui use given UI class as the IDE's Look & Feel\n\ + \ --fontsize use given number as the base font size of the\n\ \ IDE user interface, in points (11 default)\n\ \ (but see http://ui.netbeans.org/docs/ui/themes/themes.html)\n\ - \ -locale use specified locale\n\ - Rarer options (definitely not supported!):\n\ - \ -branding use specified branding (- for default)\n\ - \ -nologging do not create the log file\n\ - \ -nosplash do not show the splash screen\n\ - \ -nogui just start up internals, do not show GUI + \ --locale use specified locale\n\ + \ --userdir user settings directory (${userdir} by default)\n\ + \ --branding use specified branding (- for default) +# +# \ --nologging do not create the log file\n\ +# \ --nosplash do not show the splash screen\n\ +# \ --nogui just start up internals, do not show GUI # error messages ERR_UIExpected=UI class name expected, using default UI... +ERR_UserDirExpected=Directory expected after --userdir switch ERR_UINotFound=UI class not found, using default UI... ERR_UIError=An error occured when setting the specified UI, using default UI ... ERR_FontSizeExpected=Font size expected, using default font size... Index: core/src/org/netbeans/core/CLIOptions.java =================================================================== RCS file: /cvs/core/src/org/netbeans/core/CLIOptions.java,v retrieving revision 1.3 diff -u -r1.3 CLIOptions.java --- core/src/org/netbeans/core/CLIOptions.java 7 Oct 2003 20:30:42 -0000 1.3 +++ core/src/org/netbeans/core/CLIOptions.java 7 Jan 2004 12:49:16 -0000 @@ -46,6 +46,17 @@ return cli(arguments.getArguments()); } + private static boolean isOption (String value, String optionName) { + if (value == null) return false; + + if (value.startsWith ("--")) { + return value.substring (2).equals (optionName); + } else if (value.startsWith ("-")) { + return value.substring (1).equals (optionName); + } + return false; + } + final int cli(String[] args) { // let's go through the command line for (int i = 0; i < args.length; i++) { @@ -53,15 +64,23 @@ continue; } boolean used = true; - if (args[i].equalsIgnoreCase("-nogui")) { // NOI18N + if (isOption (args[i], "nogui")) { // NOI18N System.getProperties().put("org.openide.TopManager", "org.netbeans.core.NonGui"); // NOI18N - } else if (args[i].equalsIgnoreCase("-nosplash")) { // NOI18N + } else if (isOption (args[i], "nosplash")) { // NOI18N NonGui.noSplash = true; - } else if (args[i].equalsIgnoreCase("-noinfo")) { // NOI18N + } else if (isOption (args[i], "noinfo")) { // NOI18N // obsolete switch, ignore - } else if (args[i].equalsIgnoreCase("-nologging")) { // NOI18N + } else if (isOption (args[i], "nologging")) { // NOI18N NonGui.noLogging = true; - } else if (args[i].equalsIgnoreCase("-ui")) { // NOI18N + } else if (isOption (args[i], "userdir")) { // NOI18N + args[i] = null; + try { + System.setProperty ("netbeans.user", args[++i]); + } catch(ArrayIndexOutOfBoundsException e) { + System.err.println(NonGui.getString("ERR_UserDirExpected")); + return 2; + } + } else if (isOption (args[i], "ui")) { // NOI18N args[i] = null; try { NonGui.uiClass = Class.forName(args[++i]); @@ -72,7 +91,7 @@ System.err.println(NonGui.getString("ERR_UINotFound")); return 1; } - } else if (args[i].equalsIgnoreCase("-fontsize")) { // NOI18N + } else if (isOption (args[i], "fontsize")) { // NOI18N args[i] = null; try { NonGui.uiFontSize = Integer.parseInt(args[++i]); @@ -83,7 +102,7 @@ System.err.println(NonGui.getString("ERR_BadFontSize")); return 1; } - } else if (args[i].equalsIgnoreCase("-locale")) { // NOI18N + } else if (isOption (args[i], "locale")) { // NOI18N args[i] = null; String localeParam = args[++i]; String language; @@ -103,7 +122,7 @@ country = localeParam.substring(index1+1); } Locale.setDefault(new Locale(language, country, variant)); - } else if (args[i].equalsIgnoreCase("-branding")) { // NOI18N + } else if (isOption (args[i], "branding")) { // NOI18N args[i] = null; String branding = args[++i]; if (branding.equals("-")) branding = null; // NOI18N Index: utilities/clisrc/org/netbeans/modules/openfile/cli/Handler.java =================================================================== RCS file: /cvs/utilities/clisrc/org/netbeans/modules/openfile/cli/Handler.java,v retrieving revision 1.3 diff -u -r1.3 Handler.java --- utilities/clisrc/org/netbeans/modules/openfile/cli/Handler.java 18 Sep 2003 16:28:27 -0000 1.3 +++ utilities/clisrc/org/netbeans/modules/openfile/cli/Handler.java 7 Jan 2004 12:51:42 -0000 @@ -35,80 +35,67 @@ return (Callback)Lookup.getDefault().lookup(Callback.class); } + private File findFile (File curDir, String name) { + File f = new File(name); + if (!f.isAbsolute()) { + f = new File(curDir, name); + } + return f; + } + + private int openFile (File curDir, CLIHandler.Args args, String[] argv, int i) { + String s = argv[i]; + if (s == null) { + log("Missing argument to --open", args); + return 2; + } + argv[i] = null; + Callback c = getCallback(); + if (c == null) { + // XXX I18N required for cmdline? + log("The User Utilities module must be installed for open-file functionality to work.", args); + return 2; + } + int line = -1; + File f = findFile (curDir, s); + if (!f.exists()) { + // Check if it is file:line syntax. + int idx = s.lastIndexOf(':'); // NOI18N + if (idx != -1) { + try { + line = Integer.parseInt(s.substring(idx + 1)) - 1; + f = findFile (curDir, s.substring(0, idx)); + } catch (NumberFormatException e) { + // OK, leave as a filename + } + } + } + // Just make sure it was opened, then exit. + boolean success = c.open(f, line, null); + return success ? 0 : 1; + } + protected int cli(CLIHandler.Args args) { String[] argv = args.getArguments(); File curDir = args.getCurrentDirectory (); - boolean wait = false; for (int i = 0; i < argv.length; i++) { if (argv[i] == null) { continue; } - if (argv[i].equals("-open")) { // NOI18N + if (argv[i].equals("--open") || argv[i].equals("-open")) { // NOI18N argv[i] = null; if (i == argv.length - 1) { - log("Missing argument to -open", args); + log("Missing argument to --open", args); return 2; } - String s = argv[++i]; - if (s == null) { - log("Missing argument to -open", args); - return 2; - } - argv[i] = null; - Callback c = getCallback(); - if (c == null) { - // XXX I18N required for cmdline? - log("The User Utilities module must be installed for open-file functionality to work.", args); - return 2; - } - int line = -1; - File f = new File(s); - if (!f.isAbsolute()) { - f = new File(curDir, s); - } - if (!f.exists()) { - // Check if it is file:line syntax. - int idx = s.lastIndexOf(':'); // NOI18N - if (idx != -1) { - try { - line = Integer.parseInt(s.substring(idx + 1)) - 1; - f = new File(s.substring(0, idx)); - } catch (NumberFormatException e) { - // OK, leave as a filename - } + i++; + while (i < argv.length && !argv[i].startsWith ("-")) { + int res = openFile (curDir, args, argv, i++); + if (res != 0) { + return res; } } - boolean success; - if (wait) { - // Open it, and wait for it to be closed. - Callback.Waiter w = new Callback.Waiter() { - public synchronized void done() { - notify(); - } - }; - success = c.open(f, line, w); - /* XXX uncomment when implemented in module - if (success) { - try { - synchronized (w) { - w.wait(); - } - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - */ - } else { - // Just make sure it was opened, then exit. - success = c.open(f, line, null); - } - if (!success) { - return 1; - } - } else if (argv[i].equals("-wait")) { // NOI18N - argv[i] = null; - wait = true; - } + } } // No problems. return 0; @@ -122,15 +109,9 @@ } protected void usage(PrintWriter w) { - w.println("-open FILE"); - w.println(" Open FILE."); - w.println("-open FILE:LINE"); - w.println(" Open FILE at line LINE (starting from 1)."); - /* XXX uncomment when implemented in module - w.println("-wait -open FILE[:LINE]"); - w.println(" Open FILE (maybe at line LINE), and wait until it is closed before exiting."); - w.println(" (Currently unimplemented.)"); - */ + w.println("Open File Module options:"); + w.println(" --open FILE open FILE."); + w.println(" --open FILE:LINE open FILE at line LINE (starting from 1)."); } }