Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer registering SaveParticipant until IWorkspace service is available #752

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

import org.eclipse.core.resources.ISaveContext;
import org.eclipse.core.resources.ISaveParticipant;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IAdapterManager;
Expand Down Expand Up @@ -76,6 +76,8 @@
import org.eclipse.debug.internal.core.sourcelookup.SourceLookupUtils;
import org.eclipse.osgi.service.environment.Constants;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -436,6 +438,11 @@ public class DebugPlugin extends Plugin {
*/
private HashMap<String, IConfigurationElement> fProcessFactories = null;

/**
* Service tracker for the workspace service
*/
private ServiceTracker<IWorkspace, IWorkspace> fWorkspaceServiceTracker = null;

/**
* Mode constants for the event notifier
*/
Expand Down Expand Up @@ -716,7 +723,8 @@ public void stop(BundleContext context) throws Exception {

SourceLookupUtils.shutdown();
Preferences.savePreferences(DebugPlugin.getUniqueIdentifier());
ResourcesPlugin.getWorkspace().removeSaveParticipant(getUniqueIdentifier());
fWorkspaceServiceTracker.getService().removeSaveParticipant(getUniqueIdentifier());
fWorkspaceServiceTracker.close();
} finally {
super.stop(context);
setDefault(null);
Expand All @@ -727,22 +735,43 @@ public void stop(BundleContext context) throws Exception {
public void start(BundleContext context) throws Exception {
super.start(context);
new DebugOptions(context);
ResourcesPlugin.getWorkspace().addSaveParticipant(getUniqueIdentifier(),
new ISaveParticipant() {
@Override
public void saving(ISaveContext saveContext) throws CoreException {
if (fExpressionManager != null) {
fExpressionManager.storeWatchExpressions();

fWorkspaceServiceTracker = new ServiceTracker<>(context, IWorkspace.class, null) {
laeubi marked this conversation as resolved.
Show resolved Hide resolved

@Override
public IWorkspace addingService(ServiceReference<IWorkspace> reference) {
IWorkspace workspace = super.addingService(reference);
try {
workspace.addSaveParticipant(getUniqueIdentifier(), new ISaveParticipant() {
kwin marked this conversation as resolved.
Show resolved Hide resolved
@Override
public void saving(ISaveContext saveContext) throws CoreException {
if (fExpressionManager != null) {
fExpressionManager.storeWatchExpressions();
}
Preferences.savePreferences(DebugPlugin.getUniqueIdentifier());
}
Preferences.savePreferences(DebugPlugin.getUniqueIdentifier());
}
@Override
public void rollback(ISaveContext saveContext) {}
@Override
public void prepareToSave(ISaveContext saveContext) throws CoreException {}
@Override
public void doneSaving(ISaveContext saveContext) {}
});

@Override
public void rollback(ISaveContext saveContext) {
}

@Override
public void prepareToSave(ISaveContext saveContext) throws CoreException {
}

@Override
public void doneSaving(ISaveContext saveContext) {
}
});
} catch (CoreException e) {
log(e.getStatus());
kwin marked this conversation as resolved.
Show resolved Hide resolved
}
return workspace;
}

};
fWorkspaceServiceTracker.open();

//command adapters
IAdapterManager manager= Platform.getAdapterManager();
CommandAdapterFactory actionFactory = new CommandAdapterFactory();
Expand Down
Loading