From: <otm...@us...> - 2008-10-21 22:37:04
|
Revision: 5502 http://jython.svn.sourceforge.net/jython/?rev=5502&view=rev Author: otmarhumbel Date: 2008-10-21 22:36:57 +0000 (Tue, 21 Oct 2008) Log Message: ----------- auto switch to console mode if running on GNU java this partly fixes issue #1135 Modified Paths: -------------- trunk/installer/src/java/org/python/util/install/Installation.java trunk/installer/src/java/org/python/util/install/InstallerCommandLine.java trunk/installer/test/java/org/python/util/install/InstallationTest.java trunk/installer/test/java/org/python/util/install/InstallerCommandLineTest.java Modified: trunk/installer/src/java/org/python/util/install/Installation.java =================================================================== --- trunk/installer/src/java/org/python/util/install/Installation.java 2008-10-21 21:59:40 UTC (rev 5501) +++ trunk/installer/src/java/org/python/util/install/Installation.java 2008-10-21 22:36:57 UTC (rev 5502) @@ -23,6 +23,7 @@ protected static final String OS_NAME = "os.name"; protected static final String OS_VERSION = "os.version"; + protected static final String JAVA_VM_NAME = "java.vm.name"; protected static final String EMPTY = ""; protected static final String HEADLESS_PROPERTY_NAME = "java.awt.headless"; @@ -126,6 +127,16 @@ return isMacintosh; } + protected static boolean isGNUJava() { + boolean isGNUJava = false; + String javaVmName = System.getProperty(JAVA_VM_NAME, ""); + String lowerVmName = javaVmName.toLowerCase(); + if (lowerVmName.indexOf("gnu") >= 0 && lowerVmName.indexOf("libgcj") >= 0) { + isGNUJava = true; + } + return isGNUJava; + } + protected static boolean isJDK141() { boolean isJDK141 = false; String javaVersion = System.getProperty(JavaVersionTester.JAVA_VERSION, ""); Modified: trunk/installer/src/java/org/python/util/install/InstallerCommandLine.java =================================================================== --- trunk/installer/src/java/org/python/util/install/InstallerCommandLine.java 2008-10-21 21:59:40 UTC (rev 5501) +++ trunk/installer/src/java/org/python/util/install/InstallerCommandLine.java 2008-10-21 22:36:57 UTC (rev 5502) @@ -171,16 +171,17 @@ */ public boolean setArgs(String args[]) { _args = args; - if (!hasConsoleOptionInArgs(args) && !hasSilentOptionInArgs(args) - && !Installation.isGuiAllowed()) { - // auto switch to console mode - if (hasVerboseOptionInArgs(args)) { - ConsoleInstaller.message("auto-switching to console mode"); + 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"); + } + 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; } try { // throws for missing or unknown options / arguments Modified: trunk/installer/test/java/org/python/util/install/InstallationTest.java =================================================================== --- trunk/installer/test/java/org/python/util/install/InstallationTest.java 2008-10-21 21:59:40 UTC (rev 5501) +++ trunk/installer/test/java/org/python/util/install/InstallationTest.java 2008-10-21 22:36:57 UTC (rev 5502) @@ -71,4 +71,17 @@ assertTrue(Installation.isValidJava(javaVersionInfo)); } + public void testIsGNUJava() { + assertFalse(Installation.isGNUJava()); + String originalVmName = System.getProperty(Installation.JAVA_VM_NAME); + try { + // fake GNU java + System.setProperty(Installation.JAVA_VM_NAME, "GNU libgcj"); + assertTrue(Installation.isGNUJava()); + } finally { + System.setProperty(Installation.JAVA_VM_NAME, originalVmName); + assertFalse(Installation.isGNUJava()); + } + } + } Modified: trunk/installer/test/java/org/python/util/install/InstallerCommandLineTest.java =================================================================== --- trunk/installer/test/java/org/python/util/install/InstallerCommandLineTest.java 2008-10-21 21:59:40 UTC (rev 5501) +++ trunk/installer/test/java/org/python/util/install/InstallerCommandLineTest.java 2008-10-21 22:36:57 UTC (rev 5502) @@ -277,6 +277,38 @@ } } + public void testGNUSwitchToConsole() { + String originalVmName = System.getProperty(Installation.JAVA_VM_NAME); + try { + // fake GNU java + System.setProperty(Installation.JAVA_VM_NAME, "GNU libgcj"); + assertTrue(Installation.isGNUJava()); + String[] args; + InstallerCommandLine commandLine; + // expect auto switch + args = new String[] {"-v"}; + commandLine = new InstallerCommandLine(); + assertTrue(commandLine.setArgs(args)); + assertTrue(commandLine.hasVerboseOption()); + assertTrue(commandLine.hasConsoleOption()); // auto switch + // expect no auto switch + args = new String[] {"-s", "-d", "some_dir"}; + commandLine = new InstallerCommandLine(); + assertTrue(commandLine.setArgs(args)); + assertTrue(commandLine.hasSilentOption()); + assertFalse(commandLine.hasVerboseOption()); + assertFalse(commandLine.hasConsoleOption()); // no auto switch + assertTrue(commandLine.hasDirectoryOption()); + File dir = commandLine.getTargetDirectory(); + assertNotNull(dir); + assertEquals("some_dir", dir.getName()); + } finally { + System.setProperty(Installation.JAVA_VM_NAME, originalVmName); + assertFalse(Installation.isGNUJava()); + } + } + + public void testDirectory() { String[] args; InstallerCommandLine commandLine; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |