Bug 572128: Move startup code into Workspace The start code for the plugin can be migrated to run inside Workspace without changing existing behaviour. Change-Id: Ifef1711b809344a6ddee0f9f68c9c6deee81f671 Signed-off-by: Alex Blewitt <alex.blewitt@gmail.com>
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 8d9ecab..9c4b4a6 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
@@ -30,6 +30,7 @@ import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.internal.events.*; import org.eclipse.core.internal.localstore.FileSystemResourceManager; +import org.eclipse.core.internal.preferences.PreferencesService; import org.eclipse.core.internal.properties.IPropertyManager; import org.eclipse.core.internal.properties.PropertyManager2; import org.eclipse.core.internal.refresh.RefreshManager; @@ -1848,6 +1849,20 @@ } } + /* + * Add the project scope to the preference service's default look-up order so + * people get it for free + */ + private void initializePreferenceLookupOrder() { + PreferencesService service = PreferencesService.getDefault(); + String[] original = service.getDefaultDefaultLookupOrder(); + List<String> newOrder = new ArrayList<>(); + // put the project scope first on the list + newOrder.add(ProjectScope.SCOPE); + newOrder.addAll(Arrays.asList(original)); + service.setDefaultDefaultLookupOrder(newOrder.toArray(new String[newOrder.size()])); + } + /** * A team hook hasn't been initialized. Check the extension point and * try to create a new hook if a user has one defined as an extension. @@ -2186,6 +2201,12 @@ * @see ResourcesPlugin#getWorkspace() */ public IStatus open(IProgressMonitor monitor) throws CoreException { + if (!localMetaArea.hasSavedWorkspace()) { + localMetaArea.createMetaArea(); + } + PlatformURLResourceConnection.startup(getRoot().getLocation()); + initializePreferenceLookupOrder(); + // This method is not inside an operation because it is the one responsible for // creating the WorkManager object (who takes care of operations). String message = Messages.resources_workspaceOpen;
diff --git a/bundles/org.eclipse.core.resources/src/org/eclipse/core/resources/ResourcesPlugin.java b/bundles/org.eclipse.core.resources/src/org/eclipse/core/resources/ResourcesPlugin.java index 636b3a8..0b06c2f 100644 --- a/bundles/org.eclipse.core.resources/src/org/eclipse/core/resources/ResourcesPlugin.java +++ b/bundles/org.eclipse.core.resources/src/org/eclipse/core/resources/ResourcesPlugin.java
@@ -18,9 +18,9 @@ *******************************************************************************/ package org.eclipse.core.resources; -import java.util.*; -import org.eclipse.core.internal.preferences.PreferencesService; -import org.eclipse.core.internal.resources.*; +import java.util.Hashtable; +import org.eclipse.core.internal.resources.CheckMissingNaturesListener; +import org.eclipse.core.internal.resources.Workspace; import org.eclipse.core.internal.utils.Messages; import org.eclipse.core.internal.utils.Policy; import org.eclipse.core.runtime.*; @@ -373,24 +373,6 @@ } /** - * Constructs a brand new workspace structure at the location in the local file system - * identified by the given path and returns a new workspace object. - * - * @exception CoreException if the workspace structure could not be constructed. - * Reasons include: - * <ul> - * <li> There is an existing workspace structure on at the given location - * in the local file system. - * <li> A file exists at the given location in the local file system. - * <li> A directory could not be created at the given location in the - * local file system. - * </ul> - */ - private static void constructWorkspace() throws CoreException { - new LocalMetaArea().createMetaArea(); - } - - /** * Returns the encoding to use when reading text files in the workspace. * This is the value of the <code>PREF_ENCODING</code> preference, or the * file system encoding (<code>System.getProperty("file.encoding")</code>) @@ -477,15 +459,9 @@ Hashtable<String, String> properties = new Hashtable<>(2); properties.put(DebugOptions.LISTENER_SYMBOLICNAME, PI_RESOURCES); debugRegistration = context.registerService(DebugOptionsListener.class, Policy.RESOURCES_DEBUG_OPTIONS_LISTENER, properties); - - if (!new LocalMetaArea().hasSavedWorkspace()) { - constructWorkspace(); - } // Remember workspace before opening, to // make it easier to debug cases where open() is failing. workspace = new Workspace(); - PlatformURLResourceConnection.startup(workspace.getRoot().getLocation()); - initializePreferenceLookupOrder(); IStatus result = workspace.open(null); if (!result.isOK()) getLog().log(result); @@ -495,17 +471,4 @@ InstanceScope.INSTANCE.getNode(PI_RESOURCES).addPreferenceChangeListener(checkMissingNaturesListener); } - /* - * Add the project scope to the preference service's default look-up order so - * people get it for free - */ - private void initializePreferenceLookupOrder() { - PreferencesService service = PreferencesService.getDefault(); - String[] original = service.getDefaultDefaultLookupOrder(); - List<String> newOrder = new ArrayList<>(); - // put the project scope first on the list - newOrder.add(ProjectScope.SCOPE); - newOrder.addAll(Arrays.asList(original)); - service.setDefaultDefaultLookupOrder(newOrder.toArray(new String[newOrder.size()])); - } }