diff options
author | Thomas Watson | 2016-02-23 13:32:48 +0000 |
---|---|---|
committer | Thomas Watson | 2016-02-23 13:33:36 +0000 |
commit | da99d5b3806f3d032aa7c99352dc0bd308712e28 (patch) | |
tree | 05f288078a24292311e97cf9e6ef28ad9acf7608 | |
parent | aa864e5f2a415ddaca85c0dcb7d2f2a97b9a2782 (diff) | |
download | rt.equinox.framework-da99d5b3806f3d032aa7c99352dc0bd308712e28.tar.gz rt.equinox.framework-da99d5b3806f3d032aa7c99352dc0bd308712e28.tar.xz rt.equinox.framework-da99d5b3806f3d032aa7c99352dc0bd308712e28.zip |
Bug 487165 - Framework should read the parent configuration config.ini
file
Change-Id: I4d0b8c2ea4e954b895c29d7a29fd9c3ad89cd3f7
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
2 files changed, 49 insertions, 5 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/CascadeConfigTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/CascadeConfigTests.java index 81fb8b2a8..7e1f65825 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/CascadeConfigTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/CascadeConfigTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2013 IBM Corporation and others. + * Copyright (c) 2008, 2016 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 @@ -11,12 +11,14 @@ package org.eclipse.osgi.tests.bundles; import java.io.File; +import java.io.FileOutputStream; import java.util.*; import junit.framework.Test; import junit.framework.TestSuite; import org.eclipse.osgi.launch.Equinox; import org.eclipse.osgi.tests.OSGiTestsActivator; import org.osgi.framework.*; +import org.osgi.framework.launch.Framework; import org.osgi.framework.wiring.FrameworkWiring; public class CascadeConfigTests extends AbstractBundleTests { @@ -142,4 +144,41 @@ public class CascadeConfigTests extends AbstractBundleTests { equinox.waitForStop(10000); } + public void testCascadeConfigIni() throws Exception { + // First create a framework with the 'parent' configuration + File configParent = OSGiTestsActivator.getContext().getDataFile(getName() + "_parent"); + configParent.mkdirs(); + File parentConfigIni = new File(configParent, "config.ini"); + + Properties parentProps = new Properties(); + parentProps.put("parent.key", "parent"); + parentProps.put("parent.child.key", "parent"); + + parentProps.store(new FileOutputStream(parentConfigIni), "Parent config.ini"); + + // Now create a child framework and make sure bundle is there + File configChild = OSGiTestsActivator.getContext().getDataFile(getName() + "_child"); + configChild.mkdirs(); + File childConfigIni = new File(configChild, "config.ini"); + + Properties childProps = new Properties(); + childProps.put("parent.child.key", "child"); + childProps.put("child.key", "child"); + childProps.store(new FileOutputStream(childConfigIni), "Parent config.ini"); + Map<String, Object> childMap = new HashMap<String, Object>(); + childMap.put(Constants.FRAMEWORK_STORAGE, configChild.getAbsolutePath()); + childMap.put("osgi.sharedConfiguration.area", configParent.getCanonicalPath()); + + Framework equinox = new Equinox(childMap); + equinox.init(); + + BundleContext systemContext = equinox.getBundleContext(); + + assertEquals("Wrong value for parent.key", "parent", systemContext.getProperty("parent.key")); + assertEquals("Wrong value for parent.child.key", "child", systemContext.getProperty("parent.child.key")); + assertEquals("Wrong value for child.key", "child", systemContext.getProperty("child.key")); + + equinox.stop(); + equinox.waitForStop(10000); + } } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java index 5c05ac31e..38c1f4e82 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java @@ -477,7 +477,8 @@ public class EquinoxConfiguration implements EnvironmentInfo { // We use an AttomicBoolean to hold the setting so we can set it after the config.ini has been loaded AtomicBoolean debugLocations = new AtomicBoolean(); this.equinoxLocations = new EquinoxLocations(this.configValues, this.hookRegistry.getContainer(), debugLocations); - this.configValues.loadConfigIni(getConfigIni(equinoxLocations)); + this.configValues.loadConfigIni(getConfigIni(equinoxLocations, false)); + this.configValues.loadConfigIni(getConfigIni(equinoxLocations, true)); this.configValues.finalizeValues(); this.debugOptions = new FrameworkDebugOptions(this); @@ -553,12 +554,16 @@ public class EquinoxConfiguration implements EnvironmentInfo { } } - private URL getConfigIni(EquinoxLocations equinoxLocations2) { + private URL getConfigIni(EquinoxLocations locations, boolean parent) { if (Boolean.TRUE.toString().equals(getConfiguration(EquinoxConfiguration.PROP_IGNORE_USER_CONFIGURATION))) return null; - Location configArea = equinoxLocations.getConfigurationLocation(); - if (configArea == null) + Location configArea = locations.getConfigurationLocation(); + if (configArea != null && parent) { + configArea = configArea.getParentLocation(); + } + if (configArea == null) { return null; + } try { return new URL(configArea.getURL().toExternalForm() + CONFIG_FILE); } catch (MalformedURLException e) { |