Search in sources :

Example 1 with EclipsePreferences

use of org.eclipse.core.internal.preferences.EclipsePreferences in project polymap4-core by Polymap4.

the class ProjectPreferences method getLoadLevel.

/*
	 * Return the node at which these preferences are loaded/saved.
	 */
protected IEclipsePreferences getLoadLevel() {
    if (loadLevel == null) {
        if (project == null || qualifier == null)
            return null;
        // Make it relative to this node rather than navigating to it from the root.
        // Walk backwards up the tree starting at this node.
        // This is important to avoid a chicken/egg thing on startup.
        EclipsePreferences node = this;
        for (int i = 3; i < segmentCount; i++) node = (EclipsePreferences) node.parent();
        loadLevel = node;
    }
    return loadLevel;
}
Also used : EclipsePreferences(org.eclipse.core.internal.preferences.EclipsePreferences) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences)

Example 2 with EclipsePreferences

use of org.eclipse.core.internal.preferences.EclipsePreferences in project eclipse.platform.runtime by eclipse.

the class PreferencesServiceTest method verifyExportedPreferencesNotModified.

private void verifyExportedPreferencesNotModified(IExportedPreferences exported) throws BackingStoreException {
    Preferences node = exported;
    while (node.parent() != null) {
        node = node.parent();
    }
    String debugString = ((EclipsePreferences) node).toDeepDebugString();
    String[] children = node.childrenNames();
    assertEquals(debugString, 1, children.length);
    assertEquals(InstanceScope.SCOPE, children[0]);
    node = node.node(children[0]);
    children = node.childrenNames();
    assertEquals(debugString, 1, children.length);
    assertEquals("bug418046", children[0]);
    node = node.node(children[0]);
    children = node.childrenNames();
    assertEquals(debugString, 0, children.length);
    assertEquals(debugString, "someValue", node.get("someKey", null));
}
Also used : EclipsePreferences(org.eclipse.core.internal.preferences.EclipsePreferences) Preferences(org.osgi.service.prefs.Preferences) EclipsePreferences(org.eclipse.core.internal.preferences.EclipsePreferences)

Example 3 with EclipsePreferences

use of org.eclipse.core.internal.preferences.EclipsePreferences in project eclipse.platform.runtime by eclipse.

the class EclipsePreferencesTest method testFileFormat.

public void testFileFormat() {
    class Info {

        String path;

        String key;

        String encoded;

        Info(String path, String key, String encoded) {
            this.path = path;
            this.key = key;
            this.encoded = encoded;
        }
    }
    List<Info> list = new ArrayList<>();
    list.add(new Info("", "a", "a"));
    list.add(new Info("", "/a", "///a"));
    list.add(new Info("a", "b", "a/b"));
    list.add(new Info("a/b", "c/d", "a/b//c/d"));
    list.add(new Info("", "a//b", "//a//b"));
    list.add(new Info("a/b", "c", "a/b/c"));
    list.add(new Info("a/b", "c//d", "a/b//c//d"));
    Preferences node = new TestScope().getNode(getUniqueString());
    for (int i = 0; i < list.size(); i++) {
        Info info = list.get(i);
        node.node(info.path).put(info.key, Integer.toString(i));
    }
    assertTrue("0.8", node instanceof EclipsePreferences);
    Properties properties = null;
    try {
        properties = TestHelper.convertToProperties((EclipsePreferences) node, "");
    } catch (BackingStoreException e) {
        fail("1.0", e);
    }
    for (Object object : properties.keySet()) {
        String key = (String) object;
        String value = properties.getProperty(key);
        try {
            Info info = list.get(Integer.parseInt(value));
            assertNotNull("2.0", info);
            assertEquals("2.1." + key, info.encoded, key);
        } catch (NumberFormatException e) {
            fail("2.99." + value, e);
        }
    }
}
Also used : EclipsePreferences(org.eclipse.core.internal.preferences.EclipsePreferences) BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences) EclipsePreferences(org.eclipse.core.internal.preferences.EclipsePreferences)

Example 4 with EclipsePreferences

use of org.eclipse.core.internal.preferences.EclipsePreferences in project eclipse.platform.runtime by eclipse.

the class EclipsePreferencesTest method test_60590.

/*
	 * Bug 60590 - Flush on dirty child settings node fails if parent clean.
	 *
	 * After changing a preference value, we call #makeDirty which does a
	 * recursive call marking itself dirty as well as all its parents. As a short
	 * circuit, if a parent was already dirty then it stopped the recursion.
	 *
	 * Unfortuanatly the #makeClean method only marks the load level as
	 * clean and not all children since it doesn't know which child triggered
	 * the dirtiness.
	 *
	 * Changed the makeDirty call to mark all parent nodes as dirty.
	 */
public void test_60590() {
    IEclipsePreferences root = Platform.getPreferencesService().getRootNode();
    String one = getUniqueString();
    String two = getUniqueString();
    String threeA = getUniqueString();
    String threeB = getUniqueString();
    String key = "key";
    String value = "value";
    Preferences node = root.node(TestScope.SCOPE).node(one).node(two).node(threeA);
    node.put(key, value);
    try {
        node.flush();
    } catch (BackingStoreException e) {
        fail("1.99", e);
    }
    node = root.node(TestScope.SCOPE).node(one).node(two).node(threeB);
    node.put(key, value);
    Preferences current = node;
    int count = 0;
    while (current != null && current instanceof EclipsePreferences && current.parent() != null && new Path(current.absolutePath()).segment(0).equals(TestScope.SCOPE)) {
        assertTrue("1.0." + current.absolutePath(), ((EclipsePreferences) current).isDirty());
        count++;
        current = current.parent();
    }
    assertTrue("2.0." + count, count == 4);
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) EclipsePreferences(org.eclipse.core.internal.preferences.EclipsePreferences) Preferences(org.osgi.service.prefs.Preferences) EclipsePreferences(org.eclipse.core.internal.preferences.EclipsePreferences)

Aggregations

EclipsePreferences (org.eclipse.core.internal.preferences.EclipsePreferences)4 Preferences (org.osgi.service.prefs.Preferences)3 BackingStoreException (org.osgi.service.prefs.BackingStoreException)2 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1