diff options
| author | pguilet | 2017-03-20 17:10:33 +0000 |
|---|---|---|
| committer | Pierre-Charles David | 2017-04-11 12:35:09 +0000 |
| commit | e6b04b9c506e229cf86701ae036c2178e845ff06 (patch) | |
| tree | 9c5d12287e8405cb04f8c54a9634abed1ec1f89c | |
| parent | 5f3839d69589b9a0eb799b42d7e585e6dbf7759e (diff) | |
| download | org.eclipse.sirius-e6b04b9c506e229cf86701ae036c2178e845ff06.tar.gz org.eclipse.sirius-e6b04b9c506e229cf86701ae036c2178e845ff06.tar.xz org.eclipse.sirius-e6b04b9c506e229cf86701ae036c2178e845ff06.zip | |
[466412] Add migration participant for label edit tool variables
Add a migration participant adding line and table variables to label
edit tool of tables and cross tables.
Bug: 466412
Change-Id: I8fd62f81446cb0aefc57b4b85154a5f41948dfb6
Signed-off-by: pguilet <pierre.guilet@obeo.fr>
6 files changed, 223 insertions, 1 deletions
diff --git a/plugins/org.eclipse.sirius.table.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.table.ui/META-INF/MANIFEST.MF index 41ca23dd9f..18187696f9 100644 --- a/plugins/org.eclipse.sirius.table.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.sirius.table.ui/META-INF/MANIFEST.MF @@ -22,6 +22,7 @@ Export-Package: org.eclipse.sirius.table.metamodel.table.description.provider;ve org.eclipse.sirius.table.ui.tools.internal.editor.provider;version="2.2.0";x-internal:=true, org.eclipse.sirius.table.ui.tools.internal.editor.utils;version="2.0.2";x-internal:=true, org.eclipse.sirius.table.ui.tools.internal.export;version="2.0.2";x-internal:=true, + org.eclipse.sirius.table.ui.tools.internal.migration;version="5.0.0";x-internal:=true, org.eclipse.sirius.table.ui.tools.internal.properties.propertysource;version="2.0.2";x-internal:=true, org.eclipse.sirius.table.ui.tools.internal.properties.section.common;version="2.0.2";x-internal:=true, org.eclipse.sirius.table.ui.tools.internal.properties.section.core;version="2.0.2";x-internal:=true, diff --git a/plugins/org.eclipse.sirius.table.ui/plugin.xml b/plugins/org.eclipse.sirius.table.ui/plugin.xml index 4b5796ff32..b02fe050a9 100644 --- a/plugins/org.eclipse.sirius.table.ui/plugin.xml +++ b/plugins/org.eclipse.sirius.table.ui/plugin.xml @@ -276,5 +276,12 @@ sequence="M1+O"> </key> </extension> + <extension + point="org.eclipse.sirius.migrationParticipant"> + <participant + class="org.eclipse.sirius.table.ui.tools.internal.migration.LabelEditToolVariableMigrationParticipant" + kind="VSM"> + </participant> + </extension> </plugin> diff --git a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/migration/LabelEditToolVariableMigrationParticipant.java b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/migration/LabelEditToolVariableMigrationParticipant.java new file mode 100644 index 0000000000..c34c370a78 --- /dev/null +++ b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/migration/LabelEditToolVariableMigrationParticipant.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2017 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 + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.table.ui.tools.internal.migration; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.sirius.business.api.migration.AbstractVSMMigrationParticipant; +import org.eclipse.sirius.table.metamodel.table.description.DescriptionFactory; +import org.eclipse.sirius.table.metamodel.table.description.LabelEditTool; +import org.eclipse.sirius.table.metamodel.table.description.TableVariable; +import org.eclipse.sirius.table.metamodel.table.provider.Messages; +import org.eclipse.sirius.table.tools.api.interpreter.IInterpreterSiriusTableVariables; +import org.osgi.framework.Version; + +/** + * Make sure old VSM get the 2 table variables "table" and "line" properly defined inside LabelEditTool definition. + * + * @author pguilet + * @see http://eclip.se/466412 + */ +public class LabelEditToolVariableMigrationParticipant extends AbstractVSMMigrationParticipant { + /** + * The version for which this migration is added. + */ + public static final Version MIGRATION_VERSION = new Version("12.0.0.2017041100"); //$NON-NLS-1$ + + @Override + public Version getMigrationVersion() { + return MIGRATION_VERSION; + } + + @Override + public EObject updateCreatedObject(EObject newObject, String loadedVersion) { + if (Version.parseVersion(loadedVersion).compareTo(MIGRATION_VERSION) < 0 && newObject instanceof LabelEditTool) { + LabelEditTool labelEditTool = (LabelEditTool) newObject; + + final TableVariable tableVar = DescriptionFactory.eINSTANCE.createTableVariable(); + tableVar.setName(IInterpreterSiriusTableVariables.TABLE); + tableVar.setDocumentation(Messages.Table_TableElement); + labelEditTool.getVariables().add(tableVar); + + final TableVariable lineVar = DescriptionFactory.eINSTANCE.createTableVariable(); + lineVar.setName(IInterpreterSiriusTableVariables.LINE); + lineVar.setDocumentation(Messages.Table_LineElement); + labelEditTool.getVariables().add(lineVar); + } + return newObject; + } + +} diff --git a/plugins/org.eclipse.sirius.tests.junit/data/table/unit/migration/tables.odesign b/plugins/org.eclipse.sirius.tests.junit/data/table/unit/migration/tables.odesign new file mode 100644 index 0000000000..ccac9ba002 --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.junit/data/table/unit/migration/tables.odesign @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="ASCII"?> +<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/table/description/1.1.0" xmlns:tool="http://www.eclipse.org/sirius/description/tool/1.1.0" name="UML2 Tables tests" version="12.0.0.201702091400"> + <ownedViewpoints documentation="Sample of some UML tables " name="UML2 tables for tests" modelFileExtension="uml"> + <ownedRepresentations xsi:type="description_1:EditionTableDescription" name="SimpleTableVariables" domainClass="Model"> + <metamodel href="platform:/plugin/org.eclipse.uml2.uml/model/UML.ecore#/"/> + <ownedLineMappings name="Class lines" domainClass="Class" semanticCandidatesExpression="aql:self.eAllContents(uml::Class)->select( e | e.name='Class3')->first()" headerLabelExpression=""/> + <ownedColumnMappings name="Class name" headerLabelExpression="Name" initialWidth="200" featureName="name" labelExpression="aql:self.name" featureParentExpression="aql:if table<>null then line.target else line.target endif"> + <directEdit> + <variables name="element" documentation="The semantic currently edited element."/> + <variables name="lineSemantic" documentation="The semantic element corresponding to the line."/> + <variables name="root" documentation="The semantic root element of the table."/> + <firstModelOperation xsi:type="tool:ChangeContext" browseExpression="var:element"> + <subModelOperations xsi:type="tool:SetValue" featureName="name" valueExpression="aql:if table<>null then line.target.name+'working' else line.target.name+'working' endif"/> + </firstModelOperation> + <mask mask="{0}"/> + </directEdit> + </ownedColumnMappings> + </ownedRepresentations> + <ownedRepresentations xsi:type="description_1:CrossTableDescription" name="CrossTableVariables" domainClass="Model"> + <metamodel href="platform:/plugin/org.eclipse.uml2.uml/model/UML.ecore#/"/> + <ownedLineMappings name="CTV_LineClasses" domainClass="Class" semanticCandidatesExpression="aql:self.eAllContents(uml::Class)->select( e | e.name='Class3')->first()" headerLabelExpression="aql:self.name"/> + <ownedColumnMappings name="CTV_ColumnClasses" headerLabelExpression="aql:self.name" domainClass="Class" semanticCandidatesExpression="aql:self.eAllContents(uml::Class)->select( e | e.name='Class3')->first()"/> + <intersection name="Generalization" lineMapping="//@ownedViewpoints[name='UML2%20tables%20for%20tests']/@ownedRepresentations[name='CrossTableVariables']/@ownedLineMappings[name='CTV_LineClasses']" columnMapping="//@ownedViewpoints[name='UML2%20tables%20for%20tests']/@ownedRepresentations[name='CrossTableVariables']/@ownedColumnMappings.0" labelExpression="aql:line.target.name" columnFinderExpression="aql:self"> + <directEdit> + <variables name="element" documentation="The semantic currently edited element."/> + <variables name="lineSemantic" documentation="The semantic element corresponding to the line."/> + <variables name="columnSemantic" documentation="The semantic element corresponding to the column (only available for Intersection Mapping)."/> + <variables name="root" documentation="The semantic root element of the table."/> + <firstModelOperation xsi:type="tool:ChangeContext" browseExpression="var:element"> + <subModelOperations xsi:type="tool:SetValue" featureName="name" valueExpression="aql:if table<>null then line.target.name+'working' else line.target.name+'working' endif"/> + </firstModelOperation> + <mask mask="{0}"/> + </directEdit> + </intersection> + </ownedRepresentations> + <ownedJavaExtensions qualifiedClassName="org.eclipse.sirius.common.tools.api.interpreter.StandardServices"/> + </ownedViewpoints> +</description:Group> 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 331e1721e2..2d48156e01 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2016 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2017 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 @@ -104,6 +104,7 @@ import org.eclipse.sirius.tests.unit.common.migration.DiagramMigrationTestCampai import org.eclipse.sirius.tests.unit.common.migration.DiagramMigrationTestCampaign09; import org.eclipse.sirius.tests.unit.common.migration.DiagramMigrationTestCampaign10; import org.eclipse.sirius.tests.unit.common.migration.GeneralMigrationMechanismTest; +import org.eclipse.sirius.tests.unit.common.migration.LabelEditToolVariableMigrationTest; import org.eclipse.sirius.tests.unit.common.migration.MigrationFromSirius0_9Test; import org.eclipse.sirius.tests.unit.common.migration.MigrationFromSirius1_0_0_M5Test; import org.eclipse.sirius.tests.unit.common.migration.ModelsToSemanticResourcesMigrationTest; @@ -222,6 +223,7 @@ public class AllCommonPluginTests extends TestCase { suite.addTestSuite(FontFormatMigrationTest.class); suite.addTestSuite(BorderSizeMigrationTest.class); suite.addTestSuite(VariableMigrationTest.class); + suite.addTestSuite(LabelEditToolVariableMigrationTest.class); suite.addTestSuite(DRepresentationContainerRemovalMigrationTest.class); suite.addTestSuite(DRepDescriptorCreationMigrationTest.class); suite.addTestSuite(NoteAttachmentMigrationTest.class); diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/migration/LabelEditToolVariableMigrationTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/migration/LabelEditToolVariableMigrationTest.java new file mode 100644 index 0000000000..c5951c1a6d --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/migration/LabelEditToolVariableMigrationTest.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * Copyright (c) 2017 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 + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.tests.unit.common.migration; + +import java.io.IOException; +import java.util.Collections; + +import org.eclipse.emf.common.util.TreeIterator; +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.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.sirius.business.internal.migration.description.VSMMigrationService; +import org.eclipse.sirius.diagram.tools.api.command.IDiagramCommandFactory; +import org.eclipse.sirius.table.metamodel.table.description.LabelEditTool; +import org.eclipse.sirius.table.ui.tools.internal.migration.LabelEditToolVariableMigrationParticipant; +import org.eclipse.sirius.tests.SiriusTestsPlugin; +import org.eclipse.sirius.tests.support.api.SiriusTestCase; +import org.eclipse.sirius.viewpoint.description.Group; +import org.osgi.framework.Version; + +/** + * Ensures correct migration of + * {@link LabelEditToolVariableMigrationParticipant}. + * + * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> + */ +public class LabelEditToolVariableMigrationTest extends SiriusTestCase { + private static final String FOLDER_PATH = "data/table/unit/migration/"; + + private static final String VSM_NAME = "tables.odesign"; + + private static final String TEST_DIR = "/" + SiriusTestsPlugin.PLUGIN_ID + FOLDER_PATH; + + private static final String MODELER_PATH = TEST_DIR + VSM_NAME; + + @Override + protected IDiagramCommandFactory getCommandFactory() { + return null; + } + + /** + * Test that the data were not migrated. It allows to check the effect of + * the migration in the other test. + */ + public void testVSMMigrationIsNeededOnData() { + Version loadedVersion = checkVsmFileMigrationStatus(URI.createPlatformPluginURI(SiriusTestsPlugin.PLUGIN_ID + MODELER_PATH, true), true); + + // Check that the migration is needed. + Version migration = LabelEditToolVariableMigrationParticipant.MIGRATION_VERSION; + assertTrue("The migration must be required on test data.", loadedVersion == null || migration.compareTo(loadedVersion) > 0); + } + + /** + * Check that the line and table variables are present on table and cross + * table's label edit tool after the migration of + * {@link LabelEditToolVariableMigrationParticipant}. + * + * @throws IOException + * if a save problem occurs. + */ + public void testLabelEditToolVariableMigration() throws IOException { + copyFilesToTestProject(SiriusTestsPlugin.PLUGIN_ID, FOLDER_PATH, VSM_NAME); + ResourceSet set = new ResourceSetImpl(); + Group group = null; + Resource resourceVSM = set.getResource(URI.createPlatformResourceURI(TEMPORARY_PROJECT_NAME + "/" + VSM_NAME, true), true); + group = (Group) resourceVSM.getContents().get(0); + + assertNotNull("Group is not retrieved.", group); + + // The version will change on save, so migration service will still + // indicates that the migration is needed. + String version = group.getVersion(); + assertTrue("Before save, the migration framework will return true even if the migration has been done during load.", + VSMMigrationService.getInstance().isMigrationNeeded(Version.parseVersion(version))); + + resourceVSM.save(Collections.emptyMap()); + + // save should update the version. + version = group.getVersion(); + assertFalse("The version tag should now be set telling that the migration was done.", VSMMigrationService.getInstance().isMigrationNeeded(Version.parseVersion(version))); + + // We can now check the migration effect to be sure that the migration + // is effective. + checkVSMMigrationEffect(group); + + } + + /** + * Checks that all label edit tool from table and cross tables does contain + * the line and table variables. + * + * @param group + * the group from which the check is done. + */ + private void checkVSMMigrationEffect(Group group) { + TreeIterator<EObject> eAllContents = group.eAllContents(); + while (eAllContents.hasNext()) { + EObject eObject = eAllContents.next(); + if (eObject instanceof LabelEditTool) { + LabelEditTool labelEditTool = (LabelEditTool) eObject; + assertTrue("The label edit tool has not the variable line", labelEditTool.getVariables().stream().anyMatch(variable -> "line".equals(variable.getName()))); + assertTrue("The label edit tool has not the variable table", labelEditTool.getVariables().stream().anyMatch(variable -> "table".equals(variable.getName()))); + } + + } + } +} |
