Skip to content

Commit

Permalink
[333] Add migration participant to remove useless StringValueStyle
Browse files Browse the repository at this point in the history
The representations created before the previous commit, that fixes the
unexpected creation of StringValueStyle, can contain some kind of "empty
StringValueStyle".
The goal of this commit is to remove them.

This commit also adds tests to check migration effect.

Bug: #333
  • Loading branch information
lredor committed Jun 26, 2024
1 parent 397c22d commit 049f646
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 16 deletions.
4 changes: 3 additions & 1 deletion plugins/org.eclipse.sirius.diagram.elk/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.emf.common.ui,
org.eclipse.elk.alg.layered;bundle-version="0.9.0",
org.eclipse.sirius.ext.base;bundle-version="7.4.3",
org.eclipse.elk.alg.rectpacking;bundle-version="0.9.0"
org.eclipse.elk.alg.rectpacking;bundle-version="0.9.0",
org.eclipse.sirius.ecore.extender;bundle-version="7.4.3"
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Import-Package: com.google.common.collect;version="27.0.0",
org.eclipse.sirius.common.tools.api.util;version="3.1.0"
Bundle-Vendor: %providerName
Automatic-Module-Name: org.eclipse.sirius.diagram.elk
Export-Package: org.eclipse.sirius.diagram.elk,
org.eclipse.sirius.diagram.elk.migration,
org.eclipse.sirius.diagram.elk.migration.description
4 changes: 4 additions & 0 deletions plugins/org.eclipse.sirius.diagram.elk/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,9 @@
class="org.eclipse.sirius.diagram.elk.migration.description.ELK090MigrationParticipant"
kind="VSM">
</participant>
<participant
class="org.eclipse.sirius.diagram.elk.migration.EmptyJunctionPointsStringValueStyleMigrationParticipant"
kind="RepresentationsFile">
</participant>
</extension>
</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.diagram.elk.migration;

import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.StringValueStyle;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.sirius.business.api.migration.AbstractRepresentationsFileMigrationParticipant;
import org.eclipse.sirius.business.api.query.DViewQuery;
import org.eclipse.sirius.diagram.DDiagram;
import org.eclipse.sirius.diagram.elk.GmfLayoutCommand;
import org.eclipse.sirius.diagram.ui.business.api.query.DDiagramGraphicalQuery;
import org.eclipse.sirius.viewpoint.DAnalysis;
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
import org.eclipse.sirius.viewpoint.DView;
import org.osgi.framework.Version;

