Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Fasani2016-05-09 16:02:45 +0000
committerLaurent Fasani2016-06-28 14:49:10 +0000
commitf6b6e2a9ba90f681639b027966545e7172ab7acd (patch)
tree76ba451ad624d6462476576decc97aa21d1cf423
parent72403dc3e4e12b73d5ae12043128fb9ba07ea6f1 (diff)
downloadorg.eclipse.sirius-f6b6e2a9ba90f681639b027966545e7172ab7acd.tar.gz
org.eclipse.sirius-f6b6e2a9ba90f681639b027966545e7172ab7acd.tar.xz
org.eclipse.sirius-f6b6e2a9ba90f681639b027966545e7172ab7acd.zip
[481846] Prevent newer Sirius model loading to avoid potential issues
- We detect only the cases where a VSM or Representations resource has version higher that the newest migration participant. - For Representations and VSM resources version mismatch, we close the session when trying to open it. We provide a mechanism to overload this behavior by providing you own implementation of UICallBack.askSessionReopeningWithResourceVersionMismatch in which you can have an UI feedback letting you choose if you want to open the session anyway. - For VSM resource version mismatch, we prevent the viewpoint to be register in the ViewpointRegistry (A message is added in the log) - When opening the VSM in its editor, natively, the odesign editor displays the errors in the problems tab. - As the code getting and opening the session is mutualized for export and aird open, the monitor work dividing up is defined once (30% for getting session and 70% for opening session) - Tests are added to check VSM and aird version mismatch. - An exception thrown in the resource loading has been a considered but was rejected. Consider the case when the resource is loaded because of proxy resolution. In that cases, the exception is silently caught by ECoreUtil.resolve. It is the case for referenced analysis and for the viewpoint referenced by the View. Bug: 481846 Change-Id: I9e9209ba9b3a3d0ebdaf4661b969d56efa00cb45 Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/Release_Notes.html53
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile12
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/data/unit/resource/481846/481846.aird9
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/data/unit/resource/481846/481846.ecore5
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/data/unit/resource/481846/481846.odesign8
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/data/unit/resource/481846/481846_P1.aird21
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/data/unit/resource/481846/481846_P1.ecore5
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java2
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/session/ResourceVersionMismatchTest.java272
-rw-r--r--plugins/org.eclipse.sirius.ui/plugin.properties3
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionEditorInput.java7
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionUIManager.java1
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/session/SessionUIManagerImpl.java8
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/command/AbstractSWTCallback.java7
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/export/ExportRepresentationsFromFileAction.java101
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/repair/RepresentationFilesRepairAction.java22
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/OpenRepresentationsFileJob.java10
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/manager/ModelingProjectManagerImpl.java6
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/viewpoint/provider/Messages.java14
-rw-r--r--plugins/org.eclipse.sirius/plugin.properties4
-rw-r--r--plugins/org.eclipse.sirius/src-gen/org/eclipse/sirius/viewpoint/description/util/DescriptionResourceImpl.java30
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/componentization/ViewpointRegistryImpl.java43
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/migration/AirdResourceVersionMismatchException.java49
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/migration/DescriptionResourceVersionMismatchException.java49
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/migration/ResourceVersionMismatchDiagnostic.java87
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/modelingproject/ModelingProject.java2
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/SessionManager.java17
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/migration/resource/MigrationUtil.java12
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/resource/AirDResourceImpl.java47
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/SessionManagerImpl.java33
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java40
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/NoUICallback.java6
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/UICallBack.java14
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/viewpoint/Messages.java6
34 files changed, 880 insertions, 125 deletions
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
index dd9c1d4551..ccb1043b0f 100644
--- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
+++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
@@ -90,11 +90,36 @@
</p>
<h2 id="sirius4.1.0">Changes in Sirius 4.1.0</h2>
<h3 id="UserVisibleChanges">User-Visible Changes</h3>
- <p><span class="label label-success">Added</span> The
- <a href="./user/diagrams/Diagrams.html#snap_to_shapes">snap to shape</a> feature is now available on border nodes.
+ <ul>
+ <li><span class="label label-success">Added</span> The
+ <a href="./user/diagrams/Diagrams.html#snap_to_shapes">snap to shape</a> feature is now available on border nodes.
+ </li>
+ <li><span class="label label-info">Modified</span> When trying to open a session which holds a representation resource or a VSP which was saved using a more recent version of Sirius than the one you are using, the session will be automatically closed displaying an error message. You can overload this behavior by providing you own implementation of
+ <code>UICallBack</code> in which you can have an UI feedback letting you choose if you want to open the session anyway. Warning: if you choose to proceed, there is no guarantee that the resulting session will be usable. It may even lead to data loss or corruption; use at your own risk.
+ </li>
+ </ul>
+ <p>If a viewpoint has been defined with a more recent version of Sirius than the one you are using, the
+ <code>ViewpointRegistry</code> will not register it and a warning is logged in the error log view to inform the user.
</p>
<h3 id="SpecifierVisibleChanges">Specifier-Visible Changes</h3>
<h3 id="DeveloperVisibleChanges">Developer-Visible Changes</h3>
+ <h4 id="Changesinorg.eclipse.sirius">Changes in
+ <code>org.eclipse.sirius</code>
+ </h4>
+ <ul>
+ <li><span class="label label-success">Added</span>
+ <code>org.eclipse.sirius.business.api.migration.AirdResourceVersionMismatchException</code> exception has been added to cancel Sirius session opening due to an .aird version mismatch, i.e. when one the of the loaded Representation resources is coming from a newer Sirius release.
+ </li>
+ </ul>
+ <h4 id="Changesinorg.eclipse.sirius.ui">Changes in
+ <code>org.eclipse.sirius.ui</code>
+ </h4>
+ <ul>
+ <li><span class="label label-info">Modified</span>
+ <code>AbstractSWTCallback</code> provides a default implementation of
+ <code>UICallBack.askSessionReopeningWithResourceVersionMismatch()</code> method to give feedback about version mismatch and give the choice to reopen session despite a potential corruption.
+ </li>
+ </ul>
<h4 id="Changesinorg.eclipse.sirius.diagram.ui">Changes in
<code>org.eclipse.sirius.diagram.ui</code>
</h4>
@@ -102,6 +127,9 @@
<li><span class="label label-success">Added</span>
<code>org.eclipse.sirius.diagram.ui.business.api.query.NodeQuery.isDescendantOf(View)</code> has been added to know if a view is a descendant of another view.
</li>
+ <li><span class="label label-success">Added</span>
+ <code>org.eclipse.sirius.diagram.ui.business.api.query.ViewQuery.getAncestor(int...)</code> has been added to retrieve the first ancestor of the view, or itself, that has at least one of the visualID passed as parameter.
+ </li>
</ul>
<h4 id="Changesinorg.eclipse.sirius.ext.gmf.runtime">Changes in
<code>org.eclipse.sirius.ext.gmf.runtime</code>
@@ -113,9 +141,6 @@
<code>org.eclipse.sirius.ext.gmf.runtime.editpolicies</code>. The old class in plug-in
<code>org.eclipse.sirius.ext.gef</code> is deprecated and will be removed in the next version.
</li>
- <li><span class="label label-success">Added</span>
- <code>org.eclipse.sirius.diagram.ui.business.api.query.ViewQuery.getAncestor(int...)</code> has been added to retrieve the first ancestor of the view, or itself, that has at least one of the visualID passed as parameter.
- </li>
</ul>
<h2 id="sirius4.0.0">Changes in Sirius 4.0.0</h2>
<h3 id="UserVisibleChanges2">User-Visible Changes</h3>
@@ -216,7 +241,7 @@
<a href="developer/extensions-provide_custom_bundled_image_shape.html">developer documentation</a> for more details.
</li>
</ul>
- <h4 id="Changesinorg.eclipse.sirius">Changes in
+ <h4 id="Changesinorg.eclipse.sirius2">Changes in
<code>org.eclipse.sirius</code>
</h4>
<ul>
@@ -375,7 +400,7 @@
<code>org.eclipse.sirius.diagram.description.filter.impl.VariableFilterImpl.resetVariables()</code>.
</li>
</ul>
- <h4 id="Changesinorg.eclipse.sirius.ui">Changes in
+ <h4 id="Changesinorg.eclipse.sirius.ui2">Changes in
<code>org.eclipse.sirius.ui</code>
</h4>
<ul>
@@ -522,7 +547,7 @@
<code>org.eclipse.sirius.ext.gmf.runtime.diagram.ui.tools.MoveInDiagramDragTracker</code> has been added to declare states used by all DragTrackers which manage move in diagram using mouse middle click.
</li>
</ul>
- <h4 id="Changesinorg.eclipse.sirius.ui2">Changes in
+ <h4 id="Changesinorg.eclipse.sirius.ui3">Changes in
<code>org.eclipse.sirius.ui</code>
</h4>
<ul>
@@ -926,7 +951,7 @@
<code>org.eclipse.sirius.common.tools.api.contentassist.ContentProposalBuilder</code> used to build the content proposals with their various parameters more easily.
</li>
</ul>
- <h4 id="Changesinorg.eclipse.sirius2">Changes in
+ <h4 id="Changesinorg.eclipse.sirius3">Changes in
<code>org.eclipse.sirius</code>
</h4>
<ul>
@@ -965,7 +990,7 @@
<code>org.eclipse.sirius.tools.api.command.IUndoableCommand</code> interface removed because it is useless since undo/redo is managed by EMF Transaction.
</li>
</ul>
- <h4 id="Changesinorg.eclipse.sirius.ui3">Changes in
+ <h4 id="Changesinorg.eclipse.sirius.ui4">Changes in
<code>org.eclipse.sirius.ui</code>
</h4>
<ul>
@@ -1438,7 +1463,7 @@
<code>org.eclipse.sirius.common.ui.ext</code>.
</li>
</ul>
- <h4 id="Changesinorg.eclipse.sirius3">Changes in
+ <h4 id="Changesinorg.eclipse.sirius4">Changes in
<code>org.eclipse.sirius</code>
</h4>
<ul>
@@ -1574,7 +1599,7 @@
<code>org.eclipse.sirius.viewpoint.DContainer</code> has been removed.
</li>
</ul>
- <h4 id="Changesinorg.eclipse.sirius.ui4">Changes in
+ <h4 id="Changesinorg.eclipse.sirius.ui5">Changes in
<code>org.eclipse.sirius.ui</code>
</h4>
<ul>
@@ -2149,7 +2174,7 @@
<li>&#8220;Lozenge&#8221; is replaced by &#8220;Diamond&#8221; in diagram style.</li>
</ul>
<h3 id="APIChanges">API Changes</h3>
- <h4 id="Changesinorg.eclipse.sirius4">Changes in
+ <h4 id="Changesinorg.eclipse.sirius5">Changes in
<code>org.eclipse.sirius</code>
</h4>
<ul>
@@ -2224,7 +2249,7 @@
<code>org.eclipse.gmf.runtime.emf.core.util.CrossReferenceAdapter</code>. However considering the way Sirius uses GMF, this adapter is not needed.
</li>
</ul>
- <h4 id="Changesinorg.eclipse.sirius.ui5">Changes in
+ <h4 id="Changesinorg.eclipse.sirius.ui6">Changes in
<code>org.eclipse.sirius.ui</code>
</h4>
<ul>
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
index 266560920a..4a0c7a648f 100644
--- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
+++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
@@ -8,12 +8,22 @@ h2(#sirius4.1.0). Changes in Sirius 4.1.0
h3. User-Visible Changes
-<span class="label label-success">Added</span> The "snap to shape":./user/diagrams/Diagrams.html#snap_to_shapes feature is now available on border nodes.
+* <span class="label label-success">Added</span> The "snap to shape":./user/diagrams/Diagrams.html#snap_to_shapes feature is now available on border nodes.
+* <span class="label label-info">Modified</span> When trying to open a session which holds a representation resource or a VSP which was saved using a more recent version of Sirius than the one you are using, the session will be automatically closed displaying an error message. You can overload this behavior by providing you own implementation of @UICallBack@ in which you can have an UI feedback letting you choose if you want to open the session anyway. Warning: if you choose to proceed, there is no guarantee that the resulting session will be usable. It may even lead to data loss or corruption; use at your own risk.
+If a viewpoint has been defined with a more recent version of Sirius than the one you are using, the @ViewpointRegistry@ will not register it and a warning is logged in the error log view to inform the user.
h3. Specifier-Visible Changes
h3. Developer-Visible Changes
+h4. Changes in @org.eclipse.sirius@
+
+* <span class="label label-success">Added</span> @org.eclipse.sirius.business.api.migration.AirdResourceVersionMismatchException@ exception has been added to cancel Sirius session opening due to an .aird version mismatch, i.e. when one the of the loaded Representation resources is coming from a newer Sirius release.
+
+h4. Changes in @org.eclipse.sirius.ui@
+
+* <span class="label label-info">Modified</span> @AbstractSWTCallback@ provides a default implementation of @UICallBack.askSessionReopeningWithResourceVersionMismatch()@ method to give feedback about version mismatch and give the choice to reopen session despite a potential corruption.
+
h4. Changes in @org.eclipse.sirius.diagram.ui@
* <span class="label label-success">Added</span> @org.eclipse.sirius.diagram.ui.business.api.query.NodeQuery.isDescendantOf(View)@ has been added to know if a view is a descendant of another view.
diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/resource/481846/481846.aird b/plugins/org.eclipse.sirius.tests.junit/data/unit/resource/481846/481846.aird
new file mode 100644
index 0000000000..e090976d2d
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/resource/481846/481846.aird
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<viewpoint:DAnalysis xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:viewpoint="http://www.eclipse.org/sirius/1.1.0" xsi:schemaLocation="http://www.eclipse.org/sirius/description/1.1.0 http://www.eclipse.org/sirius/1.1.0#//description" xmi:id="_CXrBEMBOEeWh0IJrZasdZw" selectedViews="_C3X00MBOEeWh0IJrZasdZw" version="11.0.0.201604141600">
+ <referencedAnalysis xmi:type="viewpoint:DAnalysis" href="481846_P1.aird#_aNO2ABaHEea7dLNhUHPoGg"/>
+ <semanticResources>481846.ecore</semanticResources>
+ <semanticResources>481846_P1.ecore</semanticResources>
+ <ownedViews xmi:type="viewpoint:DView" xmi:id="_C3X00MBOEeWh0IJrZasdZw">
+ <viewpoint xmi:type="description:Viewpoint" href="481846.odesign#//@ownedViewpoints[name='Viewpoint_481846']"/>
+ </ownedViews>
+</viewpoint:DAnalysis>
diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/resource/481846/481846.ecore b/plugins/org.eclipse.sirius.tests.junit/data/unit/resource/481846/481846.ecore
new file mode 100644
index 0000000000..9a7f66531f
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/resource/481846/481846.ecore
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
+ name="P0">
+ <eSubpackages href="481846_P1.ecore#/"/>
+</ecore:EPackage>
diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/resource/481846/481846.odesign b/plugins/org.eclipse.sirius.tests.junit/data/unit/resource/481846/481846.odesign
new file mode 100644
index 0000000000..e1502e4d10
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/resource/481846/481846.odesign
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<description:Group xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/diagram/description/1.1.0" name="My" version="11.0.0.201601261200">
+ <ownedViewpoints name="Viewpoint_481846" modelFileExtension="ecore">
+ <ownedRepresentations xsi:type="description_1:DiagramDescription" name="DiagDesc" domainClass="ecore.EPackage" enablePopupBars="true">
+ <defaultLayer name="Default"/>
+ </ownedRepresentations>
+ </ownedViewpoints>
+</description:Group>
diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/resource/481846/481846_P1.aird b/plugins/org.eclipse.sirius.tests.junit/data/unit/resource/481846/481846_P1.aird
new file mode 100644
index 0000000000..11f4d2db5a
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/resource/481846/481846_P1.aird
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<viewpoint:DAnalysis xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/diagram/description/1.1.0" xmlns:diagram="http://www.eclipse.org/sirius/diagram/1.1.0" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:viewpoint="http://www.eclipse.org/sirius/1.1.0" xsi:schemaLocation="http://www.eclipse.org/sirius/description/1.1.0 http://www.eclipse.org/sirius/1.1.0#//description http://www.eclipse.org/sirius/diagram/description/1.1.0 http://www.eclipse.org/sirius/diagram/1.1.0#//description" xmi:id="_aNO2ABaHEea7dLNhUHPoGg" selectedViews="_aNpswBaHEea7dLNhUHPoGg" version="11.0.0.201604141600">
+ <semanticResources>481846_P1.ecore</semanticResources>
+ <ownedViews xmi:type="viewpoint:DView" xmi:id="_aNpswBaHEea7dLNhUHPoGg">
+ <viewpoint xmi:type="description:Viewpoint" href="481846.odesign#//@ownedViewpoints[name='Viewpoint_481846']"/>
+ <ownedRepresentations xmi:type="diagram:DSemanticDiagram" xmi:id="_XM-mgBaGEea7dLNhUHPoGg" name="new DiagDesc">
+ <ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_XNHwcBaGEea7dLNhUHPoGg" source="DANNOTATION_CUSTOMIZATION_KEY">
+ <data xmi:type="diagram:ComputedStyleDescriptionRegistry" xmi:id="_XNHwcRaGEea7dLNhUHPoGg"/>
+ </ownedAnnotationEntries>
+ <ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_XO-xoBaGEea7dLNhUHPoGg" source="GMF_DIAGRAMS">
+ <data xmi:type="notation:Diagram" xmi:id="_XO-xoRaGEea7dLNhUHPoGg" type="Sirius" element="_XM-mgBaGEea7dLNhUHPoGg" measurementUnit="Pixel">
+ <styles xmi:type="notation:DiagramStyle" xmi:id="_XO-xohaGEea7dLNhUHPoGg"/>
+ </data>
+ </ownedAnnotationEntries>
+ <description xmi:type="description_1:DiagramDescription" href="481846.odesign#//@ownedViewpoints[name='Viewpoint_481846']/@ownedRepresentations[name='DiagDesc']"/>
+ <filterVariableHistory xmi:type="diagram:FilterVariableHistory" xmi:id="_XNHwchaGEea7dLNhUHPoGg"/>
+ <activatedLayers xmi:type="description_1:Layer" href="481846.odesign#//@ownedViewpoints[name='Viewpoint_481846']/@ownedRepresentations[name='DiagDesc']/@defaultLayer"/>
+ <target xmi:type="ecore:EPackage" href="481846_P1.ecore#/"/>
+ </ownedRepresentations>
+ </ownedViews>
+</viewpoint:DAnalysis>
diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/resource/481846/481846_P1.ecore b/plugins/org.eclipse.sirius.tests.junit/data/unit/resource/481846/481846_P1.ecore
new file mode 100644
index 0000000000..c746e4f94a
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/resource/481846/481846_P1.ecore
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="P1">
+ <eClassifiers xsi:type="ecore:EClass" name="E1"/>
+</ecore:EPackage>
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java
index a79d4b50ce..f15d141333 100644
--- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java
+++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java
@@ -54,6 +54,7 @@ import org.eclipse.sirius.tests.unit.api.session.SessionServiceTest;
import org.eclipse.sirius.tests.unit.api.session.SiriusComparatorTests;
import org.eclipse.sirius.tests.unit.api.session.SiriusRegistryListener2Tests;
import org.eclipse.sirius.tests.unit.api.session.SiriusRegistryTests;
+import org.eclipse.sirius.tests.unit.api.session.ResourceVersionMismatchTest;
import org.eclipse.sirius.tests.unit.api.session.ViewpointSelectionTests;
import org.eclipse.sirius.tests.unit.api.tools.SiriusControlAndCrossReferenceInMultiSessionTest;
import org.eclipse.sirius.tests.unit.api.vsm.edit.SiriusAdapterFactoryRegistryTest;
@@ -249,6 +250,7 @@ public class AllCommonPluginTests extends TestCase {
suite.addTestSuite(SampleSessionTest.class);
suite.addTestSuite(SessionEditorInputTests.class);
suite.addTestSuite(SiriusRegistryTests.class);
+ suite.addTestSuite(ResourceVersionMismatchTest.class);
suite.addTestSuite(SiriusRegistryListener2Tests.class);
suite.addTestSuite(SessionSemanticResourceTests.class);
suite.addTestSuite(SessionServiceTest.class);
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/session/ResourceVersionMismatchTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/session/ResourceVersionMismatchTest.java
new file mode 100644
index 0000000000..156fa69c2a
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/session/ResourceVersionMismatchTest.java
@@ -0,0 +1,272 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.sirius.tests.unit.api.session;
+
+import static org.junit.Assert.assertNotEquals;
+
+import java.io.IOException;
+import java.util.Set;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CommandStack;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.edit.command.SetCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jdt.internal.corext.util.Messages;
+import org.eclipse.sirius.business.api.componentization.ViewpointRegistry;
+import org.eclipse.sirius.business.api.migration.AirdResourceVersionMismatchException;
+import org.eclipse.sirius.business.api.session.Session;
+import org.eclipse.sirius.business.api.session.SessionManager;
+import org.eclipse.sirius.business.internal.migration.RepresentationsFileMigrationService;
+import org.eclipse.sirius.business.internal.migration.description.VSMMigrationService;
+import org.eclipse.sirius.tests.SiriusTestsPlugin;
+import org.eclipse.sirius.tests.support.api.EclipseTestsSupportHelper;
+import org.eclipse.sirius.tests.support.api.SiriusTestCase;
+import org.eclipse.sirius.tools.api.command.ICommandFactory;
+import org.eclipse.sirius.tools.api.command.ui.NoUICallback;
+import org.eclipse.sirius.tools.api.command.ui.UICallBack;
+import org.eclipse.sirius.viewpoint.ViewpointPackage;
+import org.eclipse.sirius.viewpoint.description.DescriptionPackage;
+import org.eclipse.sirius.viewpoint.description.Viewpoint;
+import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin;
+import org.osgi.framework.Version;
+
+/**
+ * Test class for Bug 481846 about preventing loading of Sirius resource coming
+ * from a newer Sirius release.
+ *
+ * @author <a href="mailto:esteban.dugueperoux@obeo.fr">Esteban Dugueperoux</a>
+ */
+public class ResourceVersionMismatchTest extends SiriusTestCase {
+
+ private static final String PATH = "/data/unit/resource/481846/";
+
+ private static final String SESSION_MODEL_FILENAME = "481846.aird";
+
+ private static final String SESSION_MODEL_FRAGMENT_FILENAME = "481846_P1.aird";
+
+ private static final String SEMANTIC_MODEL_FILENAME = "481846.ecore";
+
+ private static final String SEMANTIC_MODEL_FRAGMENT_FILENAME = "481846_P1.ecore";
+
+ private static final String ODESIGN_MODEL_FILENAME = "481846.odesign";
+
+ private static final String VIEWPOINT_NAME = "Viewpoint_481846";
+
+ private static final String SESSION_NOT_IN_SESSIONMANAGER = "The session should not be registered in the SessionManager";
+
+ private static final String WARNING_LOGGED = "An warning should have been logged indicating that the viewpoint registry did not register the VSM because of the version mismatch";
+
+ private static final String THROWN_EXCEPTION = "A {0} should be thrown because we try to open some {1} model coming from newer Sirius release";
+
+ private URI sessionResourceURI;
+
+ /**
+ * If true, indicates that the session must be opened even if there a
+ * version mismatch.
+ */
+ private boolean forceOpeningSession = true;
+
+ /**
+ * The UICallBack as it is before starting this test class.
+ */
+ private UICallBack defaultUiCallback;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ EclipseTestsSupportHelper.INSTANCE.createProject(TEMPORARY_PROJECT_NAME);
+ EclipseTestsSupportHelper.INSTANCE.copyFile(SiriusTestsPlugin.PLUGIN_ID, PATH + SEMANTIC_MODEL_FILENAME, TEMPORARY_PROJECT_NAME + "/" + SEMANTIC_MODEL_FILENAME);
+ EclipseTestsSupportHelper.INSTANCE.copyFile(SiriusTestsPlugin.PLUGIN_ID, PATH + SESSION_MODEL_FRAGMENT_FILENAME, TEMPORARY_PROJECT_NAME + "/" + SESSION_MODEL_FRAGMENT_FILENAME);
+ EclipseTestsSupportHelper.INSTANCE.copyFile(SiriusTestsPlugin.PLUGIN_ID, PATH + ODESIGN_MODEL_FILENAME, TEMPORARY_PROJECT_NAME + "/" + ODESIGN_MODEL_FILENAME);
+ EclipseTestsSupportHelper.INSTANCE.copyFile(SiriusTestsPlugin.PLUGIN_ID, PATH + SESSION_MODEL_FILENAME, TEMPORARY_PROJECT_NAME + "/" + SESSION_MODEL_FILENAME);
+ EclipseTestsSupportHelper.INSTANCE.copyFile(SiriusTestsPlugin.PLUGIN_ID, PATH + SEMANTIC_MODEL_FRAGMENT_FILENAME, TEMPORARY_PROJECT_NAME + "/" + SEMANTIC_MODEL_FRAGMENT_FILENAME);
+ sessionResourceURI = URI.createPlatformResourceURI(TEMPORARY_PROJECT_NAME + "/" + SESSION_MODEL_FILENAME, true);
+
+ // Setting no UI callback
+ defaultUiCallback = SiriusEditPlugin.getPlugin().getUiCallback();
+ SiriusEditPlugin.getPlugin().setUiCallback(new NoUICallback() {
+ @Override
+ public boolean askSessionReopeningWithResourceVersionMismatch(AirdResourceVersionMismatchException e) {
+ return forceOpeningSession;
+ }
+ });
+ }
+
+ /**
+ * Test session opening when the main aird has a version from a more recent
+ * Sirius release </br>
+ * Test also session opening ignoring this version mismatch.
+ */
+ public void testMainAirdResourceVersionMismatch() {
+ // Setup a session with valid VSM and invalid main aird
+ setupFileVersionMismatch(false, true, false);
+
+ // check
+ checkAirdVersionMismatch();
+ }
+
+ /**
+ * Test session opening when an referenced aird has a version from a more
+ * recent Sirius release </br>
+ * Test also session opening ignoring this version mismatch.
+ */
+ public void testReferencedAirdResourceVersionMismatch() {
+ // Setup a session with valid VSM and invalid referenced aird
+ setupFileVersionMismatch(false, false, true);
+
+ // check
+ checkAirdVersionMismatch();
+ }
+
+ private void checkAirdVersionMismatch() {
+ // check opening the session anyway
+ forceOpeningSession = true;
+ Session session = SessionManager.INSTANCE.openSession(sessionResourceURI, new NullProgressMonitor(), SiriusEditPlugin.getPlugin().getUiCallback());
+ assertNotNull("The session should have opened ignoring the aird version mismatch", session);
+ session.close(new NullProgressMonitor());
+
+ // check stopping session opening
+ try {
+ forceOpeningSession = false;
+ clearErrors();
+ session = SessionManager.INSTANCE.openSession(sessionResourceURI, new NullProgressMonitor(), SiriusEditPlugin.getPlugin().getUiCallback());
+ String[] args = { AirdResourceVersionMismatchException.class.getName(), "aird" };
+ fail(Messages.format(THROWN_EXCEPTION, args));
+ } catch (RuntimeException e) {
+ assertEquals("The raised exception should be a " + AirdResourceVersionMismatchException.class.getName(), AirdResourceVersionMismatchException.class.getName(), e.getClass().getName());
+ }
+ assertTrue(SESSION_NOT_IN_SESSIONMANAGER, SessionManager.INSTANCE.getSessions().isEmpty());
+ }
+
+ /**
+ * Test that the ViewpointRegistry does not register a VSM which has a
+ * version from a more recent Sirius release </br>
+ */
+ public void testViewRegistryWithVSMResourceVersionMismatch() {
+ // Initialize error/warning log and uncaught exception handlers
+ initLoggers();
+ setWarningCatchActive(true);
+ clearWarnings();
+
+ // Setup a session with invalid VSM and valid aird
+ setupFileVersionMismatch(true, false, false);
+
+ // check that the viewpoint Registry has logged a warning
+ assertTrue(WARNING_LOGGED, doesAWarningOccurs());
+ clearWarnings();
+
+ Set<Viewpoint> viewpoints = ViewpointRegistry.getInstance().getViewpoints();
+ for (Viewpoint viewpoint : viewpoints) {
+ assertNotEquals("The Viewpoint " + VIEWPOINT_NAME + " should not registered in the viewpoint registry", viewpoint.getName());
+ }
+ }
+
+ /**
+ * Test session opening when a selected VSM aird has a version from a more
+ * recent Sirius release </br>
+ * Test also session opening ignoring this version mismatch.
+ */
+ public void testVSMResourceVersionMismatch() {
+ // Setup a session with invalid VSM and valid aird
+ setupFileVersionMismatch(true, false, false);
+
+ // Test
+ Session session = null;
+ try {
+ clearErrors();
+ session = SessionManager.INSTANCE.openSession(sessionResourceURI, new NullProgressMonitor(), SiriusEditPlugin.getPlugin().getUiCallback());
+ fail(Messages.format(THROWN_EXCEPTION, new String[] { RuntimeException.class.getName(), "VSM" }));
+ } catch (RuntimeException e) {
+ }
+ assertTrue(SESSION_NOT_IN_SESSIONMANAGER, SessionManager.INSTANCE.getSessions().isEmpty());
+ }
+
+ /**
+ * Test session opening when a selected VSM and an aird have a version from
+ * a more recent Sirius release </br>
+ * Test also session opening ignoring this version mismatch.
+ */
+ public void testVSMAndAirdResourceVersionMismatch() {
+ // Setup a session with invalid VSM aird
+ setupFileVersionMismatch(true, true, false);
+
+ // Test
+ try {
+ SessionManager.INSTANCE.openSession(sessionResourceURI, new NullProgressMonitor(), SiriusEditPlugin.getPlugin().getUiCallback());
+ String[] args = { AirdResourceVersionMismatchException.class.getName(), "VSM" };
+ fail(Messages.format(THROWN_EXCEPTION, args));
+ } catch (RuntimeException e) {
+ }
+ assertTrue(SESSION_NOT_IN_SESSIONMANAGER, SessionManager.INSTANCE.getSessions().isEmpty());
+ }
+
+ private void setupFileVersionMismatch(boolean setupInvalidVSM, boolean setupInvalidMainAird, boolean setupInvalidReferencedAird) {
+ // Session creation
+ Session session = SessionManager.INSTANCE.getSession(sessionResourceURI, new NullProgressMonitor());
+ session.open(new NullProgressMonitor());
+ TransactionalEditingDomain domain = session.getTransactionalEditingDomain();
+ CommandStack commandStack = domain.getCommandStack();
+
+ // Change VSM and Representations resources to a newer version
+ if (setupInvalidVSM) {
+ Viewpoint vp = session.getSelectedViewpoints(false).iterator().next();
+ assertEquals("Bad viewpoint name", VIEWPOINT_NAME, vp.getName());
+ EObject group = vp.eContainer();
+ Version lastMigrationVersion = VSMMigrationService.getInstance().getLastMigrationVersion();
+ Version newVersion = new Version(lastMigrationVersion.getMajor() + 1, lastMigrationVersion.getMinor(), lastMigrationVersion.getMicro(), lastMigrationVersion.getQualifier());
+ Command changeVersionCmd = SetCommand.create(domain, group, DescriptionPackage.Literals.GROUP__VERSION, newVersion.toString());
+ assertTrue(changeVersionCmd.canExecute());
+ commandStack.execute(changeVersionCmd);
+ try {
+ group.eResource().save(null);
+ } catch (IOException e) {
+ }
+ }
+
+ if (setupInvalidMainAird) {
+ Resource sessionResource = session.getSessionResource();
+ EObject dAnalysis = sessionResource.getContents().get(0);
+ Version lastMigrationVersion = RepresentationsFileMigrationService.getInstance().getLastMigrationVersion();
+ Version newVersion = new Version(lastMigrationVersion.getMajor() + 1, lastMigrationVersion.getMinor(), lastMigrationVersion.getMicro(), lastMigrationVersion.getQualifier());
+ Command changeVersionCmd = SetCommand.create(domain, dAnalysis, ViewpointPackage.Literals.DANALYSIS__VERSION, newVersion.toString());
+ assertTrue(changeVersionCmd.canExecute());
+ commandStack.execute(changeVersionCmd);
+ }
+
+ if (setupInvalidReferencedAird) {
+ Set<Resource> referencedSessions = session.getReferencedSessionResources();
+ EObject dAnalysis = referencedSessions.iterator().next().getContents().get(0);;
+ Version lastMigrationVersion = RepresentationsFileMigrationService.getInstance().getLastMigrationVersion();
+ Version newVersion = new Version(lastMigrationVersion.getMajor() + 1, lastMigrationVersion.getMinor(), lastMigrationVersion.getMicro(), lastMigrationVersion.getQualifier());
+ Command changeVersionCmd = SetCommand.create(domain, dAnalysis, ViewpointPackage.Literals.DANALYSIS__VERSION, newVersion.toString());
+ assertTrue(changeVersionCmd.canExecute());
+ commandStack.execute(changeVersionCmd);
+ }
+
+ session.save(new NullProgressMonitor());
+ session.close(new NullProgressMonitor());
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ if (defaultUiCallback != null) {
+ SiriusEditPlugin.getPlugin().setUiCallback(defaultUiCallback);
+ }
+ sessionResourceURI = null;
+ super.tearDown();
+ }
+
+ @Override
+ protected ICommandFactory getCommandFactory() {
+ return null;
+ }
+}
diff --git a/plugins/org.eclipse.sirius.ui/plugin.properties b/plugins/org.eclipse.sirius.ui/plugin.properties
index e01abd7bef..0ff32d5550 100644
--- a/plugins/org.eclipse.sirius.ui/plugin.properties
+++ b/plugins/org.eclipse.sirius.ui/plugin.properties
@@ -49,6 +49,9 @@ AddModelDependencyAction_error = Error adding model dependency
AddModelDependencyAction_resourceSelectionMessage = Select resources to add
AddModelDependencyAction_title = Add Model
AddSemanticResourceAction_title = Add Model
+AskSessionOpeningRunnable_title = Session resource version mismatch
+AskSessionOpeningRunnable_message_aird = You are trying to open a session with an .aird file coming from a more recent Sirius release:\n\n\t{0}\n
+AskSessionOpeningRunnable_message_confirm = \nThe result is unpredictable and can lead to data corruption. Are you sure you want to open it?
ChangeViewpointSelectionCommand_activationError = Unable to activate viewpoint ''{0}'' because of insufficient rights.
ChangeViewpointSelectionCommand_applySelectionTask = Apply new viewpoints selection...
ChangeViewpointSelectionCommand_deselectViewpointTask = Deselect viewpoint: {0}
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionEditorInput.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionEditorInput.java
index 13cad86428..106ba387ad 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionEditorInput.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionEditorInput.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2015 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2007, 2016 THALES GLOBAL SERVICES and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -225,10 +225,7 @@ public class SessionEditorInput extends URIEditorInput {
// previously closed session.
if (sessionFromURI == null && restore) {
status = Status.OK_STATUS;
- sessionFromURI = SessionManager.INSTANCE.getSession(sessionModelURI, new NullProgressMonitor());
- if (sessionFromURI != null && !sessionFromURI.isOpen()) {
- sessionFromURI.open(new NullProgressMonitor());
- }
+ sessionFromURI = SessionManager.INSTANCE.openSession(sessionModelURI, new NullProgressMonitor(), SiriusEditPlugin.getPlugin().getUiCallback());
}
if (sessionFromURI != null && sessionFromURI.isOpen()) {
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionUIManager.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionUIManager.java
index 85d344b4d6..e5405f279f 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionUIManager.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionUIManager.java
@@ -68,4 +68,5 @@ public interface SessionUIManager {
* @return all ui sessions.
*/
Collection<IEditingSession> getUISessions();
+
}
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/session/SessionUIManagerImpl.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/session/SessionUIManagerImpl.java
index 1586c13c31..8561205cdc 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/session/SessionUIManagerImpl.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/session/SessionUIManagerImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2014 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2008, 2016 THALES GLOBAL SERVICES and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -69,6 +69,7 @@ public final class SessionUIManagerImpl extends SessionManagerListener.Stub impl
*
* {@inheritDoc}
*/
+ @Override
public IEditingSession createUISession(final Session session) {
UISessionFactory uiSessionFactory = UISessionFactoryService.INSTANCE.getUISessionFactory();
IEditingSession editingSession = uiSessionFactory.createUISession(session);
@@ -80,6 +81,7 @@ public final class SessionUIManagerImpl extends SessionManagerListener.Stub impl
*
* {@inheritDoc}
*/
+ @Override
public IEditingSession getUISession(final Session session) {
final IEditingSession editingSession = sessionToUISession.get(session);
return editingSession;
@@ -89,6 +91,7 @@ public final class SessionUIManagerImpl extends SessionManagerListener.Stub impl
*
* {@inheritDoc}
*/
+ @Override
public void remove(final IEditingSession uiSession) {
final Collection<Session> toRemove = new ArrayList<Session>();
for (final Map.Entry<Session, IEditingSession> entry : sessionToUISession.entrySet()) {
@@ -101,6 +104,7 @@ public final class SessionUIManagerImpl extends SessionManagerListener.Stub impl
}
}
+ @Override
public Collection<IEditingSession> getUISessions() {
return sessionToUISession.values();
}
@@ -265,6 +269,7 @@ public final class SessionUIManagerImpl extends SessionManagerListener.Stub impl
*
* {@inheritDoc}
*/
+ @Override
public IEditingSession getOrCreateUISession(final Session session) {
IEditingSession uiSession = getUISession(session);
if (uiSession == null) {
@@ -272,5 +277,4 @@ public final class SessionUIManagerImpl extends SessionManagerListener.Stub impl
}
return uiSession;
}
-
}
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/command/AbstractSWTCallback.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/command/AbstractSWTCallback.java
index c93ba81af5..7ff1459bbc 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/command/AbstractSWTCallback.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/command/AbstractSWTCallback.java
@@ -38,6 +38,7 @@ import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.sirius.business.api.helper.SelectionDescriptionHelper;
import org.eclipse.sirius.business.api.helper.SiriusUtil;
+import org.eclipse.sirius.business.api.migration.AirdResourceVersionMismatchException;
import org.eclipse.sirius.business.api.query.URIQuery;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter;
@@ -361,4 +362,10 @@ public abstract class AbstractSWTCallback implements UICallBack {
MessageDialog.openError(getActiveShell(), title, message);
}
}
+
+ @Override
+ public boolean askSessionReopeningWithResourceVersionMismatch(AirdResourceVersionMismatchException e) {
+ return false;
+ }
+
}
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/export/ExportRepresentationsFromFileAction.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/export/ExportRepresentationsFromFileAction.java
index 1f5d9a4393..dcc966c1f1 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/export/ExportRepresentationsFromFileAction.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/export/ExportRepresentationsFromFileAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2015 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2007, 2016 THALES GLOBAL SERVICES and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -66,63 +66,60 @@ public class ExportRepresentationsFromFileAction implements IObjectActionDelegat
final IPath targetPath = this.sessionResourceFile.getParent().getLocation();
final URI sessionResourceURI = URI.createPlatformResourceURI(sessionResourceFile.getFullPath().toOSString(), true);
Session session = SessionManager.INSTANCE.getSession(sessionResourceURI, new SubProgressMonitor(new NullProgressMonitor(), 1));
+ if (session != null) {
+ final Collection<DRepresentation> dRepresentationsToExportAsImage = DialectManager.INSTANCE.getAllRepresentations(session);
+ if (!dRepresentationsToExportAsImage.isEmpty()) {
+ final ExportSeveralRepresentationsAsImagesDialog dialog = new ExportSeveralRepresentationsAsImagesDialog(shell, targetPath);
+ if (dialog.open() == Window.CANCEL) {
+ dialog.close();
+ return;
+ }
- final Collection<DRepresentation> dRepresentationsToExportAsImage = DialectManager.INSTANCE.getAllRepresentations(session);
- if (!dRepresentationsToExportAsImage.isEmpty()) {
- final ExportSeveralRepresentationsAsImagesDialog dialog = new ExportSeveralRepresentationsAsImagesDialog(shell, targetPath);
- if (dialog.open() == Window.CANCEL) {
- dialog.close();
- return;
- }
-
- final IPath outputPath = dialog.getOutputPath();
- final ImageFileFormat imageFormat = dialog.getImageFormat();
- final boolean exportToHtml = dialog.isExportToHtml();
-
- IRunnableWithProgress exportAllRepresentationsRunnable = new WorkspaceModifyOperation() {
-
- @Override
- protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
- Session session = null;
- boolean isOpen = false;
- try {
- monitor.beginTask(Messages.ExportRepresentationsFromFileAction_exportTask, 10);
- session = SessionManager.INSTANCE.getSession(sessionResourceURI, new SubProgressMonitor(monitor, 1));
- isOpen = session.isOpen();
- if (!isOpen) {
- session.open(new SubProgressMonitor(monitor, 1));
- }
-
- ExportAction exportAction = new ExportAction(session, dRepresentationsToExportAsImage, outputPath, imageFormat, exportToHtml);
- exportAction.run(new SubProgressMonitor(monitor, 7));
-
- } finally {
- if (!isOpen && session != null) {
- session.close(new SubProgressMonitor(monitor, 1));
+ final IPath outputPath = dialog.getOutputPath();
+ final ImageFileFormat imageFormat = dialog.getImageFormat();
+ final boolean exportToHtml = dialog.isExportToHtml();
+
+ IRunnableWithProgress exportAllRepresentationsRunnable = new WorkspaceModifyOperation() {
+
+ @Override
+ protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
+ Session session = null;
+ boolean isOpen = false;
+ try {
+ monitor.beginTask(Messages.ExportRepresentationsFromFileAction_exportTask, 10);
+ session = SessionManager.INSTANCE.openSession(sessionResourceURI, new SubProgressMonitor(monitor, 2), SiriusEditPlugin.getPlugin().getUiCallback());
+
+ if (session != null) {
+ ExportAction exportAction = new ExportAction(session, dRepresentationsToExportAsImage, outputPath, imageFormat, exportToHtml);
+ exportAction.run(new SubProgressMonitor(monitor, 7));
+ }
+ } finally {
+ if (!isOpen && session != null) {
+ session.close(new SubProgressMonitor(monitor, 1));
+ }
+ monitor.done();
}
- monitor.done();
}
- }
- };
-
- final ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
- try {
- pmd.run(false, false, exportAllRepresentationsRunnable);
- } catch (final InvocationTargetException e) {
- SiriusEditPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, SiriusEditPlugin.ID, e.getLocalizedMessage(), e));
- MessageDialog.openError(shell, Messages.ExportRepresentationsFromFileAction_errorDialog_title, e.getTargetException().getMessage());
- } catch (final InterruptedException e) {
- SiriusEditPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, SiriusEditPlugin.ID, e.getLocalizedMessage(), e));
- MessageDialog.openInformation(shell, Messages.ExportRepresentationsFromFileAction_interruptedDialog_title, e.getMessage());
- } finally {
- pmd.close();
+ };
+
+ final ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
+ try {
+ pmd.run(false, false, exportAllRepresentationsRunnable);
+ } catch (final InvocationTargetException e) {
+ SiriusEditPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, SiriusEditPlugin.ID, e.getLocalizedMessage(), e));
+ MessageDialog.openError(shell, Messages.ExportRepresentationsFromFileAction_errorDialog_title, e.getTargetException().getMessage());
+ } catch (final InterruptedException e) {
+ SiriusEditPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, SiriusEditPlugin.ID, e.getLocalizedMessage(), e));
+ MessageDialog.openInformation(shell, Messages.ExportRepresentationsFromFileAction_interruptedDialog_title, e.getMessage());
+ } finally {
+ pmd.close();
+ }
+ } else {
+ MessageDialog.openInformation(Display.getCurrent().getActiveShell(), Messages.ExportRepresentationsFromFileAction_noRepresentationsDialog_title,
+ Messages.ExportRepresentationsFromFileAction_noRepresentationsDialog_message);
}
- } else {
- MessageDialog.openInformation(Display.getCurrent().getActiveShell(), Messages.ExportRepresentationsFromFileAction_noRepresentationsDialog_title,
- Messages.ExportRepresentationsFromFileAction_noRepresentationsDialog_message);
}
-
}
@Override
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/repair/RepresentationFilesRepairAction.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/repair/RepresentationFilesRepairAction.java
index 710c89b741..ee66153c6b 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/repair/RepresentationFilesRepairAction.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/repair/RepresentationFilesRepairAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2015 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2007, 2016 THALES GLOBAL SERVICES and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -21,9 +21,13 @@ import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.sirius.business.api.migration.AirdResourceVersionMismatchException;
import org.eclipse.sirius.business.api.repair.SiriusRepairProcess;
+import org.eclipse.sirius.business.internal.migration.resource.MigrationUtil;
+import org.eclipse.sirius.tools.api.command.ui.UICallBack;
import org.eclipse.sirius.viewpoint.SiriusPlugin;
import org.eclipse.sirius.viewpoint.provider.Messages;
+import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionDelegate;
@@ -56,6 +60,22 @@ public class RepresentationFilesRepairAction extends ActionDelegate {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ try {
+ repair(monitor);
+ } catch (AirdResourceVersionMismatchException e) {
+ UICallBack uiCallback = SiriusEditPlugin.getPlugin().getUiCallback();
+ if (uiCallback != null && uiCallback.askSessionReopeningWithResourceVersionMismatch(e)) {
+ try {
+ MigrationUtil.ignoreVersionMismatch = true;
+ repair(monitor);
+ } finally {
+ MigrationUtil.ignoreVersionMismatch = false;
+ }
+ }
+ }
+ }
+
+ private void repair(IProgressMonitor monitor) throws InterruptedException {
SiriusRepairProcess process = new SiriusRepairProcess(file, true);
process.run(monitor);
process.dispose();
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/OpenRepresentationsFileJob.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/OpenRepresentationsFileJob.java
index b0d4d3aa31..87a0ce89c3 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/OpenRepresentationsFileJob.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/OpenRepresentationsFileJob.java
@@ -42,6 +42,7 @@ import org.eclipse.sirius.ui.business.api.session.SessionUIManager;
import org.eclipse.sirius.ui.tools.api.project.ModelingProjectManager;
import org.eclipse.sirius.viewpoint.SiriusPlugin;
import org.eclipse.sirius.viewpoint.provider.Messages;
+import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
@@ -144,7 +145,7 @@ public class OpenRepresentationsFileJob extends AbstractRepresentationsFileJob {
*
* @param monitor
* the progress monitor.
- * @return the opened session.
+ * @return the opened {@link Session}.
*/
private Session performOpenSession(IProgressMonitor monitor) {
Session session = null;
@@ -152,14 +153,9 @@ public class OpenRepresentationsFileJob extends AbstractRepresentationsFileJob {
SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.OpenRepresentationsFileJob_loadRepresentationsTask, 16);
if (SiriusUtil.SESSION_RESOURCE_EXTENSION.equals(representationsFileURI.fileExtension())) {
subMonitor.worked(1);
- session = SessionManager.INSTANCE.getSession(representationsFileURI, subMonitor.newChild(10));
- // Open the session if needed (load the referenced models by
- // a ResolveAll call)
subMonitor.subTask(MessageFormat.format(Messages.OpenRepresentationsFileJob_loadReferencedModelsTask, representationsFileURI.lastSegment()));
+ session = SessionManager.INSTANCE.openSession(representationsFileURI, subMonitor.newChild(14), SiriusEditPlugin.getPlugin().getUiCallback());
if (session != null) {
- if (!session.isOpen()) {
- session.open(subMonitor.newChild(4));
- }
IEditingSession editingSession = SessionUIManager.INSTANCE.getOrCreateUISession(session);
if (!editingSession.isOpen()) {
editingSession.open();
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 da90763d1b..cc559b1105 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
@@ -84,6 +84,12 @@ public class ModelingProjectManagerImpl implements ModelingProjectManager {
// ModelingProjectManager.loadAndOpenSession().
} else if (notification == SessionListener.OPENED) {
sessionFileLoading.remove(updated.getSessionResource().getURI());
+ } else if (notification == SessionListener.CLOSED) {
+ // make sure that the session is re-openable if CLOSED
+ // That is necessary because the session may not have opened
+ // correctly and the SessionListener.OPENED may not have been
+ // sent.
+ sessionFileLoading.remove(updated.getSessionResource().getURI());
}
}
};
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/viewpoint/provider/Messages.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/viewpoint/provider/Messages.java
index 314ab2b198..3d86150256 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/viewpoint/provider/Messages.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/viewpoint/provider/Messages.java
@@ -130,6 +130,14 @@ public final class Messages {
@TranslatableMessage
public static String AddSemanticResourceAction_title;
+ public static String AskSessionOpeningRunnable_title;
+
+ @TranslatableMessage
+ public static String AskSessionOpeningRunnable_message_aird;
+
+ @TranslatableMessage
+ public static String AskSessionOpeningRunnable_message_confirm;
+
@TranslatableMessage
public static String ChangeViewpointSelectionCommand_activationError;
@@ -464,6 +472,9 @@ public final class Messages {
public static String GenericModelCreationPage_fileExtensionError;
@TranslatableMessage
+ public static String InvalidModelingProjectMarkerUpdaterJob_updateMarkers;
+
+ @TranslatableMessage
public static String LoadEMFResourceRunnableWithProgress_loadResourceTask;
@TranslatableMessage
@@ -1024,9 +1035,6 @@ public final class Messages {
@TranslatableMessage
public static String ViewpointsSelectionWizardPage_title;
- @TranslatableMessage
- public static String InvalidModelingProjectMarkerUpdaterJob_updateMarkers;
-
// CHECKSTYLE:ON
private Messages() {
diff --git a/plugins/org.eclipse.sirius/plugin.properties b/plugins/org.eclipse.sirius/plugin.properties
index daaa9573e0..ba8bb04fa4 100644
--- a/plugins/org.eclipse.sirius/plugin.properties
+++ b/plugins/org.eclipse.sirius/plugin.properties
@@ -214,6 +214,8 @@ RemoveElementTask_notAViewErrorMsg = The element is not a view ! Do not delete !
RemoveSemanticResourceCommand_label = Remove model
RenameRepresentationCommand_label = Rename representation
RepresentationDescriptionMetaModelsConstraint_noMetaModel = There is no associated meta-model.
+ResourceVersionMismatchDiagnostic_airdMessage = The Sirius resource ({0}) can not be loaded because it comes from a more recent Sirius release.\nRepresentation version is: {1}\nLast Sirius migration version is: {2}
+ResourceVersionMismatchDiagnostic_vsmMessage = The viewpoint specification model ({0}) can not be loaded because it comes from a more recent Sirius release.\nVSM version is: {1}\nLast Sirius migration version is: {2}
RestoreModelElementStateCommand_label = restor model elements
RuntimeLoggerInterpreterImpl_evaluationConditionErrorMsg = Evaluation condition error
SaveSessionJob_sessionSavingMsg = Session saving
@@ -340,7 +342,7 @@ ViewpointProtocolParser_noViewpointErrorMsg = No viewpoint is corresponding to {
ViewpointProtocolParser_invalidURIErrorMsg = URI {0} is not valid.
ViewpointProtocolParser_unamed = unnamed
ViewpointRegistryImpl_FileLoadingErrorMsg = The viewpoint registry was not able to load this file {0}
-ViewpointRegistryImpl_cantDeployVSMErrorMsg = Can't deploy VSM.
+ViewpointRegistryImpl_cantDeployVSMErrorMsg = Can't deploy VSM in the viewpoint registry.
ViewpointRegistryImpl_cantLoadVSMErrorMsg = The viewpoint specification model : {0} can''t be loaded, it may need to be migrated.
ViewpointRegistryImpl_unableToUnloadFileErrorMsg = The viewpoint registry was not able to unload this file {0}
XMIModelFileHandler_parsingStopedMsg = All needed informations have been reached. Stop the parsing.
diff --git a/plugins/org.eclipse.sirius/src-gen/org/eclipse/sirius/viewpoint/description/util/DescriptionResourceImpl.java b/plugins/org.eclipse.sirius/src-gen/org/eclipse/sirius/viewpoint/description/util/DescriptionResourceImpl.java
index df50545a92..0bf6b61e8d 100644
--- a/plugins/org.eclipse.sirius/src-gen/org/eclipse/sirius/viewpoint/description/util/DescriptionResourceImpl.java
+++ b/plugins/org.eclipse.sirius/src-gen/org/eclipse/sirius/viewpoint/description/util/DescriptionResourceImpl.java
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2007, 2015 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2007, 2016 THALES GLOBAL SERVICES and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -22,6 +22,7 @@ import org.eclipse.emf.ecore.xmi.XMLLoad;
import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl;
+import org.eclipse.sirius.business.api.migration.ResourceVersionMismatchDiagnostic;
import org.eclipse.sirius.business.internal.migration.AbstractSiriusMigrationService;
import org.eclipse.sirius.business.internal.migration.description.VSMExtendedMetaData;
import org.eclipse.sirius.business.internal.migration.description.VSMMigrationService;
@@ -93,17 +94,33 @@ public class DescriptionResourceImpl extends XMIResourceImpl {
@Override
public void load(Map<?, ?> options) throws IOException {
- useURIFragmentAsId = Boolean.TRUE.equals(options.get(DescriptionResourceImpl.OPTION_USE_URI_FRAGMENT_AS_ID)) && getURI().isPlatformPlugin();
- handleMigrationOptions();
- super.load(options);
+ if (!isLoaded) {
+ useURIFragmentAsId = Boolean.TRUE.equals(options.get(DescriptionResourceImpl.OPTION_USE_URI_FRAGMENT_AS_ID)) && getURI().isPlatformPlugin();
+ Diagnostic migrationMismatchDiagnostic = handleMigrationOptions();
+ super.load(options);
+ if (migrationMismatchDiagnostic != null) {
+ getErrors().add(migrationMismatchDiagnostic);
+ }
+ }
}
- private void handleMigrationOptions() {
+ /**
+ * Handle migration options and return an error diagnostic in case of
+ * migration version mismatch
+ */
+ private Diagnostic handleMigrationOptions() {
+ Diagnostic migrationMismatchDiagnostic = null;
VSMVersionSAXParser parser = new VSMVersionSAXParser(uri);
String loadedVersion = parser.getVersion(new NullProgressMonitor());
boolean migrationIsNeeded = true;
if (loadedVersion != null) {
- migrationIsNeeded = VSMMigrationService.getInstance().isMigrationNeeded(Version.parseVersion(loadedVersion));
+ Version parsedLoadedVersion = Version.parseVersion(loadedVersion);
+ Version lastMigrationVersion = VSMMigrationService.getInstance().getLastMigrationVersion();
+ boolean attemptToLoadMoreRecentVSM = lastMigrationVersion.compareTo(parsedLoadedVersion) < 0;
+ if (attemptToLoadMoreRecentVSM) {
+ migrationMismatchDiagnostic = new ResourceVersionMismatchDiagnostic(uri, parsedLoadedVersion, lastMigrationVersion);
+ }
+ migrationIsNeeded = VSMMigrationService.getInstance().isMigrationNeeded(parsedLoadedVersion);
}
Object versionOption = this.getDefaultLoadOptions().get(AbstractSiriusMigrationService.OPTION_RESOURCE_MIGRATION_LOADEDVERSION);
@@ -119,6 +136,7 @@ public class DescriptionResourceImpl extends XMIResourceImpl {
else if (migrationIsNeeded && (versionOption == null || !versionOption.equals(loadedVersion))) {
DescriptionResourceImpl.addMigrationOptions(loadedVersion, this.getDefaultLoadOptions(), this.getDefaultSaveOptions());
}
+ return migrationMismatchDiagnostic;
}
private void removeMigrationMechanism() {
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 1f233d03c9..efac59487b 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
@@ -31,11 +31,13 @@ import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.EList;
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.Resource.Diagnostic;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.resource.impl.URIMappingRegistryImpl;
@@ -102,16 +104,22 @@ public class ViewpointRegistryImpl extends ViewpointRegistry {
@Override
public boolean isValid(final EObject descRoot) {
- boolean result;
- if (descRoot instanceof Group) {
- result = true;
- } else {
- result = false;
- if (descRoot == null) {
- // Nothing, already been log
+ boolean result = false;
+ EList<Diagnostic> errors = descRoot.eResource().getErrors();
+ if (errors.isEmpty()) {
+ if (descRoot instanceof Group) {
+ result = true;
} else {
- SiriusPlugin.getDefault().warning(MessageFormat.format(Messages.ViewpointRegistryImpl_cantLoadVSMErrorMsg, descRoot.eResource().getURI()),
- new RuntimeException(Messages.ViewpointRegistryImpl_cantDeployVSMErrorMsg));
+ if (descRoot == null) {
+ // Nothing, already been log
+ } else {
+ SiriusPlugin.getDefault().warning(MessageFormat.format(Messages.ViewpointRegistryImpl_cantLoadVSMErrorMsg, descRoot.eResource().getURI()),
+ new RuntimeException(Messages.ViewpointRegistryImpl_cantDeployVSMErrorMsg));
+ }
+ }
+ } else {
+ for (Diagnostic diagnostic : errors) {
+ SiriusPlugin.getDefault().warning(diagnostic.getMessage(), new RuntimeException(Messages.ViewpointRegistryImpl_cantDeployVSMErrorMsg));
}
}
return result;
@@ -539,15 +547,16 @@ public class ViewpointRegistryImpl extends ViewpointRegistry {
final IFile file = fileIt.next();
EObject descRoot = load(file, resourceSet);
+ if (descRoot != null) {
+ Option<ViewpointFileCollector> collector = getCollectorFromIFile(file);
- Option<ViewpointFileCollector> collector = getCollectorFromIFile(file);
-
- if (collector.some() && collector.get().isValid(descRoot)) {
- viewpoints.addAll(collector.get().collect(descRoot));
- mapToSiriusProtocol(collector.get().collect(descRoot));
- resourcesToResolve.add(descRoot.eResource());
- } else {
- unloadAndRemove(file);
+ if (collector.some() && collector.get().isValid(descRoot)) {
+ viewpoints.addAll(collector.get().collect(descRoot));
+ mapToSiriusProtocol(collector.get().collect(descRoot));
+ resourcesToResolve.add(descRoot.eResource());
+ } else {
+ unloadAndRemove(file);
+ }
}
}
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/migration/AirdResourceVersionMismatchException.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/migration/AirdResourceVersionMismatchException.java
new file mode 100644
index 0000000000..9733757964
--- /dev/null
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/migration/AirdResourceVersionMismatchException.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.sirius.business.api.migration;
+
+import java.util.Collection;
+
+import com.google.common.collect.Lists;
+
+/**
+ * A {@link RuntimeException} used when the VSM version is more recent than the
+ * last Sirius migration version.
+ *
+ * @author <a href="mailto:laurent.fasani@obeo.fr">Laurent Fasani</a>
+ */
+public class AirdResourceVersionMismatchException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ private final Collection<ResourceVersionMismatchDiagnostic> diagnostics = Lists.newArrayList();
+
+ /**
+ * Default constructor.
+ *
+ * @param diagnostics
+ * the diagnotic behind this exception
+ */
+ public AirdResourceVersionMismatchException(Collection<ResourceVersionMismatchDiagnostic> diagnostics) {
+ super(computeMessage(diagnostics));
+ this.diagnostics.addAll(diagnostics);
+ }
+
+ public Collection<ResourceVersionMismatchDiagnostic> getDiagnostics() {
+ return diagnostics;
+ }
+
+ private static String computeMessage(Collection<ResourceVersionMismatchDiagnostic> diagnostics) {
+ StringBuilder sb = new StringBuilder();
+ for (ResourceVersionMismatchDiagnostic resourceVersionMismatchDiagnostic : diagnostics) {
+ sb.append("\n" + resourceVersionMismatchDiagnostic.getMessage()); //$NON-NLS-1$
+ }
+
+ return sb.toString();
+ }
+}
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/migration/DescriptionResourceVersionMismatchException.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/migration/DescriptionResourceVersionMismatchException.java
new file mode 100644
index 0000000000..e2e27e8373
--- /dev/null
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/migration/DescriptionResourceVersionMismatchException.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.sirius.business.api.migration;
+
+import java.util.Collection;
+
+import com.google.common.collect.Lists;
+
+/**
+ * A {@link RuntimeException} used when the VSM version is more recent than the
+ * last Sirius migration version.
+ *
+ * @author <a href="mailto:laurent.fasani@obeo.fr">Laurent Fasani</a>
+ */
+public class DescriptionResourceVersionMismatchException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ private final Collection<ResourceVersionMismatchDiagnostic> diagnostics = Lists.newArrayList();
+
+ /**
+ * Default constructor.
+ *
+ * @param diagnostics
+ * the diagnotic behind this exception
+ */
+ public DescriptionResourceVersionMismatchException(Collection<ResourceVersionMismatchDiagnostic> diagnostics) {
+ super(computeMessage(diagnostics));
+ this.diagnostics.addAll(diagnostics);
+ }
+
+ public Collection<ResourceVersionMismatchDiagnostic> getDiagnostics() {
+ return diagnostics;
+ }
+
+ private static String computeMessage(Collection<ResourceVersionMismatchDiagnostic> diagnostics) {
+ StringBuilder sb = new StringBuilder();
+ for (ResourceVersionMismatchDiagnostic resourceVersionMismatchDiagnostic : diagnostics) {
+ sb.append(resourceVersionMismatchDiagnostic.getMessage());
+ }
+
+ return sb.toString();
+ }
+}
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/migration/ResourceVersionMismatchDiagnostic.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/migration/ResourceVersionMismatchDiagnostic.java
new file mode 100644
index 0000000000..c307b054c4
--- /dev/null
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/migration/ResourceVersionMismatchDiagnostic.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.sirius.business.api.migration;
+
+import java.text.MessageFormat;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource.Diagnostic;
+import org.eclipse.sirius.business.api.helper.SiriusUtil;
+import org.eclipse.sirius.viewpoint.Messages;
+import org.osgi.framework.Version;
+
+/**
+ * A {@link Diagnostic} to help Sirius to manage the case when the model being
+ * loaded is newer than the Sirius release.
+ *
+ * @author <a href="mailto:laurent.fasani@obeo.fr">Laurent Fasani</a>
+ */
+public class ResourceVersionMismatchDiagnostic implements Diagnostic {
+
+ private final URI resourceToLoadURI;
+
+ private Version lastMigrationVersion;
+
+ private Version parsedLoadedVersion;
+
+ /**
+ * Default constructor.
+ *
+ * @param resourceToLoadURI
+ * to {@link URI} of the resource to load
+ * @param parsedLoadedVersion
+ * the parsed loaded version
+ * @param lastMigrationVersion
+ * the last migration version
+ */
+ public ResourceVersionMismatchDiagnostic(URI resourceToLoadURI, Version parsedLoadedVersion, Version lastMigrationVersion) {
+ this.resourceToLoadURI = resourceToLoadURI;
+ this.lastMigrationVersion = lastMigrationVersion;
+ this.parsedLoadedVersion = parsedLoadedVersion;
+
+ }
+
+ public Version getLastMigrationVersion() {
+ return lastMigrationVersion;
+ }
+
+ public Version getParsedLoadedVersion() {
+ return parsedLoadedVersion;
+ }
+
+ public URI getResourceToLoadURI() {
+ return resourceToLoadURI;
+ }
+
+ @Override
+ public String getLocation() {
+ return null;
+ }
+
+ @Override
+ public int getLine() {
+ return 0;
+ }
+
+ @Override
+ public int getColumn() {
+ return 0;
+ }
+
+ @Override
+ public String getMessage() {
+ String message = null;
+ String fileExtension = resourceToLoadURI.fileExtension();
+ if (SiriusUtil.SESSION_RESOURCE_EXTENSION.equals(fileExtension)) {
+ message = MessageFormat.format(Messages.ResourceVersionMismatchDiagnostic_airdMessage, resourceToLoadURI, parsedLoadedVersion, lastMigrationVersion);
+ } else if (SiriusUtil.DESCRIPTION_MODEL_EXTENSION.equals(fileExtension)) {
+ message = MessageFormat.format(Messages.ResourceVersionMismatchDiagnostic_vsmMessage, resourceToLoadURI, parsedLoadedVersion, lastMigrationVersion);
+ }
+ return message;
+ }
+}
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 c14080abfa..f2efc24c5b 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
@@ -158,7 +158,7 @@ public class ModelingProject implements IProjectNature, IModelingElement {
final Option<URI> optionalUri = getMainRepresentationsFileURI(new NullProgressMonitor());
if (optionalUri.some()) {
for (Session session : SessionManager.INSTANCE.getSessions()) {
- if (optionalUri.get().equals(session.getSessionResource().getURI())) {
+ if (session.getSessionResource() != null && optionalUri.get().equals(session.getSessionResource().getURI())) {
return session;
}
}
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/SessionManager.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/SessionManager.java
index 9c1e683733..62ef05564a 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/SessionManager.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/SessionManager.java
@@ -17,6 +17,7 @@ import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.sirius.business.internal.session.SessionManagerImpl;
+import org.eclipse.sirius.tools.api.command.ui.UICallBack;
/**
* The {@link SessionManager} is responsible for a set of sessions.
@@ -142,4 +143,20 @@ public interface SessionManager {
*/
Session getExistingSession(URI sessionResourceURI);
+ /**
+ * Try to open a session. If there is a version mismatch, the user may be
+ * asked if he wants to open the session anyway.
+ *
+ * @param sessionResourceURI
+ * a session Resource {@link URI}
+ * @param monitor
+ * a {@link IProgressMonitor} to show progression of Session
+ * getting, especially if there is a resource loading
+ * @param uiCallback
+ * used to let the user choose if he wants to open the session
+ * anyway in case of version mismatch
+ * @return the opened session
+ */
+ Session openSession(URI sessionResourceURI, IProgressMonitor monitor, UICallBack uiCallback);
+
}
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/migration/resource/MigrationUtil.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/migration/resource/MigrationUtil.java
index 986633f076..291108e537 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/migration/resource/MigrationUtil.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/migration/resource/MigrationUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007-2015 THALES GLOBAL SERVICES.
+ * Copyright (c) 2007, 2016 THALES GLOBAL SERVICES.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -47,6 +47,16 @@ import org.eclipse.sirius.viewpoint.SiriusPlugin;
*/
public final class MigrationUtil {
+ /**
+ * Temporary variable to indicate that we want ignore version mismatch at
+ * session opening, waiting for Bug 456326.
+ *
+ * @provisional
+ */
+ // CHECKSTYLE:OFF
+ public static boolean ignoreVersionMismatch;
+ // CHECKSTYLE:ON
+
/** The modeler description file extension for designer v3. */
public static final String MODELER_DESCRIPTION_FILE_EXTENSION_V3 = "air"; //$NON-NLS-1$
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/resource/AirDResourceImpl.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/resource/AirDResourceImpl.java
index 575754e62c..b68ebeb08c 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/resource/AirDResourceImpl.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/resource/AirDResourceImpl.java
@@ -20,6 +20,7 @@ import org.eclipse.emf.ecore.xmi.XMLHelper;
import org.eclipse.emf.ecore.xmi.XMLLoad;
import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
+import org.eclipse.sirius.business.api.migration.ResourceVersionMismatchDiagnostic;
import org.eclipse.sirius.business.api.session.resource.AirdResource;
import org.eclipse.sirius.business.api.session.resource.DResource;
import org.eclipse.sirius.business.internal.migration.AbstractSiriusMigrationService;
@@ -27,6 +28,7 @@ import org.eclipse.sirius.business.internal.migration.RepresentationsFileExtende
import org.eclipse.sirius.business.internal.migration.RepresentationsFileMigrationService;
import org.eclipse.sirius.business.internal.migration.RepresentationsFileResourceHandler;
import org.eclipse.sirius.business.internal.migration.RepresentationsFileVersionSAXParser;
+import org.eclipse.sirius.business.internal.migration.resource.MigrationUtil;
import org.eclipse.sirius.business.internal.resource.parser.RepresentationsFileXMIHelper;
import org.eclipse.sirius.common.tools.DslCommonPlugin;
import org.eclipse.sirius.ext.base.Option;
@@ -118,26 +120,43 @@ public class AirDResourceImpl extends XMIResourceImpl implements DResource, Aird
@Override
public void load(Map<?, ?> options) throws IOException {
- DslCommonPlugin.PROFILER.startWork(SiriusTasksKey.LOAD_AIRD_KEY);
- AirDResourceImpl.incrementLoadInProgress();
- try {
- handleMigrationOptions();
- super.load(options);
- } finally {
- AirDResourceImpl.decrementLoadInProgress();
+ if (!isLoaded) {
+ DslCommonPlugin.PROFILER.startWork(SiriusTasksKey.LOAD_AIRD_KEY);
+ AirDResourceImpl.incrementLoadInProgress();
+ try {
+ Diagnostic migrationMismatchDiagnostic = handleMigrationOptions();
+ super.load(options);
+ if (migrationMismatchDiagnostic != null) {
+ getErrors().add(migrationMismatchDiagnostic);
+ }
+ } finally {
+ AirDResourceImpl.decrementLoadInProgress();
+ }
+ DslCommonPlugin.PROFILER.stopWork(SiriusTasksKey.LOAD_AIRD_KEY);
+ // AirDResourceMigration migration = new
+ // AirDResourceMigration(this);
+ // // Notify user only if there is no more load in progress.
+ // migration.migrate(!AirDResourceImpl.hasLoadInProgress());
}
- DslCommonPlugin.PROFILER.stopWork(SiriusTasksKey.LOAD_AIRD_KEY);
- // AirDResourceMigration migration = new AirDResourceMigration(this);
- // // Notify user only if there is no more load in progress.
- // migration.migrate(!AirDResourceImpl.hasLoadInProgress());
}
- private void handleMigrationOptions() {
+ /**
+ * Handle migration options and return an error diagnostic in case of
+ * migration version mismatch
+ */
+ private Diagnostic handleMigrationOptions() {
+ Diagnostic migrationMismatchDiagnostic = null;
RepresentationsFileVersionSAXParser parser = new RepresentationsFileVersionSAXParser(uri);
boolean migrationIsNeeded = true;
String loadedVersion = parser.getVersion(new NullProgressMonitor());
if (loadedVersion != null) {
- migrationIsNeeded = RepresentationsFileMigrationService.getInstance().isMigrationNeeded(Version.parseVersion(loadedVersion));
+ Version parsedLoadedVersion = Version.parseVersion(loadedVersion);
+ Version lastMigrationVersion = RepresentationsFileMigrationService.getInstance().getLastMigrationVersion();
+ boolean attemptToLoadMoreRecentVSM = lastMigrationVersion.compareTo(parsedLoadedVersion) < 0;
+ if (attemptToLoadMoreRecentVSM && !MigrationUtil.ignoreVersionMismatch) {
+ migrationMismatchDiagnostic = new ResourceVersionMismatchDiagnostic(uri, parsedLoadedVersion, lastMigrationVersion);
+ }
+ migrationIsNeeded = RepresentationsFileMigrationService.getInstance().isMigrationNeeded(parsedLoadedVersion);
}
Object versionOption = this.getDefaultLoadOptions().get(AbstractSiriusMigrationService.OPTION_RESOURCE_MIGRATION_LOADEDVERSION);
@@ -153,7 +172,7 @@ public class AirDResourceImpl extends XMIResourceImpl implements DResource, Aird
else if (migrationIsNeeded && (versionOption == null || !versionOption.equals(loadedVersion))) {
addMigrationOptions(loadedVersion, this.getDefaultLoadOptions(), this.getDefaultSaveOptions());
}
-
+ return migrationMismatchDiagnostic;
}
private void removeMigrationMechanism() {
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/SessionManagerImpl.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/SessionManagerImpl.java
index abe7c9cd65..e2ad540018 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/SessionManagerImpl.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/SessionManagerImpl.java
@@ -25,21 +25,26 @@ import org.eclipse.core.runtime.Assert;
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.core.runtime.Status;
+import org.eclipse.core.runtime.SubMonitor;
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;
import org.eclipse.sirius.business.api.logger.MarkerRuntimeLogger;
+import org.eclipse.sirius.business.api.migration.AirdResourceVersionMismatchException;
import org.eclipse.sirius.business.api.query.URIQuery;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.business.api.session.SessionListener;
import org.eclipse.sirius.business.api.session.SessionManager;
import org.eclipse.sirius.business.api.session.SessionManagerListener;
import org.eclipse.sirius.business.api.session.factory.SessionFactory;
+import org.eclipse.sirius.business.internal.migration.resource.MigrationUtil;
import org.eclipse.sirius.common.tools.api.util.EclipseUtil;
import org.eclipse.sirius.common.tools.api.util.MarkerUtil;
import org.eclipse.sirius.ext.base.Option;
+import org.eclipse.sirius.tools.api.command.ui.UICallBack;
import org.eclipse.sirius.viewpoint.DAnalysisSessionEObject;
import org.eclipse.sirius.viewpoint.Messages;
import org.eclipse.sirius.viewpoint.SiriusPlugin;
@@ -374,4 +379,32 @@ public class SessionManagerImpl extends SessionManagerEObjectImpl implements Ses
}
return extensionPointListeners;
}
+
+ @Override
+ public Session openSession(URI sessionResourceURI, IProgressMonitor monitor, UICallBack uiCallback) {
+ SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
+
+ Session session = this.getSession(sessionResourceURI, subMonitor.newChild(30));
+ if (session != null && !session.isOpen()) {
+ try {
+ session.open(subMonitor.newChild(70));
+ } catch (AirdResourceVersionMismatchException e) {
+ session = null;
+ if (uiCallback != null && uiCallback.askSessionReopeningWithResourceVersionMismatch(e)) {
+ try {
+ MigrationUtil.ignoreVersionMismatch = true;
+ session = this.getSession(sessionResourceURI, new NullProgressMonitor());
+ session.open(new NullProgressMonitor());
+ } finally {
+ MigrationUtil.ignoreVersionMismatch = false;
+ }
+ } else {
+ throw e;
+ }
+ }
+ }
+ subMonitor.done();
+
+ return session;
+ }
}
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java
index 89d4a648fa..9b049c1534 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java
@@ -32,6 +32,7 @@ import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.Resource.Diagnostic;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.transaction.RunnableWithResult;
import org.eclipse.emf.transaction.Transaction;
@@ -42,6 +43,9 @@ import org.eclipse.emf.transaction.util.ValidateEditSupport;
import org.eclipse.emf.workspace.IWorkspaceCommandStack;
import org.eclipse.emf.workspace.ResourceUndoContext;
import org.eclipse.sirius.business.api.componentization.ViewpointRegistry;
+import org.eclipse.sirius.business.api.migration.AirdResourceVersionMismatchException;
+import org.eclipse.sirius.business.api.migration.DescriptionResourceVersionMismatchException;
+import org.eclipse.sirius.business.api.migration.ResourceVersionMismatchDiagnostic;
import org.eclipse.sirius.business.api.query.DAnalysisQuery;
import org.eclipse.sirius.business.api.query.FileQuery;
import org.eclipse.sirius.business.api.query.RepresentationDescriptionQuery;
@@ -1176,6 +1180,8 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements
DViewOperations.on(this).updateSelectedViewpointsData(new SubProgressMonitor(monitor, 10));
initLocalTriggers();
+ checkResourceErrors();
+
super.setOpen(true);
DslCommonPlugin.PROFILER.stopWork(SiriusTasksKey.OPEN_SESSION_KEY);
notifyListeners(SessionListener.OPENED);
@@ -1191,6 +1197,40 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements
}
}
+ /**
+ * Throw an {@link RuntimeException} if one of the resource of the selected
+ * viewpoints or session resources contain an error.
+ */
+ private void checkResourceErrors() {
+ Collection<ResourceVersionMismatchDiagnostic> diagnostics = Lists.newArrayList();
+
+ // Prevent loading a session which VSM resource contains errors
+ Collection<Viewpoint> activatedViewpoints = getSelectedViewpoints(true);
+ for (Viewpoint viewpoint : activatedViewpoints) {
+ for (Diagnostic diagnostic : viewpoint.eResource().getErrors()) {
+ if (diagnostic instanceof ResourceVersionMismatchDiagnostic) {
+ diagnostics.add((ResourceVersionMismatchDiagnostic) diagnostic);
+ }
+ }
+ }
+ if (!diagnostics.isEmpty()) {
+ throw new DescriptionResourceVersionMismatchException(diagnostics);
+ }
+
+ // Prevent loading a session which Aird resource contains errors
+ Iterable<Resource> representationResources = Iterables.concat(getReferencedSessionResources(), Sets.newHashSet(getSessionResource()));
+ for (Resource resource : representationResources) {
+ for (Diagnostic diagnostic : resource.getErrors()) {
+ if (diagnostic instanceof ResourceVersionMismatchDiagnostic) {
+ diagnostics.add((ResourceVersionMismatchDiagnostic) diagnostic);
+ }
+ }
+ }
+ if (!diagnostics.isEmpty()) {
+ throw new AirdResourceVersionMismatchException(diagnostics);
+ }
+ }
+
@Override
public void close(IProgressMonitor monitor) {
if (!isOpen()) {
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/NoUICallback.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/NoUICallback.java
index 4de5bfe5e7..fe18e7f99c 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/NoUICallback.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/NoUICallback.java
@@ -19,6 +19,7 @@ import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.sirius.business.api.migration.AirdResourceVersionMismatchException;
import org.eclipse.sirius.business.api.resource.LoadEMFResource;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.common.tools.api.util.TreeItemWrapper;
@@ -178,4 +179,9 @@ public class NoUICallback implements UICallBack {
public List<String> askForTypedVariable(List<TypedVariable> typedVariableList, List<String> defaultValues) {
return Collections.emptyList();
}
+
+ @Override
+ public boolean askSessionReopeningWithResourceVersionMismatch(AirdResourceVersionMismatchException e) {
+ return false;
+ }
}
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/UICallBack.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/UICallBack.java
index ae22c763ec..47455afc96 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/UICallBack.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/UICallBack.java
@@ -18,6 +18,7 @@ import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.sirius.business.api.migration.AirdResourceVersionMismatchException;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.common.tools.api.util.TreeItemWrapper;
import org.eclipse.sirius.viewpoint.DRepresentation;
@@ -232,4 +233,17 @@ public interface UICallBack {
* pressed "cancel".)
*/
List<String> askForTypedVariable(List<TypedVariable> typedVariableList, List<String> defaultValues) throws InterruptedException;;
+
+ /**
+ * Ask to end-user if he wants to open the session ignoring the resource
+ * version mismatch or not.
+ *
+ * @param e
+ * the {@link AirdResourceVersionMismatchException} holding
+ * mismatch informations
+ *
+ * @return true to reopen session false otherwise
+ * @since 4.0
+ */
+ boolean askSessionReopeningWithResourceVersionMismatch(AirdResourceVersionMismatchException e);
}
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/viewpoint/Messages.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/viewpoint/Messages.java
index 657a59fff8..1308d23c60 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/viewpoint/Messages.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/viewpoint/Messages.java
@@ -456,6 +456,12 @@ public final class Messages {
public static String RestoreModelElementStateCommand_label;
@TranslatableMessage
+ public static String ResourceVersionMismatchDiagnostic_airdMessage;
+
+ @TranslatableMessage
+ public static String ResourceVersionMismatchDiagnostic_vsmMessage;
+
+ @TranslatableMessage
public static String RuntimeLoggerInterpreterImpl_evaluationConditionErrorMsg;
@TranslatableMessage

Back to the top