diff --git a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectPreferences.java b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectPreferences.java index 567801013..476f115a3 100644 --- a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectPreferences.java +++ b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectPreferences.java @@ -13,6 +13,7 @@ * Markus Schorn (Wind River) - [108066] Project prefs marked dirty on read * James Blackburn (Broadcom Corp.) - ongoing development * Lars Vogel - Bug 473427, 483529 + * Christoph Läubrich - Issue #124 *******************************************************************************/ package org.eclipse.core.internal.resources; @@ -66,6 +67,7 @@ public class ProjectPreferences extends EclipsePreferences { // cache private int segmentCount; + private Workspace workspace; static void deleted(IFile file) throws CoreException { IPath path = file.getFullPath(); @@ -191,7 +193,7 @@ private static Properties loadProperties(IFile file) throws BackingStoreExceptio } private static void preferencesChanged(IProject project) { - Workspace workspace = ((Workspace) ResourcesPlugin.getWorkspace()); + Workspace workspace = (Workspace) project.getWorkspace(); workspace.getCharsetManager().projectPreferencesChanged(project); workspace.getContentDescriptionManager().projectPreferencesChanged(project); } @@ -361,8 +363,9 @@ public ProjectPreferences() { super(null, null); } - private ProjectPreferences(EclipsePreferences parent, String name) { + private ProjectPreferences(EclipsePreferences parent, String name, Workspace workspace) { super(parent, name); + setWorkspace(workspace); // cache the segment count String path = absolutePath(); @@ -374,7 +377,7 @@ private ProjectPreferences(EclipsePreferences parent, String name) { // cache the project name String projectName = getSegment(path, 1); if (projectName != null) - project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + project = workspace.getRoot().getProject(projectName); // cache the qualifier if (segmentCount > 2) @@ -486,7 +489,7 @@ protected IPath getLocation() { @Override protected EclipsePreferences internalCreate(EclipsePreferences nodeParent, String nodeName, Object context) { - return new ProjectPreferences(nodeParent, nodeName); + return new ProjectPreferences(nodeParent, nodeName, getWorkspace()); } @Override @@ -507,7 +510,7 @@ protected String internalPut(String key, String newValue) { silentLoad(); if ((segmentCount == 3) && PREFS_REGULAR_QUALIFIER.equals(qualifier) && (project != null)) { if (ResourcesPlugin.PREF_SEPARATE_DERIVED_ENCODINGS.equals(key)) { - CharsetManager charsetManager = ((Workspace) ResourcesPlugin.getWorkspace()).getCharsetManager(); + CharsetManager charsetManager = getWorkspace().getCharsetManager(); if (Boolean.parseBoolean(newValue)) charsetManager.splitEncodingPreferences(project); else @@ -621,7 +624,7 @@ public boolean nodeExists(String path) throws BackingStoreException { return super.nodeExists(path); // if we are checking existance of a single segment child of /project, base the answer on // whether or not it exists in the workspace. - return ResourcesPlugin.getWorkspace().getRoot().getProject(path).exists() || super.nodeExists(path); + return getWorkspace().getRoot().getProject(path).exists() || super.nodeExists(path); } @Override @@ -632,7 +635,7 @@ public void remove(String key) { super.remove(key); if ((segmentCount == 3) && PREFS_REGULAR_QUALIFIER.equals(qualifier) && (project != null)) { if (ResourcesPlugin.PREF_SEPARATE_DERIVED_ENCODINGS.equals(key)) { - CharsetManager charsetManager = ((Workspace) ResourcesPlugin.getWorkspace()).getCharsetManager(); + CharsetManager charsetManager = getWorkspace().getCharsetManager(); if (ResourcesPlugin.DEFAULT_PREF_SEPARATE_DERIVED_ENCODINGS) charsetManager.splitEncodingPreferences(project); else @@ -720,8 +723,8 @@ protected void save() throws BackingStoreException { }; //don't bother with scheduling rules if we are already inside an operation try { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - if (((Workspace) workspace).getWorkManager().isLockAlreadyAcquired()) { + Workspace workspace = getWorkspace(); + if (workspace.getWorkManager().isLockAlreadyAcquired()) { operation.run(null); } else { IResourceRuleFactory factory = workspace.getRuleFactory(); @@ -756,4 +759,16 @@ private void silentLoad() { node.setLoading(false); } } + + public void setWorkspace(Workspace workspace) { + this.workspace = workspace; + } + + private Workspace getWorkspace() { + if (workspace != null) { + return workspace; + } + // last resort... + return (Workspace) ResourcesPlugin.getWorkspace(); + } } diff --git a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Workspace.java b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Workspace.java index 2df1c7292..bb1645c42 100644 --- a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Workspace.java +++ b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Workspace.java @@ -15,8 +15,7 @@ * Serge Beauchamp (Freescale Semiconductor) - [229633] Group and Project Path Variable Support * Broadcom Corporation - ongoing development * Lars Vogel - Bug 473427 - * Christoph Läubrich - Issue #77 - SaveManager access the ResourcesPlugin.getWorkspace at init phase - * - Issue #86 - Cyclic dependency between ProjectPreferences and Workspace init + * Christoph Läubrich - Issue #77, Issue #86, Issue #124 *******************************************************************************/ package org.eclipse.core.internal.resources; @@ -50,6 +49,7 @@ import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.osgi.util.NLS; import org.osgi.framework.Bundle; +import org.osgi.service.prefs.Preferences; import org.xml.sax.InputSource; /** @@ -1869,6 +1869,11 @@ private void initializePreferenceLookupOrder() { newOrder.add(ProjectScope.SCOPE); newOrder.addAll(Arrays.asList(original)); service.setDefaultDefaultLookupOrder(newOrder.toArray(new String[newOrder.size()])); + Preferences node = service.getRootNode().node(ProjectScope.SCOPE); + if (node instanceof ProjectPreferences) { + ProjectPreferences projectPreferences = (ProjectPreferences) node; + projectPreferences.setWorkspace(this); + } } /** @@ -2232,7 +2237,6 @@ public IStatus open(IProgressMonitor monitor) throws CoreException { if (!localMetaArea.hasSavedProjects()) { setExplicitWorkspaceEncoding(); } - initializePreferenceLookupOrder(); // create root location localMetaArea.locationFor(getRoot()).toFile().mkdirs(); @@ -2253,6 +2257,7 @@ public IStatus open(IProgressMonitor monitor) throws CoreException { //finally register a string pool participant stringPoolJob = new StringPoolJob(); stringPoolJob.addStringPoolParticipant(saveManager, getRoot()); + initializePreferenceLookupOrder(); return Status.OK_STATUS; }