Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSzymon Ptaszkiewicz2013-10-14 03:49:12 -0400
committerGerrit Code Review @ Eclipse.org2013-10-24 05:00:11 -0400
commitc9b101ad6019999bbc60789881427939c6977da2 (patch)
treed84d20930f87138f41ba1aa21c9e8f8ab92d988b
parent7e0b232400cb860bb566abe97003da0408e5e219 (diff)
downloadeclipse.platform.team-c9b101ad6019999bbc60789881427939c6977da2.tar.gz
eclipse.platform.team-c9b101ad6019999bbc60789881427939c6977da2.tar.xz
eclipse.platform.team-c9b101ad6019999bbc60789881427939c6977da2.zip
Bug 419228 - [Net] PreferenceModifyListener pollutes exported preferences
Change-Id: I2907c8cd1e9cd9a0a662c45652a69948e8cc75da Signed-off-by: Szymon Ptaszkiewicz <szymon.ptaszkiewicz@pl.ibm.com>
-rw-r--r--bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/PreferenceModifyListener.java20
-rw-r--r--tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/AllNetTests.java3
-rw-r--r--tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/PreferenceModifyListenerTest.java63
3 files changed, 80 insertions, 6 deletions
diff --git a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/PreferenceModifyListener.java b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/PreferenceModifyListener.java
index 0f5198221..57f9d3b4a 100644
--- a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/PreferenceModifyListener.java
+++ b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/PreferenceModifyListener.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
@@ -14,6 +14,7 @@ import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
public class PreferenceModifyListener extends
org.eclipse.core.runtime.preferences.PreferenceModifyListener {
@@ -23,11 +24,20 @@ public class PreferenceModifyListener extends
}
public IEclipsePreferences preApply(IEclipsePreferences node) {
+ // the node does not need to be the root of the hierarchy
+ Preferences root = node.node("/"); //$NON-NLS-1$
try {
- if (node.nodeExists(InstanceScope.SCOPE)) {
- ((ProxyManager)ProxyManager.getProxyManager()).migrateInstanceScopePreferences(
- node.node(InstanceScope.SCOPE).node(Activator.ID),
- node.node(ConfigurationScope.SCOPE).node(Activator.ID), false);
+ // we must not create empty preference nodes, so first check if the node exists
+ if (root.nodeExists(InstanceScope.SCOPE)) {
+ Preferences instance = root.node(InstanceScope.SCOPE);
+ // we must not create empty preference nodes, so first check if the node exists
+ if (instance.nodeExists(Activator.ID)) {
+ ((ProxyManager) ProxyManager.getProxyManager())
+ .migrateInstanceScopePreferences(
+ instance.node(Activator.ID),
+ root.node(ConfigurationScope.SCOPE).node(
+ Activator.ID), false);
+ }
}
} catch (BackingStoreException e) {
Activator.logError("Could not access instance preferences", e); //$NON-NLS-1$
diff --git a/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/AllNetTests.java b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/AllNetTests.java
index 3d2441984..d95358ade 100644
--- a/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/AllNetTests.java
+++ b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/AllNetTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 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
@@ -25,6 +25,7 @@ public class AllNetTests extends TestCase {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(NetTest.suite());
+ suite.addTest(PreferenceModifyListenerTest.suite());
return suite;
}
}
diff --git a/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/PreferenceModifyListenerTest.java b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/PreferenceModifyListenerTest.java
new file mode 100644
index 000000000..96fc9eb24
--- /dev/null
+++ b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/PreferenceModifyListenerTest.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *******************************************************************************/
+package org.eclipse.core.tests.net;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+
+import org.eclipse.core.internal.preferences.EclipsePreferences;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IExportedPreferences;
+import org.eclipse.core.runtime.preferences.IPreferencesService;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.osgi.service.prefs.BackingStoreException;
+
+public class PreferenceModifyListenerTest extends TestCase {
+ private static final String NODE_NAME = "bug419228";
+ private static final String KEY = "someKey";
+ private static final String VALUE = "someValue";
+
+ public static Test suite() {
+ return new PreferenceModifyListenerTest("testPreApply");
+ }
+
+ public PreferenceModifyListenerTest(String name) {
+ super(name);
+ }
+
+ public void testPreApply() throws BackingStoreException, CoreException {
+ // create a dummy node and export it to a stream
+ IEclipsePreferences toExport = InstanceScope.INSTANCE.getNode(NODE_NAME);
+ toExport.put(KEY, VALUE);
+ IPreferencesService service = Platform.getPreferencesService();
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ assertTrue(service.exportPreferences(toExport, stream, null).isOK());
+
+ // read preferences from a stream
+ IExportedPreferences exported = service.readPreferences(new ByteArrayInputStream(stream.toByteArray()));
+ exported = (IExportedPreferences) exported.node(InstanceScope.SCOPE).node(NODE_NAME);
+
+ // apply exported preferences to the global preferences hierarchy
+ assertTrue(service.applyPreferences(exported).isOK());
+
+ // verify that the node is not modified
+ String debugString = ((EclipsePreferences) exported.node("/")).toDeepDebugString();
+ assertFalse(debugString, exported.nodeExists("instance/org.eclipse.core.net"));
+ assertFalse(debugString, exported.nodeExists("/instance/org.eclipse.core.net"));
+ assertFalse(debugString, exported.nodeExists("configuration/org.eclipse.core.net"));
+ assertFalse(debugString, exported.nodeExists("/configuration/org.eclipse.core.net"));
+ }
+}

Back to the top