Skip to content

Commit

Permalink
Bug 572128: Move startup code into Workspace
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
alblue committed Mar 22, 2021
1 parent 69e424f commit a8a8d82
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1848,6 +1849,20 @@ protected void initializeMoveDeleteHook() {
}
}

/*
* 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.
Expand Down Expand Up @@ -2186,6 +2201,12 @@ protected long nextNodeId() {
* @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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -372,24 +372,6 @@ public ResourcesPlugin() {
plugin = this;
}

/**
* 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
Expand Down Expand Up @@ -477,15 +459,9 @@ public void start(BundleContext context) throws Exception {
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);
Expand All @@ -495,17 +471,4 @@ public void start(BundleContext context) throws Exception {
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()]));
}
}

0 comments on commit a8a8d82

Please sign in to comment.