From: <otm...@us...> - 2009-01-18 13:46:22
|
Revision: 5946 http://jython.svn.sourceforge.net/jython/?rev=5946&view=rev Author: otmarhumbel Date: 2009-01-18 13:46:12 +0000 (Sun, 18 Jan 2009) Log Message: ----------- enable running jython from a directory with an exclamation mark in it's name due to jdk limitations this is only possible for + jdk 1.6 and higher + directory names not ending with an exclamation mark due to the special treatment of exclamation marks in enabledelayedexpansion, this is currently not possible for jython.bat on windows installer autotests now use an exclamation mark if possible Modified Paths: -------------- trunk/installer/src/java/org/python/util/install/Installation.java trunk/installer/src/java/org/python/util/install/JavaVersionTester.java trunk/installer/src/java/org/python/util/install/driver/Autotest.java trunk/installer/test/java/org/python/util/install/InstallationTest.java trunk/jython/src/org/python/core/PySystemState.java Modified: trunk/installer/src/java/org/python/util/install/Installation.java =================================================================== --- trunk/installer/src/java/org/python/util/install/Installation.java 2009-01-18 10:04:29 UTC (rev 5945) +++ trunk/installer/src/java/org/python/util/install/Installation.java 2009-01-18 13:46:12 UTC (rev 5946) @@ -17,6 +17,9 @@ import org.python.util.install.driver.Tunnel; public class Installation { + public final static int NORMAL_RETURN = 0; + public final static int ERROR_RETURN = 1; + protected static final String ALL = "1"; protected static final String STANDARD = "2"; protected static final String MINIMUM = "3"; @@ -29,9 +32,6 @@ protected static final String HEADLESS_PROPERTY_NAME = "java.awt.headless"; - protected final static int NORMAL_RETURN = 0; - protected final static int ERROR_RETURN = 1; - private static final String RESOURCE_CLASS = "org.python.util.install.TextConstants"; private static ResourceBundle _textConstants = ResourceBundle.getBundle(RESOURCE_CLASS, Locale.getDefault()); @@ -92,24 +92,31 @@ protected static boolean isValidJava(JavaVersionInfo javaVersionInfo) { String specificationVersion = javaVersionInfo.getSpecificationVersion(); verboseOutput("specification version: '" + specificationVersion + "'"); + boolean valid = true; + if (getJavaSpecificationVersion(specificationVersion) < 15) { + valid = false; + } + return valid; + } + + /** + * @return specification version as an int, e.g. 15 or 16 (the micro part is ignored) + * @param specificationVersion + * as system property + */ + public static int getJavaSpecificationVersion(String specificationVersion) { // major.minor.micro // according to http://java.sun.com/j2se/1.5.0/docs/guide/versioning/spec/versioning2.html - int major = 0; - int minor = 0; + String major = "1"; + String minor = "0"; StringTokenizer tokenizer = new StringTokenizer(specificationVersion, "."); if (tokenizer.hasMoreTokens()) { - major = Integer.valueOf(tokenizer.nextToken()).intValue(); + major = tokenizer.nextToken(); } if (tokenizer.hasMoreTokens()) { - minor = Integer.valueOf(tokenizer.nextToken()).intValue(); + minor = tokenizer.nextToken(); } - boolean valid = true; - if (major == 1) { - if (minor < 5) { - valid = false; - } - } - return valid; + return Integer.valueOf(major.concat(minor)).intValue(); } public static boolean isWindows() { @@ -201,6 +208,46 @@ return versionInfo; } + + /** + * @return The system default java version + */ + public static JavaVersionInfo getDefaultJavaVersion() { + JavaVersionInfo versionInfo = new JavaVersionInfo(); + String executableName = "java"; + try { + // launch the java command - temporary file will be written by the child process + File tempFile = File.createTempFile("jython_installation", ".properties"); + if (tempFile.exists() && tempFile.canWrite()) { + String command[] = new String[5]; + command[0] = executableName; + command[1] = "-cp"; + // our own class path should be ok here + command[2] = System.getProperty("java.class.path"); + command[3] = JavaVersionTester.class.getName(); + command[4] = tempFile.getAbsolutePath(); + ChildProcess childProcess = new ChildProcess(command, 10000); // 10 seconds + childProcess.setDebug(false); + int errorCode = childProcess.run(); + if (errorCode != NORMAL_RETURN) { + versionInfo.setErrorCode(errorCode); + versionInfo.setReason(getText(TextKeys.C_NO_VALID_JAVA, executableName)); + } else { + Properties tempProperties = new Properties(); + tempProperties.load(new FileInputStream(tempFile)); + fillJavaVersionInfo(versionInfo, tempProperties); + } + } else { + versionInfo.setErrorCode(ERROR_RETURN); + versionInfo.setReason(getText(TextKeys.C_UNABLE_CREATE_TMPFILE, + tempFile.getAbsolutePath())); + } + } catch (IOException e) { + versionInfo.setErrorCode(ERROR_RETURN); + versionInfo.setReason(getText(TextKeys.C_NO_VALID_JAVA, executableName)); + } + return versionInfo; + } protected static void fillJavaVersionInfo(JavaVersionInfo versionInfo, Properties properties) { versionInfo.setVersion(properties.getProperty(JavaVersionTester.JAVA_VERSION)); @@ -208,7 +255,7 @@ versionInfo.setVendor(properties.getProperty(JavaVersionTester.JAVA_VENDOR)); } - protected static class JavaVersionInfo { + public static class JavaVersionInfo { private String _version; private String _specificationVersion; private String _vendor; @@ -246,7 +293,7 @@ return _version; } - protected String getSpecificationVersion() { + public String getSpecificationVersion() { return _specificationVersion; } @@ -254,7 +301,7 @@ return _vendor; } - protected int getErrorCode() { + public int getErrorCode() { return _errorCode; } Modified: trunk/installer/src/java/org/python/util/install/JavaVersionTester.java =================================================================== --- trunk/installer/src/java/org/python/util/install/JavaVersionTester.java 2009-01-18 10:04:29 UTC (rev 5945) +++ trunk/installer/src/java/org/python/util/install/JavaVersionTester.java 2009-01-18 13:46:12 UTC (rev 5946) @@ -9,7 +9,7 @@ public static final String JAVA_HOME = "java.home"; protected static final String JAVA_VERSION = "java.version"; - protected static final String JAVA_SPECIFICATION_VERSION = "java.specification.version"; + public static final String JAVA_SPECIFICATION_VERSION = "java.specification.version"; protected static final String JAVA_VENDOR = "java.vendor"; private static final String NEWLINE = "\n"; Modified: trunk/installer/src/java/org/python/util/install/driver/Autotest.java =================================================================== --- trunk/installer/src/java/org/python/util/install/driver/Autotest.java 2009-01-18 10:04:29 UTC (rev 5945) +++ trunk/installer/src/java/org/python/util/install/driver/Autotest.java 2009-01-18 13:46:12 UTC (rev 5946) @@ -4,9 +4,12 @@ import java.io.IOException; import org.python.util.install.FileHelper; +import org.python.util.install.Installation; import org.python.util.install.InstallationListener; import org.python.util.install.InstallerCommandLine; import org.python.util.install.JavaHomeHandler; +import org.python.util.install.JavaVersionTester; +import org.python.util.install.Installation.JavaVersionInfo; public abstract class Autotest implements InstallationListener { @@ -14,6 +17,7 @@ private static int _count = 0; // unique test number private static File _rootDirectory = null; + private static JavaVersionInfo _systemDefaultJavaVersion; private String _name; private File _targetDir; @@ -176,6 +180,10 @@ b.append(_count); // explicitly use a blank, to nail down some platform specific problems b.append(' '); + // add an exclamation mark if possible (see issue #1208) + if(canHandleExclamationMarks()) { + b.append('!'); + } b.append(getNameSuffix()); b.append('_'); _name = b.toString(); @@ -230,4 +238,37 @@ } } + /** + * Determine if the target directory may contain an exclamation mark (see also issue #1208). + * <p> + * Autotests can handle exclamation marks, if both the running and the system default java + * specification versions are 1.6 or higher. Class.getResource() was fixed for JDK 1.6, but only if the directory name does not end with '!'... + * <p> + * Currently there is no way on windows, because the enabledelayedexpansion in jython.bat cannot + * handle exclamation marks in variable names. + * + * @return <code>true</code> if we can handle exclamation marks, <code>false</code> otherwise + */ + private boolean canHandleExclamationMarks() { + boolean exclamation = false; + if (!Installation.isWindows()) { + // get the running java specification version + String specificationVersion = System.getProperty(JavaVersionTester.JAVA_SPECIFICATION_VERSION, + ""); + if (Installation.getJavaSpecificationVersion(specificationVersion) > 15) { + // get the system default java version + if (_systemDefaultJavaVersion == null) { + _systemDefaultJavaVersion = Installation.getDefaultJavaVersion(); + } + if (_systemDefaultJavaVersion.getErrorCode() == Installation.NORMAL_RETURN) { + specificationVersion = _systemDefaultJavaVersion.getSpecificationVersion(); + if (Installation.getJavaSpecificationVersion(specificationVersion) > 15) { + exclamation = true; + } + } + } + } + return exclamation; + } + } Modified: trunk/installer/test/java/org/python/util/install/InstallationTest.java =================================================================== --- trunk/installer/test/java/org/python/util/install/InstallationTest.java 2009-01-18 10:04:29 UTC (rev 5945) +++ trunk/installer/test/java/org/python/util/install/InstallationTest.java 2009-01-18 13:46:12 UTC (rev 5946) @@ -73,6 +73,15 @@ assertTrue(Installation.isValidJava(javaVersionInfo)); } + public void testGetJavaSpecificationVersion() { + String specificationVersion = "1.4.2"; + assertEquals(14, Installation.getJavaSpecificationVersion(specificationVersion)); + specificationVersion = "1.5.0"; + assertEquals(15, Installation.getJavaSpecificationVersion(specificationVersion)); + specificationVersion = "1.6.0"; + assertEquals(16, Installation.getJavaSpecificationVersion(specificationVersion)); + } + public void testIsGNUJava() { assertFalse(Installation.isGNUJava()); String originalVmName = System.getProperty(Installation.JAVA_VM_NAME); @@ -85,5 +94,14 @@ assertFalse(Installation.isGNUJava()); } } + + public void testGetDefaultJavaVersion() { + JavaVersionInfo info = Installation.getDefaultJavaVersion(); + assertNotNull(info); + assertEquals(Installation.NORMAL_RETURN, info.getErrorCode()); + String specVersion = info.getSpecificationVersion(); + assertNotNull(specVersion); + assertTrue(specVersion.length() >= 3); + } } Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2009-01-18 10:04:29 UTC (rev 5945) +++ trunk/jython/src/org/python/core/PySystemState.java 2009-01-18 13:46:12 UTC (rev 5946) @@ -889,7 +889,7 @@ if (url != null) { try { String urlString = URLDecoder.decode(url.toString()); - int jarSeparatorIndex = urlString.indexOf(JAR_SEPARATOR); + int jarSeparatorIndex = urlString.lastIndexOf(JAR_SEPARATOR); if (urlString.startsWith(JAR_URL_PREFIX) && jarSeparatorIndex > 0) { jarFileName = urlString.substring(JAR_URL_PREFIX.length(), jarSeparatorIndex); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |