Debian Codegraph @

bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SharedProfilePreferences.java

raw
1 /*******************************************************************************
2 * Copyright (c) 2012, 2017 Ericsson AB and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 * Ericsson AB - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.equinox.internal.p2.engine;
15
16 import org.eclipse.core.internal.preferences.EclipsePreferences;
17 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
18 import org.eclipse.equinox.p2.core.IProvisioningAgent;
19 import org.osgi.service.prefs.BackingStoreException;
20
21 /**
22 * A preference implementation that stores preferences in the engine's profile
23 * data area. There is one preference file per profile, with an additional file
24 * that is used when there is no currently running profile.
25 */
26 public class SharedProfilePreferences extends ProfilePreferences {
27 public SharedProfilePreferences() {
28 this(null, null);
29 }
30
31 public SharedProfilePreferences(EclipsePreferences nodeParent, String nodeName) {
32 super(nodeParent, nodeName);
33
34 //path is /profile/shared/{agent location}/{profile id}/qualifier
35
36 // cache the segment count
37 String path = absolutePath();
38 segmentCount = getSegmentCount(path);
39
40 if (segmentCount <= 3)
41 return;
42
43 if (segmentCount == 4)
44 profileLock = new Object();
45
46 if (segmentCount < 5)
47 return;
48 // cache the qualifier
49 qualifier = getQualifierSegment();
50 }
51
52 @Override
53 protected IProvisioningAgent getAgent(String segment) throws BackingStoreException {
54 IProvisioningAgent agent = super.getAgent(segment);
55 return (IProvisioningAgent) agent.getService(IProvisioningAgent.SHARED_BASE_AGENT);
56 }
57
58 @Override
59 protected void doSave(IProvisioningAgent agent) throws BackingStoreException {
60 throw new BackingStoreException("Can't store in shared install"); //$NON-NLS-1$
61 }
62
63 @Override
64 protected EclipsePreferences internalCreate(EclipsePreferences nodeParent, String nodeName, Object context) {
65 return new SharedProfilePreferences(nodeParent, nodeName);
66 }
67
68 @Override
69 protected IEclipsePreferences getLoadLevel() {
70 if (loadLevel == null) {
71 if (qualifier == null)
72 return null;
73 // Make it relative to this node rather than navigating to it from the root.
74 // Walk backwards up the tree starting at this node.
75 // This is important to avoid a chicken/egg thing on startup.
76 IEclipsePreferences node = this;
77 for (int i = 5; i < segmentCount; i++)
78 node = (EclipsePreferences) node.parent();
79 loadLevel = node;
80 }
81 return loadLevel;
82 }
83
84 @Override
85 protected synchronized void save() throws BackingStoreException {
86 throw new BackingStoreException("Can't store in shared install");
87 }
88
89 @Override
90 protected String getQualifierSegment() {
91 return getSegment(absolutePath(), 4);
92 }
93
94 @Override
95 protected String getProfileIdSegment() {
96 return getSegment(absolutePath(), 3);
97 }
98
99 @Override
100 protected String getAgentLocationSegment() {
101 return getSegment(absolutePath(), 2);
102 }
103 }