diff options
| author | Laurent Redor | 2014-04-11 08:15:59 +0000 |
|---|---|---|
| committer | Laurent Redor | 2014-04-16 14:38:14 +0000 |
| commit | 6168f11d61f41a0821a103ca490d87c335d5f93c (patch) | |
| tree | b4f13983ee84adfae277e272267fb17bd51919b6 | |
| parent | 23675bcfe7de9bfdf909af50f27d106c7d693eed (diff) | |
| download | org.eclipse.sirius-6168f11d61f41a0821a103ca490d87c335d5f93c.tar.gz org.eclipse.sirius-6168f11d61f41a0821a103ca490d87c335d5f93c.tar.xz org.eclipse.sirius-6168f11d61f41a0821a103ca490d87c335d5f93c.zip | |
[430263] Remove the ModelingProjectManagerStartup - Clean step
This startup extension implies that if Sirius is installed, a large part
of
Sirius plugins are getting loaded and started even if your are not using
it.
This commit is a first cleaning step to dissociate the core of this
change:
* Change behavior when a file is removed in a modeling project: Now
there is a validation launched when a reresentations file is deleted in
an invalid project.
* The method ModelingProject.getMainRepresentationsFileURI now marks
this project as invalid and adds a marker on it, if it is considered as
invalid (no or many representations files).
* The method InitializeModelingProjectJob.initializeModelingProjects()
does not add marker anymore (it is done by
ModelingProject.getMainRepresentationsFileURI()).
Change-Id: I9ac762e5a99867dfc592f0b43b51277507b20d86
Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
7 files changed, 85 insertions, 74 deletions
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release Notes.html index 278078f6b6..5357677409 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release Notes.html +++ b/plugins/org.eclipse.sirius.doc/doc/Release Notes.html @@ -279,6 +279,12 @@ <code>Multimap</code>. The new protected method <code>addDefinition()</code> can be used to make it easier to add entries to the map. Subclasses in Sirius have been updated to match the new signature. </li> + <li>The message + <code>org.eclipse.sirius.business.api.modelingproject.ModelingProject.ZERO_REPRESENTATIONS_FILE_FOUND_IN</code> has been removed without replacement. It was not really an API constant. + </li> + <li>The behavior of method + <code>org.eclipse.sirius.business.api.modelingproject.ModelingProject.getMainRepresentationsFileURI()</code> has changed. It now marks this project as invalid and adds a marker on it, if it is considered as invalid (no or many representations files). + </li> </ul> <h4 id="Changesinorg.eclipse.sirius.diagram">Changes in <code>org.eclipse.sirius.diagram</code> diff --git a/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile index 7e75e16c5f..ed6cfa7119 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile +++ b/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile @@ -77,6 +77,8 @@ h4. Changes in @org.eclipse.sirius@ * The @org.eclipse.sirius.business.api.modelingproject.ModelingProject.MODELING_PROJECT_PREDICATE@ constant has been removed to reduce Sirius's exposure of Guava'specific types. Use the equivalent @ModelingProject.hasModelingProjectNature()@ method instead. * The method @org.eclipse.sirius.business.api.query.EObjectQuery.getInverseReferences(Predicate<Setting>)@ has been removed from API to avoid exposing a the Guava-specific @Predicate@ type. * In class @org.eclipse.sirius.business.api.dialect.description.AbstractInterpretedExpressionQuery@, the protected methods @appendAllLocalVariableDefinitions()@ and @appendEditMaskVariables()@ now take a @Map<String, Collection<String>>@ instead of a Guava-specific @Multimap@. The new protected method @addDefinition()@ can be used to make it easier to add entries to the map. Subclasses in Sirius have been updated to match the new signature. +* The message @org.eclipse.sirius.business.api.modelingproject.ModelingProject.ZERO_REPRESENTATIONS_FILE_FOUND_IN@ has been removed without replacement. It was not really an API constant. +* The behavior of method @org.eclipse.sirius.business.api.modelingproject.ModelingProject.getMainRepresentationsFileURI()@ has changed. It now marks this project as invalid and adds a marker on it, if it is considered as invalid (no or many representations files). h4. Changes in @org.eclipse.sirius.diagram@ diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/manager/ModelingProjectManagerImpl.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/manager/ModelingProjectManagerImpl.java index 52693fa9be..e4bbd83312 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/manager/ModelingProjectManagerImpl.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/manager/ModelingProjectManagerImpl.java @@ -331,7 +331,7 @@ public class ModelingProjectManagerImpl implements ModelingProjectManager { OpenRepresentationsFileJob.scheduleNewWhenPossible(mainRepresentationsFileURI.get(), true); } } catch (IllegalArgumentException e) { - if (e.getMessage().contains(ModelingProject.ZERO_REPRESENTATIONS_FILE_FOUND_IN)) { + if (e.getMessage().contains(ModelingProjectQuery.ZERO_REPRESENTATIONS_FILE_FOUND_IN)) { // 0 files has been found : create a representation ModelingProjectManager.INSTANCE.createLocalRepresentationsFile(project, new SubProgressMonitor(monitor, 1)); } else if (e.getMessage().contains(ModelingProjectQuery.A_MODELING_PROJECT_MUST_CONTAIN_ONLY_ONE)) { diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/model/ModelingModelProvider.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/model/ModelingModelProvider.java index 3b9c966277..ab3c70d677 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/model/ModelingModelProvider.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/model/ModelingModelProvider.java @@ -27,9 +27,9 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.emf.common.util.URI; import org.eclipse.sirius.business.api.helper.SiriusUtil; import org.eclipse.sirius.business.api.modelingproject.ModelingProject; +import org.eclipse.sirius.business.api.query.FileQuery; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.business.api.session.SessionStatus; import org.eclipse.sirius.ext.base.Option; @@ -89,8 +89,7 @@ public class ModelingModelProvider extends ModelProvider { ResourceDeltaVisitor visitor = new ResourceDeltaVisitor(); delta.accept(visitor); if (visitor.getProjectContainingSessionToSaveToDelete().size() == 1) { - result = new ModelStatus(IStatus.ERROR, SiriusPlugin.ID, ModelingModelProvider.MODELING_MODEL_PROVIDER_ID, - "This modeling project contains unsaved data. This data will be lost."); + result = new ModelStatus(IStatus.ERROR, SiriusPlugin.ID, ModelingModelProvider.MODELING_MODEL_PROVIDER_ID, "This modeling project contains unsaved data. This data will be lost."); } else if (visitor.getProjectContainingSessionToSaveToDelete().size() > 1) { result = new ModelStatus(IStatus.ERROR, SiriusPlugin.ID, ModelingModelProvider.MODELING_MODEL_PROVIDER_ID, "Some modeling projects (" + getProjectsName(visitor.getProjectContainingSessionToSaveToDelete()) + ") contain unsaved data. This data will be lost."); @@ -98,8 +97,8 @@ public class ModelingModelProvider extends ModelProvider { result = new ModelStatus(IStatus.ERROR, SiriusPlugin.ID, ModelingModelProvider.MODELING_MODEL_PROVIDER_ID, "Deletion of the main representations file of \"" + visitor.getMainRepresentationsFilesToDelete().get(0).getProject().getName() + "\" will invalidate it."); } else if (visitor.getMainRepresentationsFilesToDelete().size() > 1) { - result = new ModelStatus(IStatus.ERROR, SiriusPlugin.ID, ModelingModelProvider.MODELING_MODEL_PROVIDER_ID, - "Deletion of the main representations files of some modeling projects (" + getFilesProjectName(visitor.getMainRepresentationsFilesToDelete()) + ") will invalidate them."); + result = new ModelStatus(IStatus.ERROR, SiriusPlugin.ID, ModelingModelProvider.MODELING_MODEL_PROVIDER_ID, "Deletion of the main representations files of some modeling projects (" + + getFilesProjectName(visitor.getMainRepresentationsFilesToDelete()) + ") will invalidate them."); } else if (visitor.getRepresentationsFileToAddOnValidModelingProject().size() == 1) { result = new ModelStatus(IStatus.ERROR, SiriusPlugin.ID, ModelingModelProvider.MODELING_MODEL_PROVIDER_ID, "Add another representations file to \"" + visitor.getRepresentationsFileToAddOnValidModelingProject().get(0).getProject().getName() + "\" may invalidate it."); @@ -243,12 +242,16 @@ public class ModelingModelProvider extends ModelProvider { final Option<ModelingProject> optionalModelingProject = ModelingProject.asModelingProject(currentFile.getProject()); if (optionalModelingProject.some()) { if (IResourceDelta.REMOVED == delta.getKind()) { - // Check that this IFile is not the main representations - // file of this project - URI currentURI = URI.createPlatformResourceURI(currentFile.getFullPath().toString(), true); - Option<URI> optionalMainURI = optionalModelingProject.get().getMainRepresentationsFileURI(new NullProgressMonitor(), false, false); - if (optionalMainURI.some() && currentURI.equals(optionalMainURI.get())) { - mainRepresentationsFileToDelete.add(currentFile); + if (optionalModelingProject.get().isValid()) { + // Check that this IFile is not the main representations + // file of this project + if (optionalModelingProject.get().isMainRepresentationsFile(currentFile)) { + mainRepresentationsFileToDelete.add(currentFile); + } + } else if (new FileQuery(currentFile).isSessionResourceFile()) { + // If the project is not valid and the deleted file is a + // representations file, validate the project again. + optionalModelingProject.get().getMainRepresentationsFileURI(new NullProgressMonitor(), true, false); } } else if (IResourceDelta.ADDED == delta.getKind()) { // Check that the corresponding project does not already diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/modelingproject/ModelingProject.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/modelingproject/ModelingProject.java index c600d2d05a..59626d0bfb 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/modelingproject/ModelingProject.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/modelingproject/ModelingProject.java @@ -11,8 +11,10 @@ package org.eclipse.sirius.business.api.modelingproject; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectNature; +import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; @@ -20,9 +22,11 @@ import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.emf.common.util.URI; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.business.api.session.SessionManager; +import org.eclipse.sirius.business.internal.modelingproject.marker.ModelingMarker; import org.eclipse.sirius.business.internal.query.ModelingProjectQuery; import org.eclipse.sirius.ext.base.Option; import org.eclipse.sirius.ext.base.Options; +import org.eclipse.sirius.viewpoint.SiriusPlugin; /** * A modeling project nature is used to know which projects should be handled in @@ -32,11 +36,6 @@ import org.eclipse.sirius.ext.base.Options; */ public class ModelingProject implements IProjectNature, IModelingElement { - /** - * error message when no representation file found. - */ - public static final String ZERO_REPRESENTATIONS_FILE_FOUND_IN = "Zero representations file found in \""; - /** The nature id. */ public static final String NATURE_ID = "org.eclipse.sirius.nature.modelingproject"; @@ -188,7 +187,9 @@ public class ModelingProject implements IProjectNature, IModelingElement { * Return an optional URI corresponding to the main representations file of * this project. If the main representations file is not known, it will be * computed by a specific SaxParser that analyzes representations files of - * this project to determine which is never referenced. + * this project to determine which is never referenced.<BR> + * This method marks this project as invalid and adds a marker on it, if it + * is considered as invalid. * * @param monitor * the monitor to be used for reporting progress and responding @@ -215,16 +216,27 @@ public class ModelingProject implements IProjectNature, IModelingElement { } if (valid && mainRepresentationsFileURI == null) { // The main representations file is not known (or is known but - // must - // be recompute). We must compute it. + // must be recomputed). We must compute it. try { - Option<URI> result = new ModelingProjectQuery(this).computeMainRepresentationsFileURI(new SubProgressMonitor(monitor, 1)); - if (result.some()) { - mainRepresentationsFileURI = result.get(); - } else { - throw new IllegalArgumentException(ZERO_REPRESENTATIONS_FILE_FOUND_IN + getProject().getName() + "\". A modeling project must contain one."); - } + mainRepresentationsFileURI = new ModelingProjectQuery(this).computeMainRepresentationsFileURI(new SubProgressMonitor(monitor, 1)); } catch (IllegalArgumentException e) { + // Clean existing marker if exists + try { + getProject().deleteMarkers(ModelingMarker.MARKER_TYPE, false, IResource.DEPTH_ZERO); + } catch (final CoreException ce) { + SiriusPlugin.getDefault().getLog().log(ce.getStatus()); + } + // Add a marker on this project + try { + final IMarker marker = getProject().createMarker(ModelingMarker.MARKER_TYPE); + marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); + marker.setAttribute(IMarker.MESSAGE, e.getMessage()); + } catch (final CoreException ce) { + SiriusPlugin.getDefault().getLog().log(ce.getStatus()); + } + // Set this project in invalid state + setValid(false); + // Throw exception if asked if (throwException) { throw e; } diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/modelingproject/manager/InitializeModelingProjectJob.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/modelingproject/manager/InitializeModelingProjectJob.java index 19d623adc3..618846ee6a 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/modelingproject/manager/InitializeModelingProjectJob.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/modelingproject/manager/InitializeModelingProjectJob.java @@ -12,7 +12,6 @@ package org.eclipse.sirius.business.internal.modelingproject.manager; import java.util.List; -import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; @@ -31,6 +30,7 @@ import org.eclipse.sirius.viewpoint.SiriusPlugin; import com.google.common.base.Predicate; import com.google.common.collect.Iterators; import com.google.common.collect.Lists; + /** * A job to compute the main representations file of each modeling project of * the workspace. @@ -142,18 +142,8 @@ public class InitializeModelingProjectJob extends WorkspaceJob { try { optionalModelingProject.get().getMainRepresentationsFileURI(new SubProgressMonitor(monitor, 1), forceInit, true); } catch (IllegalArgumentException e) { - // Add a marker on this project - try { - final IMarker marker = optionalModelingProject.get().getProject().createMarker(ModelingMarker.MARKER_TYPE); - marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); - marker.setAttribute(IMarker.MESSAGE, e.getMessage()); - } catch (final CoreException ce) { - SiriusPlugin.getDefault().getLog().log(ce.getStatus()); - } // Add the problem to the result status of this job errorStatus.add(new Status(IStatus.ERROR, SiriusPlugin.ID, IStatus.OK, e.getMessage(), null)); //$NON-NLS-1$) - // Set this project in invalid state - optionalModelingProject.get().setValid(false); } } else { monitor.worked(1); diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/query/ModelingProjectQuery.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/query/ModelingProjectQuery.java index 330fe319dd..60c99d98d4 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/query/ModelingProjectQuery.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/query/ModelingProjectQuery.java @@ -26,8 +26,6 @@ import org.eclipse.sirius.business.api.helper.SiriusUtil; import org.eclipse.sirius.business.api.modelingproject.ModelingProject; import org.eclipse.sirius.business.internal.session.parser.RepresentationsFileSaxParser; import org.eclipse.sirius.common.tools.api.util.WorkspaceUtil; -import org.eclipse.sirius.ext.base.Option; -import org.eclipse.sirius.ext.base.Options; /** * A class aggregating all the queries (read-only!) having a @@ -38,6 +36,11 @@ import org.eclipse.sirius.ext.base.Options; public class ModelingProjectQuery { /** + * error message when no representation file found. + */ + public static final String ZERO_REPRESENTATIONS_FILE_FOUND_IN = "Zero representations file found in \""; + + /** * error message when several representation files found. */ public static final String A_MODELING_PROJECT_MUST_CONTAIN_ONLY_ONE = ". A modeling project must contain only one."; @@ -76,50 +79,45 @@ public class ModelingProjectQuery { * @return an optional URI corresponding to the main representations file of * this project. * @throws IllegalArgumentException - * In case of multiples main representations file in the + * In case of zero or multiples main representations file in the * references. */ - public Option<URI> computeMainRepresentationsFileURI(IProgressMonitor monitor) throws IllegalArgumentException { + public URI computeMainRepresentationsFileURI(IProgressMonitor monitor) throws IllegalArgumentException { URI result = null; - try { - List<IFile> sessionFiles = getRepresentationFiles(); - monitor.beginTask("", sessionFiles.size() + 1); - Map<URI, Set<URI>> references = new HashMap<URI, Set<URI>>(sessionFiles.size()); - for (IFile sessionFile : sessionFiles) { - final RepresentationsFileSaxParser sessionSaxParser = new RepresentationsFileSaxParser(sessionFile); - sessionSaxParser.analyze(new SubProgressMonitor(monitor, 1)); - references.put(sessionSaxParser.getRepresentationsFileURI(), sessionSaxParser.getReferencedAnalysis()); - } - List<URI> notReferencedURIs = new ArrayList<URI>(); - List<URI> keys = new ArrayList<URI>(references.keySet()); - for (URI uri : references.keySet()) { - boolean referenced = false; - for (URI uri2 : keys) { - if (references.get(uri2).contains(uri)) { - referenced = true; - break; - } - } - if (!referenced) { - notReferencedURIs.add(uri); + List<IFile> sessionFiles = getRepresentationFiles(); + monitor.beginTask("", sessionFiles.size() + 1); + Map<URI, Set<URI>> references = new HashMap<URI, Set<URI>>(sessionFiles.size()); + for (IFile sessionFile : sessionFiles) { + final RepresentationsFileSaxParser sessionSaxParser = new RepresentationsFileSaxParser(sessionFile); + sessionSaxParser.analyze(new SubProgressMonitor(monitor, 1)); + references.put(sessionSaxParser.getRepresentationsFileURI(), sessionSaxParser.getReferencedAnalysis()); + } + List<URI> notReferencedURIs = new ArrayList<URI>(); + List<URI> keys = new ArrayList<URI>(references.keySet()); + for (URI uri : references.keySet()) { + boolean referenced = false; + for (URI uri2 : keys) { + if (references.get(uri2).contains(uri)) { + referenced = true; + break; } } - monitor.worked(1); - - if (notReferencedURIs.size() == 1) { - result = notReferencedURIs.get(0); - } else if (notReferencedURIs.size() > 1) { - throw new IllegalArgumentException("Found " + notReferencedURIs.size() + " main representations files (that means not referenced by another) in \"" - + modelingProject.getProject().getName() + "\": " + getFragments(notReferencedURIs) + A_MODELING_PROJECT_MUST_CONTAIN_ONLY_ONE); + if (!referenced) { + notReferencedURIs.add(uri); } - } finally { - monitor.done(); } - if (result == null) { - return Options.newNone(); + monitor.worked(1); + + if (notReferencedURIs.isEmpty()) { + throw new IllegalArgumentException(ZERO_REPRESENTATIONS_FILE_FOUND_IN + modelingProject.getProject().getName() + "\". A modeling project must contain one."); + } else if (notReferencedURIs.size() == 1) { + result = notReferencedURIs.get(0); } else { - return Options.newSome(result); + throw new IllegalArgumentException("Found " + notReferencedURIs.size() + " main representations files (that means not referenced by another) in \"" + + modelingProject.getProject().getName() + "\": " + getFragments(notReferencedURIs) + A_MODELING_PROJECT_MUST_CONTAIN_ONLY_ONE); } + monitor.done(); + return result; } /** |
