--- a/core.startup/apichanges.xml Sat Feb 26 19:14:39 2011 +0100 +++ a/core.startup/apichanges.xml Sun Feb 27 09:31:37 2011 +0100 @@ -56,6 +56,22 @@ + + + Exit when CLI options are not processed + + + + + +

+ Applications built on top of NetBeans platform can now exit + immediately when some CLI cannot be processed. See the + usecase. +

+
+ +
netbeans.bootdelegation property --- a/core.startup/arch.xml Sat Feb 26 19:14:39 2011 +0100 +++ a/core.startup/arch.xml Sun Feb 27 09:31:37 2011 +0100 @@ -111,7 +111,32 @@ -->

- XXX no answer for arch-usecases + +

+ + There is a special API that allows applications built on top of NetBeans platform + exit immediately if certain command line options cannot be processed. + +

+

How does it work? + First of all you need to define your own + OptionProcessor + (very likely processing the + always() + option too). When its process method is called, verify + the options and if they are not OK, throw + CommandException. +

+ +

+ To make sure the above also exits the application create a branding + branding/core/core.jar/org/netbeans/core/startup/Bundle.properties + and put there following line ON_CLI_ERROR=exit. This will + tell the system to exit in response to + CommandException. +

+ +

--- a/core.startup/manifest.mf Sat Feb 26 19:14:39 2011 +0100 +++ a/core.startup/manifest.mf Sun Feb 27 09:31:37 2011 +0100 @@ -3,5 +3,5 @@ OpenIDE-Module-Localizing-Bundle: org/netbeans/core/startup/Bundle.properties OpenIDE-Module-Layer: org/netbeans/core/startup/layer.xml OpenIDE-Module-Provides: org.openide.modules.InstalledFileLocator -OpenIDE-Module-Specification-Version: 1.29 +OpenIDE-Module-Specification-Version: 1.30 --- a/core.startup/nbproject/project.xml Sat Feb 26 19:14:39 2011 +0100 +++ a/core.startup/nbproject/project.xml Sun Feb 27 09:31:37 2011 +0100 @@ -55,7 +55,7 @@ 1 - 2.32 + 2.40 --- a/core.startup/src/org/netbeans/core/startup/Bundle.properties Sat Feb 26 19:14:39 2011 +0100 +++ a/core.startup/src/org/netbeans/core/startup/Bundle.properties Sun Feb 27 09:31:37 2011 +0100 @@ -97,6 +97,9 @@ SplashProgressBarEdgeColor=0xC5646F #NOI18N SplashProgressBarCornerColor=0xB4A2B5 +#NOI18N +# acceptable values: "warn", "exit" +ON_CLI_ERROR=warn ################### --- a/core.startup/src/org/netbeans/core/startup/Main.java Sat Feb 26 19:14:39 2011 +0100 +++ a/core.startup/src/org/netbeans/core/startup/Main.java Sun Feb 27 09:31:37 2011 +0100 @@ -311,7 +311,8 @@ CoreBridge.getDefault().registerPropertyEditors(); StartLog.logProgress ("PropertyEditors registered"); // NOI18N - org.netbeans.Main.finishInitialization(); + boolean exit = "exit".equals(NbBundle.getMessage(Main.class, "ON_CLI_ERROR")); // NOI18N + org.netbeans.Main.finishInitialization(exit); StartLog.logProgress("Ran any delayed command-line options"); // NOI18N for (RunLevel level : Lookup.getDefault().lookupAll(RunLevel.class)) { --- a/o.n.bootstrap/manifest.mf Sat Feb 26 19:14:39 2011 +0100 +++ a/o.n.bootstrap/manifest.mf Sun Feb 27 09:31:37 2011 +0100 @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.bootstrap/1 -OpenIDE-Module-Specification-Version: 2.39 +OpenIDE-Module-Specification-Version: 2.40 OpenIDE-Module-Localizing-Bundle: org/netbeans/Bundle.properties OpenIDE-Module-Recommends: org.netbeans.NetigsoFramework --- a/o.n.bootstrap/src/org/netbeans/Main.java Sat Feb 26 19:14:39 2011 +0100 +++ a/o.n.bootstrap/src/org/netbeans/Main.java Sun Feb 27 09:31:37 2011 +0100 @@ -84,6 +84,15 @@ * delayed command-line options like -open FILE. */ public static void finishInitialization() { - MainImpl.finishInitialization(); + finishInitialization(false); + } + /** + * Call when the system is up and running, to complete handling of + * delayed command-line options like -open FILE. + * @param exit true, if the system shall exit on error + * @since 2.40 + */ + public static void finishInitialization(boolean exit) { + MainImpl.finishInitialization(exit); } } --- a/o.n.bootstrap/src/org/netbeans/MainImpl.java Sat Feb 26 19:14:39 2011 +0100 +++ a/o.n.bootstrap/src/org/netbeans/MainImpl.java Sun Feb 27 09:31:37 2011 +0100 @@ -67,6 +67,7 @@ import java.util.StringTokenizer; import java.util.concurrent.atomic.AtomicReference; import org.openide.util.Lookup; +import org.openide.util.NbBundle; import org.openide.util.lookup.Lookups; /** Bootstrap main class. @@ -225,12 +226,15 @@ * Call when the system is up and running, to complete handling of * delayed command-line options like -open FILE. */ - public static void finishInitialization() { + public static void finishInitialization(boolean exit) { int r = CLIHandler.finishInitialization (false); if (r != 0) { - // Not much to do about it. - System.err.println ("Post-initialization command-line options could not be run."); // NOI18N - //System.err.println("r=" + r + " args=" + java.util.Arrays.asList(args.getArguments())); + if (exit) { + TopSecurityManager.exit(r); + } else { + // Not much to do about it. + System.err.println ("Post-initialization command-line options could not be run."); // NOI18N + } } } --- a/sendopts/src/org/netbeans/modules/sendopts/Bundle.properties Sat Feb 26 19:14:39 2011 +0100 +++ a/sendopts/src/org/netbeans/modules/sendopts/Bundle.properties Sun Feb 27 09:31:37 2011 +0100 @@ -49,3 +49,4 @@ OpenIDE-Module-Display-Category=Infrastructure MSG_OptionsHeader=\nAdditional Module(s) Option(s):\n +MSG_Error=Cannot process command line option(s): {0} --- a/sendopts/src/org/netbeans/modules/sendopts/HandlerImpl.java Sat Feb 26 19:14:39 2011 +0100 +++ a/sendopts/src/org/netbeans/modules/sendopts/HandlerImpl.java Sun Feb 27 09:31:37 2011 +0100 @@ -44,6 +44,7 @@ package org.netbeans.modules.sendopts; import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintStream; @@ -68,10 +69,12 @@ return 0; } catch (CommandException ex) { PrintStream ps = new PrintStream(err); - ps.println(ex.getLocalizedMessage()); - // XXX pst is not useful, only in verbose mode - // the question is how to turn that mode on - // ex.printStackTrace(ps); + try { + ps.println(NbBundle.getMessage(HandlerImpl.class, "MSG_Error", ex.getLocalizedMessage())); + err.flush(); + } catch (IOException io) { + io.printStackTrace(ps); + } return ex.getExitCode(); } }