From: <otm...@us...> - 2008-11-05 17:51:40
|
Revision: 5547 http://jython.svn.sourceforge.net/jython/?rev=5547&view=rev Author: otmarhumbel Date: 2008-11-05 17:51:34 +0000 (Wed, 05 Nov 2008) Log Message: ----------- allow the installer to be started as follows: java -Djava.awt.headless=true -jar jython_installer-2.5b0.jar -A this is necessary if we want to stress-test it on build bots Modified Paths: -------------- trunk/installer/src/java/org/python/util/install/InstallerCommandLine.java trunk/installer/test/java/org/python/util/install/InstallerCommandLineTest.java Modified: trunk/installer/src/java/org/python/util/install/InstallerCommandLine.java =================================================================== --- trunk/installer/src/java/org/python/util/install/InstallerCommandLine.java 2008-11-05 15:32:35 UTC (rev 5546) +++ trunk/installer/src/java/org/python/util/install/InstallerCommandLine.java 2008-11-05 17:51:34 UTC (rev 5547) @@ -134,28 +134,6 @@ } /** - * Pre-scan of the arguments to detect a console flag - * @param args - * @return <code>true</code> if there is a console option - */ - public static final boolean hasConsoleOptionInArgs(String[] args) { - String shortConsole = "-".concat(CONSOLE_SHORT); - String longConsole = "--".concat(CONSOLE_LONG); - return hasOptionInArgs(args, shortConsole, longConsole); - } - - /** - * Pre-scan of the arguments to detect a silent flag - * @param args - * @return <code>true</code> if there is a silent option - */ - public static final boolean hasSilentOptionInArgs(String[] args) { - String shortSilent = "-".concat(SILENT_SHORT); - String longSilent = "--".concat(SILENT_LONG); - return hasOptionInArgs(args, shortSilent, longSilent); - } - - /** * constructor intended for JUnit tests only. */ public InstallerCommandLine() { @@ -170,19 +148,26 @@ * <code>false</code> is returned */ public boolean setArgs(String args[]) { - _args = args; - if (!hasConsoleOptionInArgs(args) && !hasSilentOptionInArgs(args)) { - if (!Installation.isGuiAllowed() || Installation.isGNUJava()) { - // auto switch to console mode - if (hasVerboseOptionInArgs(args)) { - ConsoleInstaller.message("auto-switching to console mode"); + // pre-process args to determine if we can (and should) switch to console mode + try { + CommandLine preCommandLine = _parser.parse(_options, args, false); + if (!hasConsoleOption(preCommandLine) && !hasSilentOption(preCommandLine) + && !hasAutotestOption(preCommandLine)) { + if (!Installation.isGuiAllowed() || Installation.isGNUJava()) { + // auto switch to console mode + if (hasVerboseOption(preCommandLine)) { + ConsoleInstaller.message("auto-switching to console mode"); + } + String[] newArgs = new String[args.length + 1]; + System.arraycopy(args, 0, newArgs, 0, args.length); + newArgs[args.length] = "-" + CONSOLE_SHORT; + args = newArgs; } - String[] newArgs = new String[args.length + 1]; - System.arraycopy(args, 0, newArgs, 0, args.length); - newArgs[args.length] = "-" + CONSOLE_SHORT; - _args = newArgs; } + } catch (Exception e) { + // ignore } + _args = args; try { // throws for missing or unknown options / arguments _commandLine = _parser.parse(_options, _args, false); @@ -245,16 +230,28 @@ } public boolean hasSilentOption() { - return _commandLine.hasOption(SILENT_SHORT) || _commandLine.hasOption(SILENT_LONG); + return hasSilentOption(_commandLine); } + private boolean hasSilentOption(CommandLine commandLine) { + return commandLine.hasOption(SILENT_SHORT) || commandLine.hasOption(SILENT_LONG); + } + public boolean hasConsoleOption() { - return _commandLine.hasOption(CONSOLE_SHORT) || _commandLine.hasOption(CONSOLE_LONG); + return hasConsoleOption(_commandLine); } + + private boolean hasConsoleOption(CommandLine commandLine) { + return commandLine.hasOption(CONSOLE_SHORT) || commandLine.hasOption(CONSOLE_LONG); + } public boolean hasAutotestOption() { - return _commandLine.hasOption(AUTOTEST_SHORT) || _commandLine.hasOption(AUTOTEST_LONG); + return hasAutotestOption(_commandLine); } + + private boolean hasAutotestOption(CommandLine commandLine) { + return commandLine.hasOption(AUTOTEST_SHORT) || commandLine.hasOption(AUTOTEST_LONG); + } public boolean hasDirectoryOption() { return _commandLine.hasOption(DIRECTORY_SHORT) || _commandLine.hasOption(DIRECTORY_LONG); @@ -277,9 +274,13 @@ } public boolean hasVerboseOption() { - return _commandLine.hasOption(VERBOSE_SHORT) || _commandLine.hasOption(VERBOSE_LONG); + return hasVerboseOption(_commandLine); } + private boolean hasVerboseOption(CommandLine commandLine) { + return commandLine.hasOption(VERBOSE_SHORT) || commandLine.hasOption(VERBOSE_LONG); + } + public void printHelp() { HelpFormatter formatter = new HelpFormatter(); formatter.defaultWidth = 76; Modified: trunk/installer/test/java/org/python/util/install/InstallerCommandLineTest.java =================================================================== --- trunk/installer/test/java/org/python/util/install/InstallerCommandLineTest.java 2008-11-05 15:32:35 UTC (rev 5546) +++ trunk/installer/test/java/org/python/util/install/InstallerCommandLineTest.java 2008-11-05 17:51:34 UTC (rev 5547) @@ -269,6 +269,22 @@ File dir = commandLine.getTargetDirectory(); assertNotNull(dir); assertEquals("some_dir", dir.getName()); + + // -A (autotest) should override as well + args = new String[] {"-A"}; + commandLine = new InstallerCommandLine(); + assertTrue(commandLine.setArgs(args)); + assertFalse(commandLine.hasVerboseOption()); + assertFalse(commandLine.hasConsoleOption()); // no auto switch + assertFalse(commandLine.hasSilentOption()); + + // console aready present should be no problem + args = new String[] {"-c", "-v"}; + commandLine = new InstallerCommandLine(); + assertTrue(commandLine.setArgs(args)); + assertTrue(commandLine.hasVerboseOption()); + assertTrue(commandLine.hasConsoleOption()); + assertFalse(commandLine.hasSilentOption()); } finally { if (!originalHeadless) { System.setProperty(Installation.HEADLESS_PROPERTY_NAME, "false"); @@ -607,51 +623,5 @@ args = new String[] {"a", "--" + InstallerCommandLine.VERBOSE_LONG, "c"}; assertTrue(InstallerCommandLine.hasVerboseOptionInArgs(args)); } - - public void testHasConsoleOptionInArgs() { - String[] args = new String[0]; - assertFalse(InstallerCommandLine.hasConsoleOptionInArgs(args)); - - args = new String[] {"a", "b", "c"}; - assertFalse(InstallerCommandLine.hasConsoleOptionInArgs(args)); - - args = new String[] {"a", InstallerCommandLine.CONSOLE_SHORT, "c"}; - assertFalse(InstallerCommandLine.hasConsoleOptionInArgs(args)); - - args = new String[] {"a", "-" + InstallerCommandLine.CONSOLE_SHORT, "c"}; - assertTrue(InstallerCommandLine.hasConsoleOptionInArgs(args)); - - args = new String[] {"a", InstallerCommandLine.CONSOLE_LONG, "c"}; - assertFalse(InstallerCommandLine.hasConsoleOptionInArgs(args)); - - args = new String[] {"a", "-" + InstallerCommandLine.CONSOLE_LONG, "c"}; - assertFalse(InstallerCommandLine.hasConsoleOptionInArgs(args)); - - args = new String[] {"a", "--" + InstallerCommandLine.CONSOLE_LONG, "c"}; - assertTrue(InstallerCommandLine.hasConsoleOptionInArgs(args)); - } - - public void testHasSilentOptionInArgs() { - String[] args = new String[0]; - assertFalse(InstallerCommandLine.hasSilentOptionInArgs(args)); - - args = new String[] {"a", "b", "c"}; - assertFalse(InstallerCommandLine.hasSilentOptionInArgs(args)); - - args = new String[] {"a", InstallerCommandLine.SILENT_SHORT, "c"}; - assertFalse(InstallerCommandLine.hasSilentOptionInArgs(args)); - - args = new String[] {"a", "-" + InstallerCommandLine.SILENT_SHORT, "c"}; - assertTrue(InstallerCommandLine.hasSilentOptionInArgs(args)); - - args = new String[] {"a", InstallerCommandLine.SILENT_LONG, "c"}; - assertFalse(InstallerCommandLine.hasSilentOptionInArgs(args)); - - args = new String[] {"a", "-" + InstallerCommandLine.SILENT_LONG, "c"}; - assertFalse(InstallerCommandLine.hasSilentOptionInArgs(args)); - - args = new String[] {"a", "--" + InstallerCommandLine.SILENT_LONG, "c"}; - assertTrue(InstallerCommandLine.hasSilentOptionInArgs(args)); - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |