diff options
author | Pascal Rapicault (Ericsson) | 2013-01-24 19:04:04 +0000 |
---|---|---|
committer | Pascal Rapicault | 2013-01-24 19:05:53 +0000 |
commit | 9f26147ae6cafb9d0c90c8963e702d136cce1adf (patch) | |
tree | 92ee0c6b4e44f566dbe3b83513d82273cb432dfa | |
parent | 34499883d8d54b5965136d5ebb399550ab98ec57 (diff) | |
download | rt.equinox.framework-9f26147ae6cafb9d0c90c8963e702d136cce1adf.tar.gz rt.equinox.framework-9f26147ae6cafb9d0c90c8963e702d136cce1adf.tar.xz rt.equinox.framework-9f26147ae6cafb9d0c90c8963e702d136cce1adf.zip |
Detect when config.ini in the base has changed
-rw-r--r-- | bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java | 77 |
1 files changed, 68 insertions, 9 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 a63d6930e..85417f637 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 @@ -9,6 +9,7 @@ * IBM Corporation - initial API and implementation * Anton Leherbauer (Wind River Systems) - bug 301226 * Red Hat Inc. - bug 373640 + * Ericsson AB (Pascal Rapicault) - bug 304132 *******************************************************************************/ package org.eclipse.equinox.launcher; @@ -239,6 +240,12 @@ public class Main { public static final String VARIABLE_DELIM_STRING = "$"; //$NON-NLS-1$ public static final char VARIABLE_DELIM_CHAR = '$'; + //for change detection in the base when running in shared install mode + private static final long NO_TIMESTAMP = -1; + private static final String BASE_TIMESTAMP_FILE_CONFIGINI = ".baseConfigIniTimestamp"; //$NON-NLS-1$ + private static final String KEY_CONFIGINI_TIMESTAMP = "configIniTimestamp"; //$NON-NLS-1$ + private static final String PROP_IGNORE_USER_CONFIGURATION = "eclipse.ignoreUserConfiguration"; //$NON-NLS-1$ + /** * A structured form for a version identifier. * @@ -1777,7 +1784,9 @@ public class Main { } // Now we know where the base configuration is supposed to be. Go ahead and load - // it and merge into the System properties. Then, if cascaded, read the parent configuration + // it and merge into the System properties. Then, if cascaded, read the parent configuration. + // Note that in a cascaded situation, the user configuration may be ignored if the parent + // configuration has changed since the user configuration has been written. // Note that the parent may or may not be the same parent as we read above since the // base can define its parent. The first parent we read was either defined by the user // on the command line or was the one in the install dir. @@ -1786,11 +1795,12 @@ public class Main { Properties configuration = baseConfiguration; if (configuration == null || !getConfigurationLocation().equals(baseConfigurationLocation)) configuration = loadConfiguration(getConfigurationLocation()); - mergeProperties(System.getProperties(), configuration, null); - if ("false".equalsIgnoreCase(System.getProperty(PROP_CONFIG_CASCADED))) //$NON-NLS-1$ - // if we are not cascaded then remove the parent property even if it was set. + + if (configuration != null && "false".equalsIgnoreCase(configuration.getProperty(PROP_CONFIG_CASCADED))) { //$NON-NLS-1$ System.getProperties().remove(PROP_SHARED_CONFIG_AREA); - else { + configuration.remove(PROP_SHARED_CONFIG_AREA); + mergeProperties(System.getProperties(), configuration, null); + } else { ensureAbsolute(PROP_SHARED_CONFIG_AREA); URL sharedConfigURL = buildLocation(PROP_SHARED_CONFIG_AREA, null, ""); //$NON-NLS-1$ if (sharedConfigURL == null) @@ -1802,15 +1812,33 @@ public class Main { } // if the parent location is different from the config location, read it too. if (sharedConfigURL != null) { - if (sharedConfigURL.equals(getConfigurationLocation())) - // remove the property to show that we do not have a parent. + if (sharedConfigURL.equals(getConfigurationLocation())) { + //After all we are not in a shared configuration setup. + // - remove the property to show that we do not have a parent + // - merge configuration with the system properties System.getProperties().remove(PROP_SHARED_CONFIG_AREA); - else { + mergeProperties(System.getProperties(), configuration, null); + } else { // if the parent we are about to read is the same as the base config we read above, // just reuse the base Properties sharedConfiguration = baseConfiguration; - if (!sharedConfigURL.equals(baseConfigurationLocation)) + if (!sharedConfigURL.equals(baseConfigurationLocation)) { sharedConfiguration = loadConfiguration(sharedConfigURL); + } + long sharedConfigTimestamp = getCurrentConfigIniBaseTimestamp(sharedConfigURL); + long lastKnownBaseTimestamp = getLastKnownConfigIniBaseTimestamp(); + if (debug) + System.out.println("Timestamps found: \n\t config.ini in the base: " + sharedConfigTimestamp + "\n\t remembered " + lastKnownBaseTimestamp); //$NON-NLS-1$ //$NON-NLS-2$ + + //merge user configuration since the base has not changed. + if (lastKnownBaseTimestamp == sharedConfigTimestamp || lastKnownBaseTimestamp == NO_TIMESTAMP) { + mergeProperties(System.getProperties(), configuration, null); + } else { + configuration = null; + System.setProperty(PROP_IGNORE_USER_CONFIGURATION, Boolean.TRUE.toString()); + } + + //now merge the base configuration mergeProperties(System.getProperties(), sharedConfiguration, configuration); System.getProperties().put(PROP_SHARED_CONFIG_AREA, sharedConfigURL.toExternalForm()); if (debug) @@ -1831,6 +1859,37 @@ public class Main { } } + private long getCurrentConfigIniBaseTimestamp(URL url) { + try { + url = new URL(url, CONFIG_FILE); + } catch (MalformedURLException e1) { + return NO_TIMESTAMP; + } + URLConnection connection = null; + try { + connection = url.openConnection(); + } catch (IOException e) { + return NO_TIMESTAMP; + } + return connection.getLastModified(); + } + + //Get the timestamp that has been remembered. The BASE_TIMESTAMP_FILE_CONFIGINI is written at provisioning time by fwkAdmin. + private long getLastKnownConfigIniBaseTimestamp() { + if (debug) + System.out.println("Loading timestamp file from:\n\t " + getConfigurationLocation() + " " + BASE_TIMESTAMP_FILE_CONFIGINI); //$NON-NLS-1$ //$NON-NLS-2$ + Properties result; + try { + result = load(getConfigurationLocation(), BASE_TIMESTAMP_FILE_CONFIGINI); + } catch (IOException e) { + if (debug) + System.out.println("\tNo timestamp file found"); //$NON-NLS-1$ + return NO_TIMESTAMP; + } + String timestamp = result.getProperty(KEY_CONFIGINI_TIMESTAMP); + return Long.parseLong(timestamp); + } + /** * Ensures the value for a system property is an absolute URL. Relative URLs are translated to * absolute URLs by taking the install URL as reference. |