/**
*
* This migration participant fixes the GMF edges that contain an empty "junctionPoints" StringValueStyle. These empty
* "junctionPoints" StringValueStyle were created due to a bug in ELK./Sirius integration. This migration participant
* simply removes the empty "junctionPoints" StringValueStyle.
*
* @author Laurent Redor
*
*/
public class EmptyJunctionPointsStringValueStyleMigrationParticipant extends AbstractRepresentationsFileMigrationParticipant {

/**
* Migration version.
*/
public static final Version MIGRATION_VERSION = new Version("15.4.3.202406261640"); //$NON-NLS-1$

@Override
public Version getMigrationVersion() {
return MIGRATION_VERSION;
}

/**
* Update the styles of this <code>edge</code> if it contains empty "junctionPoints" StringValueStyle. In this case,
* this style is removed.
*
* @param edge
* the GMF edge
*/
private void updateEdge(View edge) {
StringValueStyle stringValueStyle = (StringValueStyle) edge.getStyle(NotationPackage.Literals.STRING_VALUE_STYLE);
if (stringValueStyle != null && GmfLayoutCommand.JUNCTION_POINTS_STYLE_NAME.equals(stringValueStyle.getName()) && "()".equals(stringValueStyle.getStringValue())) { //$NON-NLS-1$
edge.getStyles().remove(stringValueStyle);
}
}

/**
* Update the GMF diagram to migrate all invalid edges.
*
* @param diagram
* the GMF diagram
*/
private void migrateDiagram(Diagram diagram) {
List<Edge> edges = diagram.getEdges();
edges.stream().forEach(edge -> updateEdge(edge));
}

/**
* This method returns the associated GMF diagram of a Sirius diagram.
*
* @param dDiagram
* the Sirius diagram
* @return the associated GMF diagram if present
*/
private Optional<Diagram> getGMFDiagram(DDiagram dDiagram) {
DDiagramGraphicalQuery query = new DDiagramGraphicalQuery(dDiagram);
return Optional.ofNullable(query.getAssociatedGMFDiagram().get());
}

/**
* This method returns all representations descriptors of a view.
*
* @param dView
* the Sirius viewpoint.
* @return java stream of all representation descriptors of the <code>dView</code>.
*/
private Stream<DRepresentationDescriptor> getRepresentationsDescriptors(DView dView) {
return new DViewQuery(dView).getLoadedRepresentationsDescriptors().stream();
}

/**
* This method is overridden to fix file with inconsistent GMF edges, ie having an empty "junctionPoints"
* StringValueStyle.
*/
@Override
protected void postLoad(DAnalysis dAnalysis, Version loadedVersion) {
if (loadedVersion.compareTo(MIGRATION_VERSION) < 0) { // loadedVersion < MIGRATION_VERSION
// for each diagrams of each viewpoints
dAnalysis.getOwnedViews().stream() //
.flatMap(this::getRepresentationsDescriptors) //
.map(descriptor -> descriptor.getRepresentation()) //
.filter(representation -> representation instanceof DDiagram) //
.map(representation -> (DDiagram) representation) //
.map(this::getGMFDiagram) //
.flatMap(Optional::stream) //
.forEach(this::migrateDiagram);
}
}
}
25 changes: 14 additions & 11 deletions plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ <h3 id="SpecifierVisibleChanges">Specifier-Visible Changes</h3>
</li>
</ul>
<h3 id="DeveloperVisibleChanges">Developer-Visible Changes</h3>
<h4 id="Migrations">Migrations</h4>
<ul>
<li><span class="label label-success">Added</span> A migration participant, EmptyJunctionPointsStringValueStyleMigrationParticipant, has been added to fix the GMF edges that contain an empty &#8220;junctionPoints&#8221; StringValueStyle. These empty &#8220;junctionPoints&#8221; StringValueStyle were created due to a bug in ELK./Sirius integration. This migration participant simply removes the empty &#8220;junctionPoints&#8221; StringValueStyle. As reminder, this migration participant has been introduced in Sirius 7.4.3. The corresponding version, stored in attribute version of viewpoint:DAnalysis of the aird file, is
<em>15.4.3.202406261640</em>.
</li>
</ul>
<h2 id="sirius7.4.2">Changes in Sirius Desktop 7.4.2</h2>
<h3 id="UserVisibleChanges2">User-Visible Changes</h3>
<ul>
Expand All @@ -227,10 +233,7 @@ <h3 id="UserVisibleChanges2">User-Visible Changes</h3>
</ul>
<h3 id="SpecifierVisibleChanges2">Specifier-Visible Changes</h3>
<h3 id="DeveloperVisibleChanges2">Developer-Visible Changes</h3>
<h4 id="Migrations">Migrations</h4>
<p>
<em>None</em>.
</p>
<h4 id="Migrations2">Migrations</h4>
<h2 id="sirius7.4.1">Changes in Sirius Desktop 7.4.1</h2>
<h3 id="UserVisibleChanges3">User-Visible Changes</h3>
<ul>
Expand All @@ -249,7 +252,7 @@ <h4 id="Changesinorg.eclipse.sirius.diagram.ui">Changes in
<code>Map&lt;String, RGB&gt; collectVsmAndDefaultColors(Session session)</code>.
</li>
</ul>
<h4 id="Migrations2">Migrations</h4>
<h4 id="Migrations3">Migrations</h4>
<ul>
<li><span class="label label-success">Added</span> The migration participant WorkspaceImageGMFBoundsMigrationParticipant has been updated to handle the missed case of the image style of nodes contained in a container (and not directly in diagram). As reminder, this migration participant has been introduced in Sirius 7.0.0. The corresponding version, stored in attribute version of viewpoint:DAnalysis of the aird file, is
<em>15.4.1.202403191723</em>.
Expand Down Expand Up @@ -428,7 +431,7 @@ <h4 id="Changesinorg.eclipse.sirius.diagram.ui2">Changes in
</ul>
</li>
</ul>
<h4 id="Migrations3">Migrations</h4>
<h4 id="Migrations4">Migrations</h4>
<ul>
<li><span class="label label-success">Added</span> A migration participant has been added to migrate ELK options used in VSM. Some have been renamed and some others have been removed. You should carefully read the information logged during this migration and the
<a href="https://eclipse.dev/elk/downloads/releasenotes/release-0.9.0.html">ELK release notes</a> to check if any manual adjustments need to be made. The corresponding version, stored in attribute version of description:Group of the odesign file, is
Expand Down Expand Up @@ -677,7 +680,7 @@ <h4 id="Changesinorg.eclipse.sirius.properties.core">Changes in
<code>org.eclipse.sirius.properties.core.api.SiriusInputDescriptor.getOriginalSelections()</code>.
</li>
</ul>
<h4 id="Migrations4">Migrations</h4>
<h4 id="Migrations5">Migrations</h4>
<ul>
<li><span class="label label-info">Modified</span>The migration participant introduced by
<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=576423">Bug 576423 -
Expand Down Expand Up @@ -1080,7 +1083,7 @@ <h4 id="Changesinorg.eclipse.sirius.tests.junit.support">Changes in
<code>org.eclipse.sirius.tests.support.api.EclipseTestsSupportHelper.copyDirectory(String, String)</code> have been added to ease to the copy of the test files from the test plugin to the junit workspace.
</li>
</ul>
<h4 id="Migrations5">Migrations</h4>
<h4 id="Migrations6">Migrations</h4>
<ul>
<li><span class="label label-success">Added</span> A migration participant has been added to repair size of GMF nodes with Workspace Image style description. A default size was set for this type of nodes, which resulted in graphical inconsistencies (see
<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=576423)">Bug 576423 -
Expand Down Expand Up @@ -1146,7 +1149,7 @@ <h4 id="Changesinorg.eclipse.sirius.diagram.ui7">Changes in
<code>org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDDiagramEditPart.refreshChildren()</code> has been overridden to redraw the edges figures according to the order of the GMF edges.
</li>
</ul>
<h4 id="Migrations6">Migrations</h4>
<h4 id="Migrations7">Migrations</h4>
<ul>
<li><span class="label label-success">Added</span> A migration participant has been added to set a changeId value for each DRepresentationDescriptor that did not have one. Some old models were missing the changeId attribute, which could lead to technical problems. The migration participant
<code>org.eclipse.sirius.diagram.ui.business.internal.migration.SetChangeIdMigrationParticipant</code> sets a random changeId if it didn&#8217;t already exist. The corresponding version, stored in attribute version of viewpoint:DAnalysis of the aird file, is
Expand All @@ -1158,7 +1161,7 @@ <h4 id="Migrations6">Migrations</h4>
</ul>
<h2 id="sirius6.5.1">Changes in Sirius 6.5.1</h2>
<h3 id="DeveloperVisibleChanges14">Developer-Visible Changes</h3>
<h4 id="Migrations7">Migrations</h4>
<h4 id="Migrations8">Migrations</h4>
<ul>
<li><span class="label label-info">Modified</span> The migration participant
<code>org.eclipse.sirius.diagram.ui.business.internal.migration.NoteShapeDefaultLabelAlignmentMigrationParticipant</code> has been updated to repair Notes with a potential wrong vertical label alignment. This problem can occur since Sirius 6.3.2 used in a collaborative environment, Obeo Designer Team Edition or Team For Capella for example. The corresponding version, stored in the attribute version of viewpoint:DAnalysis of the aird file, is
Expand Down Expand Up @@ -1298,7 +1301,7 @@ <h4 id="Changesinorg.eclipse.sirius.ext.gmf.runtime">Changes in
<code>org.eclipse.sirius.ext.gmf.runtime.editparts.GraphicalHelper.getAbsoluteBoundsWithoutLabelsIn100Percent(GraphicalEditPart)</code> has been added to get the rectangle bounds without taking labels into account. This is used, in particular, to compute the bendpoints of an edge when the source or the target of the edge is an edge.
</li>
</ul>
<h4 id="Migrations8">Migrations</h4>
<h4 id="Migrations9">Migrations</h4>
<ul>
<li><span class="label label-success">Added</span> A migration participant has been added to repair rectilinear edges containing only one bendpoint. Bracket edges are not relevant. The corresponding version, stored in attribute version of viewpoint:DAnalysis of the aird file, is
<em>14.5.0.202104070943</em>.
Expand Down
7 changes: 4 additions & 3 deletions plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ h3. Specifier-Visible Changes

