summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault2013-01-11 08:15:20 (EST)
committerPascal Rapicault2013-01-11 08:15:55 (EST)
commite004dc5270abd33a60da9a8d0340409bc8e4a38d (patch)
tree3f657fa23eaccb1822035a8bfef7e8e4e90b46cb
parenta0235c0c95b9047e64d6e24c9d8f6b8588087113 (diff)
downloadrt.equinox.p2-e004dc5270abd33a60da9a8d0340409bc8e4a38d.zip
rt.equinox.p2-e004dc5270abd33a60da9a8d0340409bc8e4a38d.tar.gz
rt.equinox.p2-e004dc5270abd33a60da9a8d0340409bc8e4a38d.tar.bz2
ignore user config.ini if out of sync with base
-rw-r--r--bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwConfigFileParser.java24
-rw-r--r--bundles/org.eclipse.equinox.frameworkadmin.test/dataFile/sharedconfiguration/ignoreUserConfig/config.ini1
-rw-r--r--bundles/org.eclipse.equinox.frameworkadmin.test/dataFile/sharedconfiguration/ignoreUserConfig/user-config.ini3
-rw-r--r--bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/SharedConfigurationTest.java126
4 files changed, 138 insertions, 16 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 22d2e86..856ceee 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
@@ -201,6 +201,7 @@ public class EquinoxFwConfigFileParser {
if (inputFile.isDirectory())
throw new IllegalArgumentException(NLS.bind(Messages.exception_inputFileIsDirectory, inputFile));
+ boolean baseHasChanged = false;
//Initialize data structures
ConfigData configData = manipulator.getConfigData();
LauncherData launcherData = manipulator.getLauncherData();
@@ -213,7 +214,9 @@ public class EquinoxFwConfigFileParser {
// load shared configuration properties
Properties sharedConfigProperties = getSharedConfiguration(ParserUtils.getOSGiInstallArea(Arrays.asList(manipulator.getLauncherData().getProgramArgs()), props, manipulator.getLauncherData()), props.getProperty(EquinoxConstants.PROP_SHARED_CONFIGURATION_AREA));
if (sharedConfigProperties != null) {
- sharedConfigProperties.putAll(props);
+ baseHasChanged = hasBasedChanged(inputFile, manipulator, props);
+ if (!baseHasChanged)
+ sharedConfigProperties.putAll(props);
props = sharedConfigProperties;
}
@@ -225,7 +228,9 @@ public class EquinoxFwConfigFileParser {
//readLauncherPath(props, rootURI);
readp2DataArea(props, configArea);
readSimpleConfiguratorURL(props, configArea);
- readBundlesList(manipulator, ParserUtils.getOSGiInstallArea(Arrays.asList(launcherData.getProgramArgs()), props, launcherData).toURI(), props);
+
+ if (!baseHasChanged)
+ readBundlesList(manipulator, ParserUtils.getOSGiInstallArea(Arrays.asList(launcherData.getProgramArgs()), props, launcherData).toURI(), props);
readInitialStartLeve(configData, props);
readDefaultStartLevel(configData, props);
@@ -239,6 +244,21 @@ public class EquinoxFwConfigFileParser {
Log.log(LogService.LOG_INFO, NLS.bind(Messages.log_configFile, inputFile.getAbsolutePath()));
}
+ 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);
+ Properties timestamps;
+ try {
+ timestamps = loadProperties(timestampFile);
+ } catch (FileNotFoundException e) {
+ return false;
+ } catch (IOException e) {
+ return false;
+ }
+ return String.valueOf(sharedConfigIni.lastModified()).equals(timestamps.getProperty(KEY_CONFIG_TIMESTAMP));
+ }
+
private void readDefaultStartLevel(ConfigData configData, Properties props) {
if (props.getProperty(EquinoxConstants.PROP_BUNDLES_STARTLEVEL) != null)
configData.setInitialBundleStartLevel(Integer.parseInt(props.getProperty(EquinoxConstants.PROP_BUNDLES_STARTLEVEL)));
diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/dataFile/sharedconfiguration/ignoreUserConfig/config.ini b/bundles/org.eclipse.equinox.frameworkadmin.test/dataFile/sharedconfiguration/ignoreUserConfig/config.ini
new file mode 100644
index 0000000..cb5fd86
--- /dev/null
+++ b/bundles/org.eclipse.equinox.frameworkadmin.test/dataFile/sharedconfiguration/ignoreUserConfig/config.ini
@@ -0,0 +1 @@
+sharedKey=sharedValue \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/dataFile/sharedconfiguration/ignoreUserConfig/user-config.ini b/bundles/org.eclipse.equinox.frameworkadmin.test/dataFile/sharedconfiguration/ignoreUserConfig/user-config.ini
new file mode 100644
index 0000000..8797ba5
--- /dev/null
+++ b/bundles/org.eclipse.equinox.frameworkadmin.test/dataFile/sharedconfiguration/ignoreUserConfig/user-config.ini
@@ -0,0 +1,3 @@
+osgi.sharedConfiguration.area=file\:configuration/
+userKey=userValue
+
diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/SharedConfigurationTest.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/SharedConfigurationTest.java
index 134d7be..0d0eba5 100644
--- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/SharedConfigurationTest.java
+++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/SharedConfigurationTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 IBM Corporation and others.
+ * Copyright (c) 2008, 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,20 +7,29 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Ericsson AB (Pascal Rapicault) - Improve shared install
*******************************************************************************/
package org.eclipse.equinox.frameworkadmin.tests;
-import java.io.File;
-import java.io.IOException;
+import java.io.*;
+import java.net.URISyntaxException;
+import java.util.Properties;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.URIUtil;
+import org.eclipse.equinox.frameworkadmin.BundleInfo;
+import org.eclipse.equinox.internal.frameworkadmin.equinox.Log;
+import org.eclipse.equinox.internal.frameworkadmin.equinox.Messages;
import org.eclipse.equinox.internal.provisional.frameworkadmin.*;
+import org.eclipse.osgi.util.NLS;
import org.osgi.framework.BundleException;
+import org.osgi.service.log.LogService;
public class SharedConfigurationTest extends AbstractFwkAdminTest {
public SharedConfigurationTest(String name) {
super(name);
}
-
+
public void testDefaultConfiguration() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException {
startSimpleConfiguratorManipulator();
FrameworkAdmin fwkAdmin = getEquinoxFrameworkAdmin();
@@ -30,19 +39,19 @@ public class SharedConfigurationTest extends AbstractFwkAdminTest {
File defaultConfigurationFolder = new File(installFolder, "configuration");
defaultConfigurationFolder.mkdirs();
copy("creating shared config.ini", getTestData("", "dataFile/sharedconfiguration/config.ini"), new File(defaultConfigurationFolder, "config.ini"));
-
+
String launcherName = "foo";
LauncherData launcherData = manipulator.getLauncherData();
launcherData.setFwConfigLocation(defaultConfigurationFolder);
launcherData.setLauncher(new File(installFolder, launcherName));
-
+
try {
manipulator.load();
} catch (IllegalStateException e) {
//TODO We ignore the framework JAR location not set exception
}
-
+
assertEquals("false", manipulator.getConfigData().getProperty("config.shared"));
assertEquals("true", manipulator.getConfigData().getProperty("from.parent"));
}
@@ -59,23 +68,23 @@ public class SharedConfigurationTest extends AbstractFwkAdminTest {
File userConfigurationFolder = new File(installFolder, "user/configuration");
userConfigurationFolder.mkdirs();
copy("creating shared config.ini", getTestData("", "dataFile/sharedconfiguration/user-config.ini"), new File(userConfigurationFolder, "config.ini"));
-
+
String launcherName = "foo";
LauncherData launcherData = manipulator.getLauncherData();
launcherData.setFwConfigLocation(userConfigurationFolder);
launcherData.setLauncher(new File(installFolder, launcherName));
-
+
try {
manipulator.load();
} catch (IllegalStateException e) {
//TODO We ignore the framework JAR location not set exception
}
-
+
assertEquals("true", manipulator.getConfigData().getProperty("config.shared"));
assertEquals("true", manipulator.getConfigData().getProperty("from.parent"));
}
-
+
public void testNotSharedConfiguration() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException {
startSimpleConfiguratorManipulator();
FrameworkAdmin fwkAdmin = getEquinoxFrameworkAdmin();
@@ -88,20 +97,109 @@ public class SharedConfigurationTest extends AbstractFwkAdminTest {
File userConfigurationFolder = new File(installFolder, "user/configuration");
userConfigurationFolder.mkdirs();
copy("creating shared config.ini", getTestData("", "dataFile/sharedconfiguration/user-noshare-config.ini"), new File(userConfigurationFolder, "config.ini"));
-
+
String launcherName = "foo";
LauncherData launcherData = manipulator.getLauncherData();
launcherData.setFwConfigLocation(userConfigurationFolder);
launcherData.setLauncher(new File(installFolder, launcherName));
-
+
try {
manipulator.load();
} catch (IllegalStateException e) {
//TODO We ignore the framework JAR location not set exception
}
-
+
assertEquals("false", manipulator.getConfigData().getProperty("config.shared"));
assertEquals(null, manipulator.getConfigData().getProperty("from.parent"));
}
+
+ public void testConfigIniTimestamp() throws BundleException, FrameworkAdminRuntimeException, IOException, URISyntaxException {
+ startSimpleConfiguratorManipulator();
+ FrameworkAdmin fwkAdmin = getEquinoxFrameworkAdmin();
+ Manipulator manipulator = fwkAdmin.getManipulator();
+
+ File installFolder = Activator.getContext().getDataFile(SharedConfigurationTest.class.getName());
+ File defaultConfigurationFolder = new File(installFolder, "configuration");
+ defaultConfigurationFolder.mkdirs();
+ copy("creating shared config.ini", getTestData("", "dataFile/sharedconfiguration/config.ini"), new File(defaultConfigurationFolder, "config.ini"));
+ File userConfigurationFolder = new File(installFolder, "user/configuration");
+ userConfigurationFolder.mkdirs();
+ copy("creating shared config.ini", getTestData("", "dataFile/sharedconfiguration/user-config.ini"), new File(userConfigurationFolder, "config.ini"));
+
+ String launcherName = "foo";
+
+ LauncherData launcherData = manipulator.getLauncherData();
+ launcherData.setFwConfigLocation(userConfigurationFolder);
+ launcherData.setLauncher(new File(installFolder, launcherName));
+
+ try {
+ manipulator.load();
+ } catch (IllegalStateException e) {
+ //TODO We ignore the framework JAR location not set exception
+ }
+
+ BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", URIUtil.toURI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar"))), 0, true);
+ BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", URIUtil.toURI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar"))), 1, true);
+
+ manipulator.getConfigData().addBundle(osgiBi);
+ manipulator.getConfigData().addBundle(configuratorBi);
+
+ manipulator.save(false);
+ File baseTimestamp = new File(userConfigurationFolder, ".baseTimestamps");
+ assertIsFile(baseTimestamp);
+ assertContent(baseTimestamp, Long.toString(new File(defaultConfigurationFolder, "config.ini").lastModified()));
+ }
+
+ public void testConfigurationIgnoredWhenChanged() throws BundleException, FrameworkAdminRuntimeException, IOException {
+ startSimpleConfiguratorManipulator();
+ FrameworkAdmin fwkAdmin = getEquinoxFrameworkAdmin();
+ Manipulator manipulator = fwkAdmin.getManipulator();
+
+ //setup the files
+ File installFolder = Activator.getContext().getDataFile(SharedConfigurationTest.class.getName());
+ File defaultConfigurationFolder = new File(installFolder, "configuration");
+ defaultConfigurationFolder.mkdirs();
+ copy("creating shared config.ini", getTestData("", "dataFile/sharedconfiguration/ignoreUserConfig/config.ini"), new File(defaultConfigurationFolder, "config.ini"));
+ File userConfigurationFolder = new File(installFolder, "user/configuration");
+ userConfigurationFolder.mkdirs();
+ copy("creating shared config.ini", getTestData("", "dataFile/sharedconfiguration/ignoreUserConfig/user-config.ini"), new File(userConfigurationFolder, "config.ini"));
+
+ //setup the timestamp
+ Properties p = new Properties();
+ p.setProperty("configIniTimestamp", Long.toString(new File(defaultConfigurationFolder, "config.ini").lastModified()));
+ saveProperties(new File(userConfigurationFolder, ".baseTimestamps"), p);
+
+ String launcherName = "foo";
+
+ LauncherData launcherData = manipulator.getLauncherData();
+ launcherData.setFwConfigLocation(userConfigurationFolder);
+ launcherData.setLauncher(new File(installFolder, launcherName));
+
+ try {
+ manipulator.load();
+ } catch (IllegalStateException e) {
+ //TODO We ignore the framework JAR location not set exception
+ }
+
+ assertNull(manipulator.getConfigData().getProperty("userKey"));
+ assertEquals("sharedValue", manipulator.getConfigData().getProperty("sharedKey"));
+ }
+
+ private void saveProperties(File outputFile, Properties configProps) throws IOException {
+ String header = "This configuration file was written by: " + this.getClass().getName(); //$NON-NLS-1$
+ FileOutputStream out = null;
+ try {
+ out = new FileOutputStream(outputFile);
+ configProps.store(out, header);
+ Log.log(LogService.LOG_INFO, NLS.bind(Messages.log_propertiesSaved, outputFile));
+ } finally {
+ try {
+ out.flush();
+ out.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
}