diff options
author | Thomas Watson | 2012-03-05 19:04:15 +0000 |
---|---|---|
committer | Thomas Watson | 2012-03-05 19:04:15 +0000 |
commit | 45fb68c833efdc1f43bd7aab875008feaad4a4e7 (patch) | |
tree | 9199c5ebf2a148bc62321075590313648f75cbd1 | |
parent | 1a35bb385aa30896b6cc54270a77394fa7e389cf (diff) | |
download | rt.equinox.framework-45fb68c833efdc1f43bd7aab875008feaad4a4e7.tar.gz rt.equinox.framework-45fb68c833efdc1f43bd7aab875008feaad4a4e7.tar.xz rt.equinox.framework-45fb68c833efdc1f43bd7aab875008feaad4a4e7.zip |
Bug 241192 - Instance default location should use better directory onv20120305-1904
Windows
2 files changed, 81 insertions, 2 deletions
diff --git a/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java b/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java index 0545349ca..fe2bf1ebb 100644 --- a/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java +++ b/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -234,6 +234,10 @@ public class Main { protected BufferedWriter log = null; protected boolean newSession = true; + // for variable substitution + public static final String VARIABLE_DELIM_STRING = "$"; //$NON-NLS-1$ + public static final char VARIABLE_DELIM_CHAR = '$'; + /** * A structured form for a version identifier. * @@ -1946,7 +1950,7 @@ public class Main { if (debug) System.out.println(" not found or not read"); //$NON-NLS-1$ } - return result; + return substituteVars(result); } private Properties loadProperties(URL url) throws IOException { @@ -2698,4 +2702,66 @@ public class Main { return super.findLibrary(name); } } + + private Properties substituteVars(Properties result) { + for (Enumeration eKeys = result.keys(); eKeys.hasMoreElements();) { + Object key = eKeys.nextElement(); + if (key instanceof String) { + String value = result.getProperty((String) key); + if (value != null) + result.put(key, substituteVars(value)); + } + } + return result; + } + + public static String substituteVars(String path) { + StringBuffer buf = new StringBuffer(path.length()); + StringTokenizer st = new StringTokenizer(path, VARIABLE_DELIM_STRING, true); + boolean varStarted = false; // indicates we are processing a var subtitute + String var = null; // the current var key + while (st.hasMoreElements()) { + String tok = st.nextToken(); + if (VARIABLE_DELIM_STRING.equals(tok)) { + if (!varStarted) { + varStarted = true; // we found the start of a var + var = ""; //$NON-NLS-1$ + } else { + // we have found the end of a var + String prop = null; + // get the value of the var from system properties + if (var != null && var.length() > 0) + prop = System.getProperty(var); + if (prop == null) { + try { + // try using the System.getenv method if it exists (bug 126921) + Method getenv = System.class.getMethod("getenv", new Class[] {String.class}); //$NON-NLS-1$ + prop = (String) getenv.invoke(null, new Object[] {var}); + } catch (Throwable t) { + // do nothing; + // on 1.4 VMs this throws an error + // on J2ME this method does not exist + } + } + if (prop != null) + // found a value; use it + buf.append(prop); + else + // could not find a value append the var name w/o delims + buf.append(var == null ? "" : var); //$NON-NLS-1$ + varStarted = false; + var = null; + } + } else { + if (!varStarted) + buf.append(tok); // the token is not part of a var + else + var = tok; // the token is the var key; save the key to process when we find the end token + } + } + if (var != null) + // found a case of $var at the end of the path with no trailing $; just append it as is. + buf.append(VARIABLE_DELIM_CHAR).append(var); + return buf.toString(); + } } diff --git a/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseStarter.java b/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseStarter.java index 0a5692db9..9c2f824d7 100644 --- a/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseStarter.java +++ b/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseStarter.java @@ -24,6 +24,7 @@ import org.eclipse.osgi.framework.internal.core.*; import org.eclipse.osgi.framework.internal.core.Constants; import org.eclipse.osgi.framework.log.FrameworkLog; import org.eclipse.osgi.framework.log.FrameworkLogEntry; +import org.eclipse.osgi.internal.baseadaptor.BaseStorageHook; import org.eclipse.osgi.internal.profile.Profile; import org.eclipse.osgi.service.datalocation.Location; import org.eclipse.osgi.service.resolver.*; @@ -1154,6 +1155,18 @@ public class EclipseStarter { // its ok if there is no file. We'll just use the defaults for everything // TODO but it might be nice to log something with gentle wording (i.e., it is not an error) } + return substituteVars(result); + } + + private static Properties substituteVars(Properties result) { + for (Enumeration<Object> eKeys = result.keys(); eKeys.hasMoreElements();) { + Object key = eKeys.nextElement(); + if (key instanceof String) { + String value = result.getProperty((String) key); + if (value != null) + result.put(key, BaseStorageHook.substituteVars(value)); + } + } return result; } |