blob: 71cffc4b094e3be22dc841c5c90785c3234563ff (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
/*******************************************************************************
* Copyright (c) 2012 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.internal.preferences;
import java.util.Properties;
import org.eclipse.core.internal.preferences.EclipsePreferences;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.tests.harness.CoreTest;
import org.osgi.service.prefs.BackingStoreException;
/*
* Test scope used for testing the file format on disk.
* Specifically in EclipsePreferencesTest.test_342709.
*/
public class TestScope2 extends EclipsePreferences implements IScopeContext {
public static final String SCOPE = "test2"; //$NON-NLS-1$
private String qualifier;
private int segmentCount;
private IEclipsePreferences loadLevel;
public static IPath baseLocation;
private IPath location;
static {
baseLocation = new CoreTest().getRandomLocation();
}
public TestScope2() {
this(null, null);
}
private TestScope2(EclipsePreferences parent, String key) {
super(parent, key);
// cache the segment count
IPath path = new Path(absolutePath());
segmentCount = path.segmentCount();
if (segmentCount < 2)
return;
// cache the qualifier
String scope = path.segment(0);
if (TestScope2.SCOPE.equals(scope))
qualifier = path.segment(1);
// cache the location
if (qualifier == null)
return;
}
protected IEclipsePreferences getLoadLevel() {
if (loadLevel == null) {
if (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.
IEclipsePreferences node = this;
for (int i = 2; i < segmentCount; i++)
node = (IEclipsePreferences) node.parent();
loadLevel = node;
}
return loadLevel;
}
public IPath getLocation() {
if (location == null) {
location = computeLocation(baseLocation, qualifier);
}
return location;
}
public String getName() {
return SCOPE;
}
public IEclipsePreferences getNode(String qualifier) {
return (IEclipsePreferences) Platform.getPreferencesService().getRootNode().node(SCOPE).node(qualifier);
}
protected EclipsePreferences internalCreate(EclipsePreferences nodeParent, String nodeName, Object context) {
return new TestScope2(nodeParent, nodeName);
}
void setDirty(boolean value) {
dirty = value;
}
Properties toProperties() throws BackingStoreException {
return convertToProperties(new Properties(), "");
}
}
|