summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault (Ericsson)2013-01-16 19:50:32 (EST)
committerPascal Rapicault2013-01-16 19:58:17 (EST)
commit3de6f8593d5c1b21be3bd21000e34acb945056b1 (patch)
tree8ec169e7953ec2afad562038a2cb08c594407eef
parent446649c95063dca689f4d2c886b26975a11f3499 (diff)
downloadrt.equinox.p2-3de6f8593d5c1b21be3bd21000e34acb945056b1.zip
rt.equinox.p2-3de6f8593d5c1b21be3bd21000e34acb945056b1.tar.gz
rt.equinox.p2-3de6f8593d5c1b21be3bd21000e34acb945056b1.tar.bz2
Detect changes in the bundles.info
-rw-r--r--bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwConfigFileParser.java12
-rw-r--r--bundles/org.eclipse.equinox.simpleconfigurator.manipulator/src/org/eclipse/equinox/internal/simpleconfigurator/manipulator/SimpleConfiguratorManipulatorImpl.java34
-rw-r--r--bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/SimpleConfiguratorImpl.java62
3 files changed, 87 insertions, 21 deletions
diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwConfigFileParser.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwConfigFileParser.java
index 856ceee..6f21df7 100644
--- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwConfigFileParser.java
+++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwConfigFileParser.java
@@ -30,8 +30,8 @@ public class EquinoxFwConfigFileParser {
private static final String KEY_ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL = "org.eclipse.equinox.simpleconfigurator.configUrl"; //$NON-NLS-1$
private static final String REFERENCE_SCHEME = "reference:"; //$NON-NLS-1$
private static final String FILE_PROTOCOL = "file:"; //$NON-NLS-1$
- private static final String BASE_TIMESTAMPS_FILE = ".baseTimestamps"; //$NON-NLS-1$
- private static final String KEY_CONFIG_TIMESTAMP = "configIniTimestamp"; //$NON-NLS-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 boolean DEBUG = false;
@@ -247,7 +247,7 @@ public class EquinoxFwConfigFileParser {
private boolean hasBasedChanged(File configIni, Manipulator manipulator, Properties configProps) {
LauncherData launcherData = manipulator.getLauncherData();
File sharedConfigIni = findSharedConfigIniFile(ParserUtils.getOSGiInstallArea(Arrays.asList(launcherData.getProgramArgs()), configProps, launcherData), configProps.getProperty(EquinoxConstants.PROP_SHARED_CONFIGURATION_AREA));
- File timestampFile = new File(configIni.getParentFile(), BASE_TIMESTAMPS_FILE);
+ File timestampFile = new File(configIni.getParentFile(), BASE_TIMESTAMP_FILE_CONFIGINI);
Properties timestamps;
try {
timestamps = loadProperties(timestampFile);
@@ -256,7 +256,7 @@ public class EquinoxFwConfigFileParser {
} catch (IOException e) {
return false;
}
- return String.valueOf(sharedConfigIni.lastModified()).equals(timestamps.getProperty(KEY_CONFIG_TIMESTAMP));
+ return String.valueOf(sharedConfigIni.lastModified()).equals(timestamps.getProperty(KEY_CONFIGINI_TIMESTAMP));
}
private void readDefaultStartLevel(ConfigData configData, Properties props) {
@@ -593,14 +593,14 @@ public class EquinoxFwConfigFileParser {
File sharedConfigIni = findSharedConfigIniFile(ParserUtils.getOSGiInstallArea(Arrays.asList(launcherData.getProgramArgs()), configProps, launcherData), configProps.getProperty(EquinoxConstants.PROP_SHARED_CONFIGURATION_AREA));
if (sharedConfigIni == null)
return;
- File timestampFile = new File(folder, BASE_TIMESTAMPS_FILE);
+ File timestampFile = new File(folder, BASE_TIMESTAMP_FILE_CONFIGINI);
Properties timestamps;
try {
timestamps = loadProperties(timestampFile);
} catch (IOException e) {
timestamps = new Properties();
}
- timestamps.setProperty(KEY_CONFIG_TIMESTAMP, String.valueOf(sharedConfigIni.lastModified()));
+ timestamps.setProperty(KEY_CONFIGINI_TIMESTAMP, String.valueOf(sharedConfigIni.lastModified()));
saveProperties(timestampFile, timestamps);
}
diff --git a/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/src/org/eclipse/equinox/internal/simpleconfigurator/manipulator/SimpleConfiguratorManipulatorImpl.java b/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/src/org/eclipse/equinox/internal/simpleconfigurator/manipulator/SimpleConfiguratorManipulatorImpl.java
index c6748e9..6fe8fa6 100644
--- a/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/src/org/eclipse/equinox/internal/simpleconfigurator/manipulator/SimpleConfiguratorManipulatorImpl.java
+++ b/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/src/org/eclipse/equinox/internal/simpleconfigurator/manipulator/SimpleConfiguratorManipulatorImpl.java
@@ -1,10 +1,13 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 IBM Corporation and others. All rights reserved.
+ * Copyright (c) 2007, 2013 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 http://www.eclipse.org/legal/epl-v10.html
*
* Contributors: IBM Corporation - initial API and implementation
+ *
+ * Ericsson AB (Pascal Rapicault) - Bug 397216 -[Shared] Better shared
+ * configuration change discovery
*******************************************************************************/
package org.eclipse.equinox.internal.simpleconfigurator.manipulator;
@@ -63,7 +66,7 @@ public class SimpleConfiguratorManipulatorImpl implements SimpleConfiguratorMani
if (manipulator.getLauncherData().getLauncher() != null) {
baseDir = manipulator.getLauncherData().getLauncher().getParentFile();
} else {
- throw new IllegalStateException("All of fwConfigFile, home, launcher are not set.");
+ throw new IllegalStateException("All of fwConfigFile, home, launcher are not set."); //$NON-NLS-1$
}
}
} else {
@@ -393,6 +396,33 @@ public class SimpleConfiguratorManipulatorImpl implements SimpleConfiguratorMani
return;
}
SimpleConfiguratorManipulatorUtils.writeConfiguration(simpleInfos, outputFile);
+ if (CONFIG_LIST.equals(outputFile.getName()))
+ rememberSharedBundlesInfoTimestamp(installArea, outputFile.getParentFile());
+ }
+
+ private void rememberSharedBundlesInfoTimestamp(URI installArea, File outputFolder) {
+ if (installArea == null)
+ return;
+
+ File sharedBundlesInfo = new File(URIUtil.append(installArea, "configuration" + File.separatorChar + CONFIGURATOR_FOLDER + File.separatorChar + CONFIG_LIST));
+ if (!sharedBundlesInfo.exists())
+ return;
+
+ Properties timestampToPersist = new Properties();
+ timestampToPersist.put(SimpleConfiguratorImpl.KEY_BUNDLESINFO_TIMESTAMP, Long.toString(sharedBundlesInfo.lastModified()));
+ OutputStream os = null;
+ try {
+ try {
+ File outputFile = new File(outputFolder, SimpleConfiguratorImpl.BASE_TIMESTAMP_FILE_BUNDLESINFO);
+ os = new BufferedOutputStream(new FileOutputStream(outputFile));
+ timestampToPersist.store(os, "Written by " + this.getClass()); //$NON-NLS-1$
+ } finally {
+ if (os != null)
+ os.close();
+ }
+ } catch (IOException e) {
+ return;
+ }
}
private org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo[] convertBundleInfos(BundleInfo[] configuration, URI installArea) {
diff --git a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/SimpleConfiguratorImpl.java b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/SimpleConfiguratorImpl.java
index dbd2aec..ba07518 100644
--- a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/SimpleConfiguratorImpl.java
+++ b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/SimpleConfiguratorImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 IBM Corporation and others.
+ * Copyright (c) 2007, 2013 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
@@ -7,13 +7,14 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Ericsson AB (Pascal Rapicault) - Bug 397216 -[Shared] Better shared configuration change discovery
*******************************************************************************/
package org.eclipse.equinox.internal.simpleconfigurator;
-import java.io.File;
-import java.io.IOException;
-import java.net.*;
-import java.util.List;
+import java.io.*;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Properties;
import org.eclipse.equinox.internal.provisional.configurator.Configurator;
import org.eclipse.equinox.internal.simpleconfigurator.utils.*;
import org.osgi.framework.Bundle;
@@ -42,6 +43,12 @@ public class SimpleConfiguratorImpl implements Configurator {
private ConfigApplier configApplier;
private Bundle bundle;
+ //for change detection in the base when running in shared install mode
+ private static final long NO_TIMESTAMP = -1;
+ public static final String BASE_TIMESTAMP_FILE_BUNDLESINFO = ".baseBundlesInfoTimestamp"; //$NON-NLS-1$
+ public static final String KEY_BUNDLESINFO_TIMESTAMP = "bundlesInfoTimestamp";
+ private static final String PROP_IGNORE_USER_CONFIGURATION = "eclipse.ignoreUserConfiguration"; //$NON-NLS-1$
+
public SimpleConfiguratorImpl(BundleContext context, Bundle bundle) {
this.context = context;
this.bundle = bundle;
@@ -92,15 +99,15 @@ public class SimpleConfiguratorImpl implements Configurator {
if (!sharedConfig.exists())
return userConfig.toURL();
- URI base = EquinoxUtils.getInstallLocationURI(context);
-
- URL sharedConfigURL = sharedConfig.toURL();
- List sharedBundles = SimpleConfiguratorUtils.readConfiguration(sharedConfigURL, base);
+ long sharedBundlesInfoTimestamp = getCurrentBundlesInfoBaseTimestamp(sharedConfig);
+ long lastKnownBaseTimestamp = getLastKnownBundlesInfoBaseTimestamp(userConfig.getParentFile());
- URL userConfigURL = userConfig.toURL();
- List userBundles = SimpleConfiguratorUtils.readConfiguration(userConfigURL, base);
-
- return (userBundles.containsAll(sharedBundles)) ? userConfigURL : sharedConfigURL;
+ if (lastKnownBaseTimestamp == sharedBundlesInfoTimestamp || lastKnownBaseTimestamp == NO_TIMESTAMP) {
+ return userConfig.toURL();
+ } else {
+ System.setProperty(PROP_IGNORE_USER_CONFIGURATION, Boolean.TRUE.toString());
+ return sharedConfig.toURL();
+ }
}
} catch (MalformedURLException e) {
return null;
@@ -116,6 +123,35 @@ public class SimpleConfiguratorImpl implements Configurator {
return null;
}
+ private long getLastKnownBundlesInfoBaseTimestamp(File configFolder) {
+ File storedSharedTimestamp = new File(configFolder, BASE_TIMESTAMP_FILE_BUNDLESINFO);
+ if (!storedSharedTimestamp.exists())
+ return NO_TIMESTAMP;
+
+ Properties p = new Properties();
+ InputStream is = null;
+ try {
+ try {
+ is = new BufferedInputStream(new FileInputStream(storedSharedTimestamp));
+ p.load(is);
+ if (p.get(KEY_BUNDLESINFO_TIMESTAMP) != null) {
+ return Long.valueOf((String) p.get(KEY_BUNDLESINFO_TIMESTAMP)).longValue();
+ }
+ } finally {
+ is.close();
+ }
+ } catch (IOException e) {
+ return NO_TIMESTAMP;
+ }
+ return NO_TIMESTAMP;
+ }
+
+ private long getCurrentBundlesInfoBaseTimestamp(File sharedBundlesInfo) {
+ if (!sharedBundlesInfo.exists())
+ return NO_TIMESTAMP;
+ return sharedBundlesInfo.lastModified();
+ }
+
public void applyConfiguration(URL url) throws IOException {
synchronized (configurationLock) {
if (Activator.DEBUG)