diff options
| author | Esteban Dugueperoux | 2015-02-20 11:08:32 +0000 |
|---|---|---|
| committer | Esteban DUGUEPEROUX | 2015-02-25 13:04:33 +0000 |
| commit | 287cbe05bdac112d652dd5253cb28f58244f5c4d (patch) | |
| tree | 2bcdb03911bf11ebb3f77efe54f51a655c0d275c | |
| parent | a420549a1c41f2a5a2ca9e4d22976c46e579b6c8 (diff) | |
| download | org.eclipse.sirius-287cbe05bdac112d652dd5253cb28f58244f5c4d.tar.gz org.eclipse.sirius-287cbe05bdac112d652dd5253cb28f58244f5c4d.tar.xz org.eclipse.sirius-287cbe05bdac112d652dd5253cb28f58244f5c4d.zip | |
[452962] Make session creation and opening possible in standalone
Make session creation and opening possible in standalone to have my
JUnit test runnable in standalone.
Bug: 452962
Change-Id: I2a7df2449c2c6ea2e36717e34016420c8f16e2be
Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
15 files changed, 291 insertions, 219 deletions
diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/resource/ResourceSetSync.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/resource/ResourceSetSync.java index 8740f26443..27e41b6581 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/resource/ResourceSetSync.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/resource/ResourceSetSync.java @@ -22,6 +22,7 @@ import java.util.Map.Entry; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; @@ -30,6 +31,7 @@ import org.eclipse.emf.common.notify.impl.AdapterImpl; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.plugin.EcorePlugin; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.URIConverter; @@ -243,7 +245,10 @@ public final class ResourceSetSync extends ResourceSetListenerImpl implements Re } private void addDefaultBackends() { - backends.add(new WorkspaceBackend(this)); + IWorkspaceRoot workspaceRoot = EcorePlugin.getWorkspaceRoot(); + if (workspaceRoot != null) { + backends.add(new WorkspaceBackend(this)); + } } private ResourceStatus getResourceStatus(final Resource res) { @@ -486,12 +491,12 @@ public final class ResourceSetSync extends ResourceSetListenerImpl implements Re private void doSave(final Iterable<Resource> resourcesToSave, final Map<?, ?> saveOptions, Collection<ResourceStatusChange> changesToTransmit) throws InterruptedException, IOException { final Collection<IFile> files2Validate = Lists.newArrayList(); - final Iterator<Resource> it = resourcesToSave.iterator(); - while (it.hasNext()) { - final Resource nextResource = it.next(); - final IFile file = WorkspaceSynchronizer.getFile(nextResource); - if (file != null && file.isReadOnly()) { - files2Validate.add(file); + for (Resource resourceToSave : resourcesToSave) { + if (resourceToSave.getURI().isPlatformResource()) { + IFile file = WorkspaceSynchronizer.getFile(resourceToSave); + if (file != null && file.isReadOnly()) { + files2Validate.add(file); + } } } diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/EclipseUtil.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/EclipseUtil.java index ec46ccd3c9..a057b7ddb1 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/EclipseUtil.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/EclipseUtil.java @@ -18,15 +18,15 @@ import java.util.Map; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceVisitor; -import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.Platform; +import org.eclipse.emf.common.EMFPlugin; +import org.eclipse.emf.ecore.plugin.EcorePlugin; import org.eclipse.sirius.common.tools.DslCommonPlugin; import com.google.common.base.Objects; @@ -123,27 +123,27 @@ public final class EclipseUtil { */ private static <T> List<T> getExtensionPlugins(final Class<T> clazz, final String extensionId, final String executableAttribute, final String attributeName, final Predicate<String> attributeValuePredicate) { + final List<T> contributors = new ArrayList<T>(); + if (EMFPlugin.IS_ECLIPSE_RUNNING) { + final IExtension[] extensions = EclipseUtil.getExtensions(extensionId); + for (final IExtension ext : extensions) { + final IConfigurationElement[] ce = ext.getConfigurationElements(); + for (IConfigurationElement element : ce) { - final IExtension[] extensions = EclipseUtil.getExtensions(extensionId); - final List<T> contributors = new ArrayList<T>(extensions.length); - - for (final IExtension ext : extensions) { - final IConfigurationElement[] ce = ext.getConfigurationElements(); - for (IConfigurationElement element : ce) { - - if (EclipseUtil.checkAttribute(element, attributeName, attributeValuePredicate)) { - Object obj; - try { - obj = element.createExecutableExtension(executableAttribute); - if (clazz.isInstance(obj)) { - contributors.add(clazz.cast(obj)); + if (EclipseUtil.checkAttribute(element, attributeName, attributeValuePredicate)) { + Object obj; + try { + obj = element.createExecutableExtension(executableAttribute); + if (clazz.isInstance(obj)) { + contributors.add(clazz.cast(obj)); + } + } catch (final CoreException e) { + DslCommonPlugin.getDefault().error("Impossible to load the extension " + ext.getLabel(), e); + DslCommonPlugin.getDefault().getLog().log(e.getStatus()); } - } catch (final CoreException e) { - DslCommonPlugin.getDefault().error("Impossible to load the extension " + ext.getLabel(), e); - DslCommonPlugin.getDefault().getLog().log(e.getStatus()); } - } + } } } return contributors; @@ -171,36 +171,37 @@ public final class EclipseUtil { * @since 1.0.0M7 */ public static <T> Map<String, Collection<T>> getExtensionPluginsByKey(Class<T> clazz, String extensionId, String executableAttribute, String keyAttributeName) { - final IExtension[] extensions = EclipseUtil.getExtensions(extensionId); final Map<String, Collection<T>> contributors = Maps.newLinkedHashMap(); + if (EMFPlugin.IS_ECLIPSE_RUNNING) { + final IExtension[] extensions = EclipseUtil.getExtensions(extensionId); + for (final IExtension ext : extensions) { + final IConfigurationElement[] ce = ext.getConfigurationElements(); + for (IConfigurationElement element : ce) { - for (final IExtension ext : extensions) { - final IConfigurationElement[] ce = ext.getConfigurationElements(); - for (IConfigurationElement element : ce) { - - if (EclipseUtil.checkAttribute(element, keyAttributeName, Predicates.<String> alwaysTrue())) { - Object obj; - try { - obj = element.createExecutableExtension(executableAttribute); - if (clazz.isInstance(obj)) { - String key = null; - if (keyAttributeName != null) { - key = element.getAttribute(keyAttributeName); - } - key = Objects.firstNonNull(key, ""); - Collection<T> val = contributors.get(key); - if (val == null) { - val = Lists.newArrayList(); - contributors.put(key, val); + if (EclipseUtil.checkAttribute(element, keyAttributeName, Predicates.<String> alwaysTrue())) { + Object obj; + try { + obj = element.createExecutableExtension(executableAttribute); + if (clazz.isInstance(obj)) { + String key = null; + if (keyAttributeName != null) { + key = element.getAttribute(keyAttributeName); + } + key = Objects.firstNonNull(key, ""); + Collection<T> val = contributors.get(key); + if (val == null) { + val = Lists.newArrayList(); + contributors.put(key, val); + } + val.add(clazz.cast(obj)); } - val.add(clazz.cast(obj)); + } catch (final CoreException e) { + DslCommonPlugin.getDefault().error("Impossible to load the extension " + ext.getLabel(), e); + DslCommonPlugin.getDefault().getLog().log(e.getStatus()); } - } catch (final CoreException e) { - DslCommonPlugin.getDefault().error("Impossible to load the extension " + ext.getLabel(), e); - DslCommonPlugin.getDefault().getLog().log(e.getStatus()); } - } + } } } return contributors; @@ -246,27 +247,44 @@ public final class EclipseUtil { */ public static List<IFile> getFilesFromWorkspace(final String prefix, final String suffix) { final List<IFile> matches = Lists.newArrayList(); - final IWorkspace workspace = ResourcesPlugin.getWorkspace(); - final IWorkspaceRoot root = workspace.getRoot(); - try { - root.accept(new IResourceVisitor() { - public boolean visit(IResource resource) throws CoreException { - if (resource.isAccessible() && resource instanceof IFile) { - IFile file = (IFile) resource; - boolean okForPrefix = StringUtil.isEmpty(prefix) || file.getName().startsWith(prefix); - boolean okForSuffix = StringUtil.isEmpty(suffix) || file.getName().endsWith(suffix); - if (okForPrefix && okForSuffix) { - matches.add(file); + IWorkspaceRoot root = EcorePlugin.getWorkspaceRoot(); + if (root != null) { + root.accept(new IResourceVisitor() { + public boolean visit(IResource resource) throws CoreException { + if (resource.isAccessible() && resource instanceof IFile) { + IFile file = (IFile) resource; + boolean okForPrefix = StringUtil.isEmpty(prefix) || file.getName().startsWith(prefix); + boolean okForSuffix = StringUtil.isEmpty(suffix) || file.getName().endsWith(suffix); + if (okForPrefix && okForSuffix) { + matches.add(file); + } } + return true; } - return true; - } - }); + }); + } } catch (final CoreException e1) { // do nothing -- fail silently } return matches; } + + /** + * Get {@link IConfigurationElement configurationElements} for a specified + * extensionPointId. + * + * @param extensionPointId + * the id of extension point + * @return {@link IConfigurationElement configurationElements} for a + * specified extensionPointId + */ + public static IConfigurationElement[] getConfigurationElementsFor(String extensionPointId) { + IConfigurationElement[] result = new IConfigurationElement[0]; + if (Platform.isRunning()) { + result = Platform.getExtensionRegistry().getConfigurationElementsFor(extensionPointId); + } + return result; + } } diff --git a/plugins/org.eclipse.sirius.doc/doc/Release Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release Notes.html index f8a1e24499..3e7d6d3ebc 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release Notes.html +++ b/plugins/org.eclipse.sirius.doc/doc/Release Notes.html @@ -159,6 +159,11 @@ <code>postXMLEndElement([..])</code> which is called during a migration operation. This method should be overrided by participants which have to hook the loading process after each end of XML tag. The corresponding abstract class <code>org.eclipse.sirius.business.api.migration.AbstractMigrationParticipant</code> provides a default NO-OP implementation. </li> + <li> + <code>org.eclipse.sirius.common.tools.api.util.EclipseUtil.getConfigurationElementsFor()</code> added to call + <code>org.eclipse.core.runtime.Platform.getExtensionRegistry().getConfigurationElementsFor()</code> and check + <code>Platform.isRunning()</code> before. + </li> </ul> <h4 id="Changesinorg.eclipse.sirius.ecore.extender">Changes in <code>org.eclipse.sirius.ecore.extender</code> diff --git a/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile index f918e39600..a5c076ad8a 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile +++ b/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile @@ -46,6 +46,7 @@ h4. Changes in @org.eclipse.sirius.common@ * The @org.eclipse.sirius.common.tools.api.util.LazyCrossReferencer.enableResolve()@ and @disableResolve()@ methods has been moved to @SiriusCrossReferenceAdapter.enableResolveProxy()@ and @disableResolveProxy()@. * The @org.eclipse.sirius.common.tools.api.resource.ImageFileFormat@ class has been added (it was in @org.eclipse.sirius.ext.swt@ before). * The interface @org.eclipse.sirius.business.api.migration.IMigrationParticipant@ exposes a new method @postXMLEndElement([..])@ which is called during a migration operation. This method should be overrided by participants which have to hook the loading process after each end of XML tag. The corresponding abstract class @org.eclipse.sirius.business.api.migration.AbstractMigrationParticipant@ provides a default NO-OP implementation. +* @org.eclipse.sirius.common.tools.api.util.EclipseUtil.getConfigurationElementsFor()@ added to call @org.eclipse.core.runtime.Platform.getExtensionRegistry().getConfigurationElementsFor()@ and check @Platform.isRunning()@ before. h4. Changes in @org.eclipse.sirius.ecore.extender@ diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/properties/SiriusCellEditorProviderCollector.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/properties/SiriusCellEditorProviderCollector.java index 1ca2ef7291..ea755cd9c1 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/properties/SiriusCellEditorProviderCollector.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/properties/SiriusCellEditorProviderCollector.java @@ -18,10 +18,10 @@ import java.util.Set; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.edit.provider.IItemPropertyDescriptor; +import org.eclipse.sirius.common.tools.api.util.EclipseUtil; import org.eclipse.sirius.ext.emf.ui.ICellEditorProvider; import org.eclipse.sirius.ext.emf.ui.properties.CellEditorProviderCollector; import org.eclipse.sirius.viewpoint.SiriusPlugin; @@ -71,7 +71,7 @@ public final class SiriusCellEditorProviderCollector implements CellEditorProvid */ private void loadCache() { cache = new HashSet<ICellEditorProvider>(); - IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_POINT_ID); + IConfigurationElement[] config = EclipseUtil.getConfigurationElementsFor(EXTENSION_POINT_ID); for (IConfigurationElement configurationElement : config) { try { Object contribution = configurationElement.createExecutableExtension("class"); diff --git a/plugins/org.eclipse.sirius/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius/META-INF/MANIFEST.MF index 96c5d2b06b..88cb9adf5e 100644 --- a/plugins/org.eclipse.sirius/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.sirius/META-INF/MANIFEST.MF @@ -130,6 +130,6 @@ Import-Package: org.eclipse.sirius.ext.base;version="2.0.0", org.eclipse.sirius.ext.emf;version="2.0.0", org.eclipse.sirius.ext.emf.tx;version="2.0.0" Eclipse-LazyStart: true -Bundle-Activator: org.eclipse.sirius.viewpoint.SiriusPlugin +Bundle-Activator: org.eclipse.sirius.viewpoint.SiriusPlugin$Implementation Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/componentization/ViewpointRegistryImpl.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/componentization/ViewpointRegistryImpl.java index a9cb4e161b..66582a4f6c 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/componentization/ViewpointRegistryImpl.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/componentization/ViewpointRegistryImpl.java @@ -26,12 +26,13 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceChangeEvent; import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Path; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.common.util.WrappedException; import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.plugin.EcorePlugin; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; @@ -146,10 +147,10 @@ public class ViewpointRegistryImpl extends ViewpointRegistry { crossReferencer = new ECrossReferenceAdapter(); this.resourceSet.eAdapters().add(crossReferencer); - - final IWorkspace workspace = ResourcesPlugin.getWorkspace(); - workspace.addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE); - + IWorkspaceRoot workspaceRoot = EcorePlugin.getWorkspaceRoot(); + if (workspaceRoot != null) { + workspaceRoot.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE); + } initViewpointsFromPlugins(); refreshComponentsFromWorkspace(); } @@ -470,8 +471,10 @@ public class ViewpointRegistryImpl extends ViewpointRegistry { if (filters != null) { filters.clear(); } - final IWorkspace workspace = ResourcesPlugin.getWorkspace(); - workspace.removeResourceChangeListener(this); + IWorkspaceRoot workspaceRoot = EcorePlugin.getWorkspaceRoot(); + if (workspaceRoot != null) { + workspaceRoot.getWorkspace().removeResourceChangeListener(this); + } invalidateCache(); } diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/repair/SiriusRepairProcess.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/repair/SiriusRepairProcess.java index 0338cd6d15..ba5bef75ac 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/repair/SiriusRepairProcess.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/repair/SiriusRepairProcess.java @@ -29,7 +29,6 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.jobs.Job; @@ -53,6 +52,7 @@ import org.eclipse.sirius.business.internal.repair.commands.RestoreModelElementS import org.eclipse.sirius.business.internal.repair.commands.SaveModelElementStateCommand; import org.eclipse.sirius.business.internal.session.danalysis.SaveSessionJob; import org.eclipse.sirius.common.tools.api.resource.ResourceSetSync.ResourceStatus; +import org.eclipse.sirius.common.tools.api.util.EclipseUtil; import org.eclipse.sirius.common.tools.api.util.ResourceUtil; import org.eclipse.sirius.ecore.extender.tool.api.ModelUtils; import org.eclipse.sirius.viewpoint.DAnalysis; @@ -110,7 +110,7 @@ public class SiriusRepairProcess { private List<IRepairParticipant> getRepairParticipants() { List<IRepairParticipant> participants = new ArrayList<IRepairParticipant>(); - IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.sirius.repairParticipant"); + IConfigurationElement[] config = EclipseUtil.getConfigurationElementsFor("org.eclipse.sirius.repairParticipant"); for (IConfigurationElement configurationElement : config) { try { diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/AbstractSavingPolicy.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/AbstractSavingPolicy.java index d14b778b5f..2e2f28d10d 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/AbstractSavingPolicy.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/AbstractSavingPolicy.java @@ -16,13 +16,13 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; -import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.emf.ecore.plugin.EcorePlugin; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.xmi.XMLResource; import org.eclipse.emf.transaction.TransactionalEditingDomain; @@ -59,20 +59,23 @@ public abstract class AbstractSavingPolicy implements SavingPolicy { final Collection<Resource> resourcesToSave = Lists.newArrayList(); try { monitor.beginTask("Save Session", IProgressMonitor.UNKNOWN); + resourcesToSave.addAll(computeResourcesToSave(Sets.newLinkedHashSet(allResources), options, monitor)); if (alreadyIsInWorkspaceModificationOperation()) { - resourcesToSave.addAll(computeResourcesToSave(Sets.newLinkedHashSet(allResources), options, monitor)); wrappedSave(resourcesToSave, allResources, options, new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN)); } else { - final IWorkspace workspace = ResourcesPlugin.getWorkspace(); - try { - workspace.run(new IWorkspaceRunnable() { - public void run(final IProgressMonitor monitor) throws CoreException { - resourcesToSave.addAll(computeResourcesToSave(Sets.newLinkedHashSet(allResources), options, monitor)); - wrappedSave(resourcesToSave, allResources, options, monitor); - } - }, new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN)); - } catch (final CoreException e) { - SiriusPlugin.getDefault().error("Core exception while saving session", e); + IWorkspaceRoot workspaceRoot = EcorePlugin.getWorkspaceRoot(); + if (workspaceRoot != null) { + try { + workspaceRoot.getWorkspace().run(new IWorkspaceRunnable() { + public void run(final IProgressMonitor monitor) throws CoreException { + wrappedSave(resourcesToSave, allResources, options, monitor); + } + }, new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN)); + } catch (final CoreException e) { + SiriusPlugin.getDefault().error("Core exception while saving session", e); + } + } else { + wrappedSave(resourcesToSave, allResources, options, monitor); } } } finally { diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/migration/AbstractSiriusMigrationService.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/migration/AbstractSiriusMigrationService.java index 15469da09c..37f54e958f 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/migration/AbstractSiriusMigrationService.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/migration/AbstractSiriusMigrationService.java @@ -17,7 +17,6 @@ import java.util.Map; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EClassifier; @@ -29,6 +28,7 @@ import org.eclipse.emf.ecore.util.FeatureMap.Entry; import org.eclipse.emf.ecore.xmi.XMLResource; import org.eclipse.emf.ecore.xml.type.AnyType; import org.eclipse.sirius.business.api.migration.IMigrationParticipant; +import org.eclipse.sirius.common.tools.api.util.EclipseUtil; import org.eclipse.sirius.ext.base.Option; import org.eclipse.sirius.ext.base.Options; import org.eclipse.sirius.viewpoint.SiriusPlugin; @@ -45,9 +45,8 @@ import org.xml.sax.Attributes; public abstract class AbstractSiriusMigrationService { /** - * This option is passed during a resource load if a migration should - * be done. The value contains a string representation of the loaded - * version. + * This option is passed during a resource load if a migration should be + * done. The value contains a string representation of the loaded version. */ public static final String OPTION_RESOURCE_MIGRATION_LOADEDVERSION = "RESOURCE_MIGRATION_LOADEDVERSION"; @@ -72,7 +71,7 @@ public abstract class AbstractSiriusMigrationService { */ protected void loadContributions() { delegatesParticipants.clear(); - IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.sirius.migrationParticipant"); + IConfigurationElement[] config = EclipseUtil.getConfigurationElementsFor("org.eclipse.sirius.migrationParticipant"); for (IConfigurationElement configurationElement : config) { try { String kind = configurationElement.getAttribute("kind"); diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/movida/registry/ViewpointRegistry.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/movida/registry/ViewpointRegistry.java index 98b72c2f5f..018c0254d4 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/movida/registry/ViewpointRegistry.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/movida/registry/ViewpointRegistry.java @@ -46,6 +46,7 @@ import org.eclipse.sirius.business.internal.movida.registry.monitoring.PluginMon import org.eclipse.sirius.business.internal.movida.registry.monitoring.ViewpointResourceListener; import org.eclipse.sirius.business.internal.movida.registry.monitoring.ViewpointResourceMonitor; import org.eclipse.sirius.business.internal.movida.registry.monitoring.WorkspaceMonitor; +import org.eclipse.sirius.common.tools.api.util.EclipseUtil; import org.eclipse.sirius.ext.base.Option; import org.eclipse.sirius.ext.base.Options; import org.eclipse.sirius.ext.base.relations.Relation; @@ -174,7 +175,7 @@ public class ViewpointRegistry extends org.eclipse.sirius.business.api.component private void configureResourceHandler() { compositeResourceHandler.addResourceType(new DefaultViewpointResourceHandler()); - IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(VIEWPOINT_RESOURCE_TYPE_EXTENSION_POINT); + IConfigurationElement[] elements = EclipseUtil.getConfigurationElementsFor(VIEWPOINT_RESOURCE_TYPE_EXTENSION_POINT); for (IConfigurationElement element : elements) { if ("handler".equals(element.getName())) { Object handler; diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/ResourceSaveDiagnose.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/ResourceSaveDiagnose.java index 6e359d64bc..b4e3aeed09 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/ResourceSaveDiagnose.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/ResourceSaveDiagnose.java @@ -18,9 +18,9 @@ import java.util.Map; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.URIConverter; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; -import org.eclipse.sirius.business.api.helper.SiriusUtil; /** * Class able to tell whether a save operation on a resource can succeed or not, @@ -30,7 +30,6 @@ import org.eclipse.sirius.business.api.helper.SiriusUtil; * resource to know whether it will change the file or not. * * @author cbrun - * */ public class ResourceSaveDiagnose { @@ -52,7 +51,10 @@ public class ResourceSaveDiagnose { * @return true if the resource might be saved, false otherwise. */ public boolean isSaveable() { - return resourcetoSave.getURI().isFile() || resourcetoSave.getURI().isPlatformResource() && !SiriusUtil.isModelerDescriptionFile(resourcetoSave); + boolean isSaveable = false; + ResourceSet resourceSet = resourcetoSave.getResourceSet(); + isSaveable = resourceSet != null && !Boolean.TRUE.equals(resourceSet.getURIConverter().getAttributes(resourcetoSave.getURI(), null).get(URIConverter.ATTRIBUTE_READ_ONLY)); + return isSaveable; } /** @@ -77,7 +79,7 @@ public class ResourceSaveDiagnose { final URIConverter uriConverter = resourcetoSave.getResourceSet() == null ? new ResourceSetImpl().getURIConverter() : resourcetoSave.getResourceSet().getURIConverter(); final OutputStream temporaryFileOutputStream = uriConverter.createOutputStream(temporaryFileURI); - + long preSaveTimestamp = resourcetoSave.getTimeStamp(); boolean preSaveIsModified = resourcetoSave.isModified(); try { @@ -86,9 +88,10 @@ public class ResourceSaveDiagnose { temporaryFileOutputStream.close(); /* * saving the resource instance even in an external buffer will - * change the session state, notably isModified and the timestamp - * (see the implementation of ResourceImpl). We don't want to have - * this side effect, the best we can do is undo it aftersaving. + * change the session state, notably isModified and the + * timestamp (see the implementation of ResourceImpl). We don't + * want to have this side effect, the best we can do is undo it + * aftersaving. */ resourcetoSave.setModified(preSaveIsModified); resourcetoSave.setTimeStamp(preSaveTimestamp); diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/SessionResourcesSynchronizer.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/SessionResourcesSynchronizer.java index 8a3b4c94c6..114620d309 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/SessionResourcesSynchronizer.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/SessionResourcesSynchronizer.java @@ -20,7 +20,6 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.emf.common.command.Command; -import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.util.EcoreUtil; @@ -28,7 +27,6 @@ import org.eclipse.emf.transaction.RunnableWithResult; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.emf.workspace.util.WorkspaceSynchronizer; import org.eclipse.sirius.business.api.query.ResourceQuery; -import org.eclipse.sirius.business.api.query.URIQuery; import org.eclipse.sirius.business.api.session.ReloadingPolicy.Action; import org.eclipse.sirius.business.api.session.SessionListener; import org.eclipse.sirius.common.tools.api.resource.ResourceSetSync; @@ -278,8 +276,9 @@ public class SessionResourcesSynchronizer implements ResourceSyncClient { boolean allResourceAreInSync = true; for (Resource resource : resourcesToConsider) { ResourceStatus status = ResourceSetSync.getStatus(resource); - URI uri = resource.getURI(); - allResourceAreInSync = status == ResourceStatus.SYNC || (!uri.isPlatformResource() && !new URIQuery(uri).isInMemoryURI() && !new URIQuery(uri).isCDOURI()); + // Test also resource.modified field in case ResourceStatus == + // UNKNOWN + allResourceAreInSync = status == ResourceStatus.SYNC || !resource.isModified(); if (!allResourceAreInSync) { break; } diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/ui/RefreshEditorsPrecommitListener.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/ui/RefreshEditorsPrecommitListener.java index 30b3fad1fc..904a0a0368 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/ui/RefreshEditorsPrecommitListener.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/ui/RefreshEditorsPrecommitListener.java @@ -229,7 +229,7 @@ public class RefreshEditorsPrecommitListener implements ModelChangeTrigger, Sess * @return true if a refresh must be launch. */ private boolean isAutoRefresh() { - return Platform.getPreferencesService().getBoolean(SiriusPlugin.ID, SiriusPreferencesKeys.PREF_AUTO_REFRESH.name(), false, null); + return Platform.isRunning() && Platform.getPreferencesService().getBoolean(SiriusPlugin.ID, SiriusPreferencesKeys.PREF_AUTO_REFRESH.name(), false, null); } /** diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/viewpoint/SiriusPlugin.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/viewpoint/SiriusPlugin.java index b60ae08244..4c323d49f9 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/viewpoint/SiriusPlugin.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/viewpoint/SiriusPlugin.java @@ -13,9 +13,11 @@ package org.eclipse.sirius.viewpoint; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Status; +import org.eclipse.emf.common.EMFPlugin; +import org.eclipse.emf.common.util.ResourceLocator; import org.eclipse.emf.ecore.EValidator; +import org.eclipse.emf.ecore.plugin.EcorePlugin; import org.eclipse.sirius.business.api.componentization.ViewpointRegistry; import org.eclipse.sirius.business.api.helper.SiriusUtil; import org.eclipse.sirius.business.internal.helper.delete.DeleteHookDescriptorRegistryListener; @@ -26,6 +28,7 @@ import org.eclipse.sirius.tools.internal.ui.ExternalJavaActionRegistryListener; import org.eclipse.sirius.tools.internal.validation.EValidatorAdapter; import org.eclipse.sirius.viewpoint.description.DescriptionPackage; import org.eclipse.sirius.viewpoint.description.tool.ToolPackage; +import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; /** @@ -33,7 +36,7 @@ import org.osgi.framework.BundleContext; * * @author ymortier */ -public final class SiriusPlugin extends Plugin { +public final class SiriusPlugin extends EMFPlugin { /** * Tell whether Eclipse is running or not. */ @@ -53,8 +56,10 @@ public final class SiriusPlugin extends Plugin { /** The id. */ public static final String ID = "org.eclipse.sirius"; //$NON-NLS-1$ - /** The shared instance. */ - private static SiriusPlugin defaultPlugin; + /** Keep track of the singleton.. */ + public static final SiriusPlugin INSTANCE = new SiriusPlugin(); + + private static Implementation plugin; /** * create at the initialization to avoid synchronization cost in @@ -69,136 +74,166 @@ public final class SiriusPlugin extends Plugin { private static final InterpreterRegistry INTER_REGISTRY = new InterpreterRegistry(); /** - * The registry listener that will be used to listen to sessionFactory - * extension changes. - */ - private SessionFactoryRegistryListener sessionFactoryRegistryListener; - - /** The registry listener that will be used to listen to extension changes. */ - private DeleteHookDescriptorRegistryListener deleteHookDescriptorRegistryListener; - - /** - * The registry listener that will be used to listen to contribution changes - * against the external java action extension point. - */ - private ExternalJavaActionRegistryListener javaActionRegistryListener; - - /** - * Creates a new <code>ExtensionPlugin</code>. + * Creates the instance. */ public SiriusPlugin() { - defaultPlugin = this; + super(new ResourceLocator[] { EcorePlugin.INSTANCE, SiriusPlugin.INSTANCE, }); } /** - * Returns the shared instance. + * Returns the singleton instance of the Eclipse plugin. * - * @return the shared instance. + * @return the singleton instance. */ - public static SiriusPlugin getDefault() { - return SiriusPlugin.defaultPlugin; + @Override + public ResourceLocator getPluginResourceLocator() { + return plugin; } /** - * Logs an error in the error log. + * Returns the singleton instance of the Eclipse plugin. * - * @param message - * the message to log (optional). - * @param e - * the exception (optional). + * @return the singleton instance. */ - public void error(String message, final Throwable e) { - String messageToDisplay = message; - if (messageToDisplay == null && e != null) { - messageToDisplay = e.getMessage(); - } - if (e instanceof CoreException) { - this.getLog().log(((CoreException) e).getStatus()); - } else { - final IStatus status = new Status(IStatus.ERROR, this.getBundle().getSymbolicName(), messageToDisplay, e); - this.getLog().log(status); - } + public static Implementation getDefault() { + return plugin; } /** - * Logs a warning in the error log. - * - * @param message - * the message to log (optional). - * @param e - * the exception (optional). + * The actual implementation of the Eclipse <b>Plugin</b>. */ - public void warning(String message, final Exception e) { - String messageToDisplay = message; - if (messageToDisplay == null && e != null) { - messageToDisplay = e.getMessage(); + public static class Implementation extends EclipsePlugin { + + /** + * The registry listener that will be used to listen to sessionFactory + * extension changes. + */ + private SessionFactoryRegistryListener sessionFactoryRegistryListener; + + /** + * The registry listener that will be used to listen to extension + * changes. + */ + private DeleteHookDescriptorRegistryListener deleteHookDescriptorRegistryListener; + + /** + * The registry listener that will be used to listen to contribution + * changes against the external java action extension point. + */ + private ExternalJavaActionRegistryListener javaActionRegistryListener; + + /** + * Creates an instance. + */ + public Implementation() { + super(); + plugin = this; } - if (e instanceof CoreException) { - this.getLog().log(((CoreException) e).getStatus()); - } else { - final IStatus status = new Status(IStatus.WARNING, this.getBundle().getSymbolicName(), messageToDisplay, e); - this.getLog().log(status); + + /** + * The actual implementation of the purely OSGi-compatible <b>Bundle + * Activator</b>. + */ + public static final class Activator extends EMFPlugin.OSGiDelegatingBundleActivator { + @Override + protected BundleActivator createBundle() { + return new Implementation(); + } } - } - /** - * {@inheritDoc} - * - * @see org.eclipse.core.runtime.Plugin#start(org.osgi.framework.BundleContext) - */ - @Override - public void start(final BundleContext context) throws Exception { - super.start(context); - - // Sets the validator for these model. - EValidator.Registry.INSTANCE.put(ViewpointPackage.eINSTANCE, new EValidatorAdapter()); - EValidator.Registry.INSTANCE.put(DescriptionPackage.eINSTANCE, new EValidatorAdapter()); - EValidator.Registry.INSTANCE.put(ToolPackage.eINSTANCE, new EValidatorAdapter()); - - sessionFactoryRegistryListener = new SessionFactoryRegistryListener(); - sessionFactoryRegistryListener.init(); - deleteHookDescriptorRegistryListener = new DeleteHookDescriptorRegistryListener(); - deleteHookDescriptorRegistryListener.init(); - javaActionRegistryListener = new ExternalJavaActionRegistryListener(); - javaActionRegistryListener.init(); - } + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + + // Sets the validator for these model. + EValidator.Registry.INSTANCE.put(ViewpointPackage.eINSTANCE, new EValidatorAdapter()); + EValidator.Registry.INSTANCE.put(DescriptionPackage.eINSTANCE, new EValidatorAdapter()); + EValidator.Registry.INSTANCE.put(ToolPackage.eINSTANCE, new EValidatorAdapter()); + + sessionFactoryRegistryListener = new SessionFactoryRegistryListener(); + sessionFactoryRegistryListener.init(); + deleteHookDescriptorRegistryListener = new DeleteHookDescriptorRegistryListener(); + deleteHookDescriptorRegistryListener.init(); + javaActionRegistryListener = new ExternalJavaActionRegistryListener(); + javaActionRegistryListener.init(); + } - /** - * {@inheritDoc} - * - * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext) - */ - @Override - public void stop(final BundleContext context) throws Exception { - super.stop(context); - REGISTRY.dispose(); - - sessionFactoryRegistryListener.dispose(); - sessionFactoryRegistryListener = null; - deleteHookDescriptorRegistryListener.dispose(); - deleteHookDescriptorRegistryListener = null; - javaActionRegistryListener.dispose(); - javaActionRegistryListener = null; - - ViewpointRegistry.getInstance().dispose(); - } + @Override + public void stop(BundleContext context) throws Exception { + REGISTRY.dispose(); - /** - * Return the global instance of {@link ModelAccessorsRegistry}. - * - * @return the global instance of {@link ModelAccessorsRegistry}. - */ - public ModelAccessorsRegistry getModelAccessorRegistry() { - return REGISTRY; - } + sessionFactoryRegistryListener.dispose(); + sessionFactoryRegistryListener = null; + deleteHookDescriptorRegistryListener.dispose(); + deleteHookDescriptorRegistryListener = null; + javaActionRegistryListener.dispose(); + javaActionRegistryListener = null; + + ViewpointRegistry.getInstance().dispose(); + + super.stop(context); + } + + /** + * Return the global instance of {@link ModelAccessorsRegistry}. + * + * @return the global instance of {@link ModelAccessorsRegistry}. + */ + public ModelAccessorsRegistry getModelAccessorRegistry() { + return REGISTRY; + } + + /** + * Return the global instance of {@link ExtendedPackageRegistry}. + * + * @return the global instance of {@link ExtendedPackageRegistry}. + */ + public InterpreterRegistry getInterpreterRegistry() { + return INTER_REGISTRY; + } + + /** + * Logs an error in the error log. + * + * @param message + * the message to log (optional). + * @param e + * the exception (optional). + */ + public void error(String message, final Throwable e) { + String messageToDisplay = message; + if (messageToDisplay == null && e != null) { + messageToDisplay = e.getMessage(); + } + if (e instanceof CoreException) { + getLog().log(((CoreException) e).getStatus()); + } else { + IStatus status = new Status(IStatus.ERROR, getDefault().getSymbolicName(), messageToDisplay, e); + getLog().log(status); + } + } + + /** + * Logs a warning in the error log. + * + * @param message + * the message to log (optional). + * @param e + * the exception (optional). + */ + public void warning(String message, final Exception e) { + String messageToDisplay = message; + if (messageToDisplay == null && e != null) { + messageToDisplay = e.getMessage(); + } + if (e instanceof CoreException) { + getLog().log(((CoreException) e).getStatus()); + } else { + final IStatus status = new Status(IStatus.WARNING, getDefault().getSymbolicName(), messageToDisplay, e); + getLog().log(status); + } + } - /** - * Return the global instance of {@link ExtendedPackageRegistry}. - * - * @return the global instance of {@link ExtendedPackageRegistry}. - */ - public InterpreterRegistry getInterpreterRegistry() { - return INTER_REGISTRY; } } |