h3. Developer-Visible Changes

h4. Migrations

* <span class="label label-success">Added</span> A migration participant, EmptyJunctionPointsStringValueStyleMigrationParticipant, has been added to fix the GMF edges that contain an empty "junctionPoints" StringValueStyle. These empty "junctionPoints" StringValueStyle were created due to a bug in ELK./Sirius integration. This migration participant simply removes the empty "junctionPoints" StringValueStyle. As reminder, this migration participant has been introduced in Sirius 7.4.3. The corresponding version, stored in attribute version of viewpoint:DAnalysis of the aird file, is _15.4.3.202406261640_.

h2(#sirius7.4.2). Changes in Sirius Desktop 7.4.2

h3. User-Visible Changes
Expand All @@ -26,9 +30,6 @@ h3. Developer-Visible Changes

h4. Migrations

_None_.


h2(#sirius7.4.1). Changes in Sirius Desktop 7.4.1

h3. User-Visible Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
Expand Down Expand Up @@ -62,12 +63,14 @@
import org.eclipse.gmf.runtime.draw2d.ui.internal.figures.AnimatableScrollPane;
import org.eclipse.gmf.runtime.notation.Bounds;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.FontStyle;
import org.eclipse.gmf.runtime.notation.LayoutConstraint;
import org.eclipse.gmf.runtime.notation.Location;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.Routing;
import org.eclipse.gmf.runtime.notation.StringValueStyle;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.sirius.diagram.DDiagram;
Expand All @@ -89,6 +92,8 @@
import org.eclipse.sirius.diagram.description.EnumLayoutOption;
import org.eclipse.sirius.diagram.description.EnumLayoutValue;
import org.eclipse.sirius.diagram.description.LayoutOptionTarget;
import org.eclipse.sirius.diagram.elk.GmfLayoutCommand;
import org.eclipse.sirius.diagram.elk.migration.EmptyJunctionPointsStringValueStyleMigrationParticipant;
import org.eclipse.sirius.diagram.tools.api.preferences.SiriusDiagramPreferencesKeys;
import org.eclipse.sirius.diagram.tools.internal.commands.PinElementsCommand;
import org.eclipse.sirius.diagram.ui.business.api.query.ViewQuery;
Expand Down Expand Up @@ -121,6 +126,7 @@
import org.eclipse.sirius.viewpoint.description.Group;
import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
import org.eclipse.ui.IEditorPart;
import org.osgi.framework.Version;

import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -1888,6 +1894,18 @@ private void testArrangeAllResultForEdgesRoutingStyle(String diagramName, String
checkRoutingStyle(edgeEditPartWithoutRightAngle, WRONG_ROUTING_AFTER_LAYOUT_MESSAGE, secondEdgeNameToCheck, afterLayoutExpectedEdgeRouting);
}

/**
* Test that the data were not migrated on the repository. It allows to check the effect of the migration of
* EmptyJunctionPointsStringValueStyleMigrationParticipant in other tests.
*/
public void testMigrationIsNeededOnData() {
Version migrationVersion = new EmptyJunctionPointsStringValueStyleMigrationParticipant().getMigrationVersion();

// Check that the migration of the session resource is needed.
Version loadedVersion = checkRepresentationFileMigrationStatus(URI.createPlatformPluginURI("/" + TEMPORARY_PROJECT_NAME + "/" + REPRESENTATIONS_RESOURCE_NAME, true), true);
assertTrue("The migration must be required on test data.", migrationVersion.compareTo(loadedVersion) > 0); //$NON-NLS-1$
}

private void checkRoutingStyle(AbstractDiagramEdgeEditPart edgeEditPart, String message, String edgeName, int expectedRoutingStyle) {
String fullMessage = MessageFormat.format(message, edgeName);
View notationView = edgeEditPart.getNotationView();
Expand Down Expand Up @@ -1915,8 +1933,24 @@ protected void openDiagram(String diagramName) {
diagram = (DDiagram) getRepresentationsByName(diagramName).toArray()[0];
editorPart = (IDiagramWorkbenchPart) DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
TestsUtil.synchronizationWithUIThread();
checkStringValueStyle();
}

protected void checkStringValueStyle() {
Diagram gmfDiag = getGmfDiagram(diagram);
if (gmfDiag != null) {
TreeIterator<EObject> childIterator = gmfDiag.eAllContents();
while (childIterator.hasNext()) {
EObject eObject = childIterator.next();
if (eObject instanceof Edge edge) {
StringValueStyle stringValueStyle = (StringValueStyle) edge.getStyle(NotationPackage.Literals.STRING_VALUE_STYLE);
if (stringValueStyle != null && GmfLayoutCommand.JUNCTION_POINTS_STYLE_NAME.equals(stringValueStyle.getName()) && "()".equals(stringValueStyle.getStringValue())) {
fail("At least one edge contains an empty junctionPoints StringValueStyle.");
}
}
}
}
}

/**
* Check that the Note is moved or not moved with an arrange using ELK, according to the value of the preference
* "Move unlinked notes during layout".
Expand Down

0 comments on commit 049f646

Please sign in to comment.