diff options
| author | Jessy Mallet | 2014-12-12 14:43:58 +0000 |
|---|---|---|
| committer | Florian Barbin | 2015-01-07 10:09:26 +0000 |
| commit | cb8499c09408259c240f11574c166c742b81434c (patch) | |
| tree | 51332fc2e980f8775f69976ecee9ce9fce39b535 | |
| parent | 0861e3010268a59f4325f66b43fc78be771ce44a (diff) | |
| download | org.eclipse.sirius-cb8499c09408259c240f11574c166c742b81434c.tar.gz org.eclipse.sirius-cb8499c09408259c240f11574c166c742b81434c.tar.xz org.eclipse.sirius-cb8499c09408259c240f11574c166c742b81434c.zip | |
[431196] Avoid NPE in VSM editor for invalid metamodel URI.
When the Properties view is visible on tab metamodel, an error is logged
for invalid diagram's metamodel URI and the NPE is avoid.
Bug: 431196
Change-Id: Ib9b5af3d6c57d0317fea671d30f746c972dced81
Signed-off-by: Jessy Mallet <jessy.mallet@obeo.fr>
4 files changed, 207 insertions, 25 deletions
diff --git a/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/properties/sections/description/representationdescription/RepresentationDescriptionMetamodelPropertySectionSpec.java b/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/properties/sections/description/representationdescription/RepresentationDescriptionMetamodelPropertySectionSpec.java index 8475a24332..ba588d1bdf 100644 --- a/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/properties/sections/description/representationdescription/RepresentationDescriptionMetamodelPropertySectionSpec.java +++ b/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/properties/sections/description/representationdescription/RepresentationDescriptionMetamodelPropertySectionSpec.java @@ -13,18 +13,25 @@ package org.eclipse.sirius.editor.properties.sections.description.representation import java.util.ArrayList; import java.util.List; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.InternalEObject; import org.eclipse.emf.ecore.plugin.EcorePlugin; import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.emf.edit.domain.IEditingDomainProvider; +import org.eclipse.jface.fieldassist.FieldDecoration; +import org.eclipse.jface.fieldassist.FieldDecorationRegistry; +import org.eclipse.sirius.editor.editorPlugin.SiriusEditorPlugin; import org.eclipse.sirius.editor.properties.ViewpointPropertySheetPage; import org.eclipse.sirius.editor.properties.sections.common.AbstractViewpointPropertySection; import org.eclipse.sirius.viewpoint.description.DescriptionPackage; import org.eclipse.sirius.viewpoint.description.RepresentationDescription; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.widgets.Button; @@ -185,32 +192,47 @@ public class RepresentationDescriptionMetamodelPropertySectionSpec extends Abstr for (EPackage ePackage : ePackages) { TableItem item = new TableItem(metamodelsTable, 0); item.setData(ePackage); - String ePackageName = ePackage.getName(); - if (ePackageName == null) { - ePackageName = "null"; - } - item.setText(0, ePackageName); - String ePackageNSURI = ePackage.getNsURI(); - if (ePackageNSURI == null) { - ePackageNSURI = "null"; - } - item.setText(1, ePackageNSURI); - String ePackageURI = null; - URI completeURIToEPackage = representationDescriptionMetamodelsUpdater.getCompleteURIToEPackage(ePackage); - if (completeURIToEPackage != null) { - ePackageURI = URI.decode(completeURIToEPackage.toString()); - } else { - URI genModelResourceURI = EcorePlugin.getEPackageNsURIToGenModelLocationMap().get(ePackage.getNsURI()); - if (genModelResourceURI != null) { - ePackageURI = genModelResourceURI.trimFileExtension().appendFileExtension("ecore").toString(); + if (ePackage.eResource() != null) { + String ePackageName = ePackage.getName(); + if (ePackageName == null) { + ePackageName = "null"; } - } - if (ePackageURI == null) { - ePackageURI = "unknow metamodel resource URI"; - } - item.setText(2, ePackageURI); - if (!previousEPackages.contains(ePackage)) { - newItems.add(item); + item.setText(0, ePackageName); + String ePackageNSURI = ePackage.getNsURI(); + if (ePackageNSURI == null) { + ePackageNSURI = "null"; + } + item.setText(1, ePackageNSURI); + String ePackageURI = null; + URI completeURIToEPackage = representationDescriptionMetamodelsUpdater.getCompleteURIToEPackage(ePackage); + if (completeURIToEPackage != null) { + ePackageURI = URI.decode(completeURIToEPackage.toString()); + } else { + URI genModelResourceURI = EcorePlugin.getEPackageNsURIToGenModelLocationMap().get(ePackage.getNsURI()); + if (genModelResourceURI != null) { + ePackageURI = genModelResourceURI.trimFileExtension().appendFileExtension("ecore").toString(); + } + } + if (ePackageURI == null) { + ePackageURI = "unknow metamodel resource URI"; + } + item.setText(2, ePackageURI); + if (!previousEPackages.contains(ePackage)) { + newItems.add(item); + } + } else { + URI proxyURI = ((InternalEObject) ePackage).eProxyURI(); + String ePackageName = proxyURI.lastSegment().substring(0, proxyURI.lastSegment().indexOf('.')); + item.setText(0, ePackageName); + item.setText(1, "null"); + String ePackageURI = proxyURI.trimFragment().toString(); + item.setText(2, ePackageURI); + // Adding decorator + FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR); + Image img = fieldDecoration.getImage(); + item.setImage(img); + // Log an error in the "Error log" view. + SiriusEditorPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, SiriusEditorPlugin.PLUGIN_ID, "Invalid ressource access for the metamodel " + ePackageURI)); } } if (!newItems.isEmpty()) { diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/viewpoint_uri/bugzilla-431196/invalidMetamodelUri.odesign b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/viewpoint_uri/bugzilla-431196/invalidMetamodelUri.odesign new file mode 100644 index 0000000000..1007796baf --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/viewpoint_uri/bugzilla-431196/invalidMetamodelUri.odesign @@ -0,0 +1,31 @@ +<?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" xmlns:style="http://www.eclipse.org/sirius/diagram/description/style/1.1.0" name="Group" version="10.0.0.201411061000"> + <ownedViewpoints name="testInvalidMetamodelUri" modelFileExtension="basicfamily"> + <ownedRepresentations xsi:type="description_1:DiagramDescription" name="Family" domainClass="basicfamily.Family"> + <metamodel href="file:/C:/Users/Stephan%20Kranz/workspace/basicfamily/model/basicfamily.ecore#/"/> + <defaultLayer name="Default"> + <nodeMappings name="Family" domainClass="basicfamily.Family"> + <style xsi:type="style:SquareDescription" resizeKind="NSEW"> + <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <color xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='gray']"/> + </style> + </nodeMappings> + <nodeMappings name="Man" domainClass="basicfamily.Man"> + <style xsi:type="style:SquareDescription" resizeKind="NSEW"> + <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <color xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='light_blue']"/> + </style> + </nodeMappings> + <nodeMappings name="Woman" domainClass="basicfamily.Woman"> + <style xsi:type="style:SquareDescription" resizeKind="NSEW"> + <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <color xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='light_red']"/> + </style> + </nodeMappings> + </defaultLayer> + </ownedRepresentations> + </ownedViewpoints> +</description:Group> diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/InvalidMetamodelRessourceTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/InvalidMetamodelRessourceTest.java new file mode 100644 index 0000000000..c2b5c8b0c9 --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/InvalidMetamodelRessourceTest.java @@ -0,0 +1,128 @@ +/******************************************************************************* + * Copyright (c) 2014 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.swtbot; + +import org.eclipse.sirius.tests.swtbot.support.api.AbstractSiriusSwtBotGefTestCase; +import org.eclipse.sirius.tests.swtbot.support.api.condition.TreeItemExpanded; +import org.eclipse.sirius.tests.swtbot.support.api.editor.SWTBotSiriusHelper; +import org.eclipse.sirius.tests.swtbot.support.api.editor.SWTBotVSMEditor; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; + +/** + * Test that the invalid Meta-model is displayed in the error log. + * + * @author <a href="mailto:jessy.mallet@obeo.fr">Jessy MALLET</a> + */ +public class InvalidMetamodelRessourceTest extends AbstractSiriusSwtBotGefTestCase { + + /** + * Viewpoint Specific Model. + */ + private static final String VSM = "invalidMetamodelUri.odesign"; + + /** + * VSM path. + */ + private static final String ODESIGN = "platform:/resource/DesignerTestProject/" + VSM; + + /** + * Test repository. + */ + private static final String DATA_UNIT_DIR = "data/unit/viewpoint_uri/bugzilla-431196/"; + + /** + * Sirius Group. + */ + private static final String GROUP = "Group"; + + /** + * Properties view tab Meta-models. + */ + private static final String METAMODELS = "Metamodels"; + + /** + * Properties view. + */ + protected static final String PROPERTIES = "Properties"; + + /** + * {@inheritDoc} + */ + @Override + protected void onSetUpBeforeClosingWelcomePage() throws Exception { + copyFileToTestProject(Activator.PLUGIN_ID, DATA_UNIT_DIR, VSM); + } + + /** + * Test that the invalid meta-model appears in the "Error log" view. + */ + public void testDefaultLabelExpressionValue() { + // Opened VSM + SWTBotVSMEditor odesignEditor = openViewpointSpecificationModel(VSM); + // expand the tree : Node Mapping + SWTBotTree tree = odesignEditor.bot().tree(); + tree.expandNode(ODESIGN).expandNode(GROUP).expandNode("testInvalidMetamodelUri").expandNode("Family").select(); + // accesses to property view + SWTBotView propertiesBot = bot.viewByTitle(PROPERTIES); + propertiesBot.setFocus(); + // accesses to tab Meta-model + SWTBotSiriusHelper.selectPropertyTabItem(METAMODELS); + checkMessageErrorLog(); + } + + /** + * Check that the error message for invalid meta-model URI appears in the + * "Error Log" view. + */ + private void checkMessageErrorLog() { + try { + openErrorLogView(); + SWTBotView logViewBot = bot.viewByTitle("Error Log"); + assertTrue("Invalid Metamodel URI does not appear in the error log.", isMessageInErrorLog(logViewBot)); + logViewBot.close(); + } finally { + // Reset to previous environment + errors.clear(); + } + } + + /** + * Open the error log view. + */ + private void openErrorLogView() { + bot.menu("Window").menu("Show View").menu("Other...").click(); + SWTBotTree viewsTreeBot = bot.tree(); + bot.text().setText("Error"); + SWTBotTreeItem expandNode = viewsTreeBot.expandNode("General"); + bot.waitUntil(new TreeItemExpanded(expandNode, expandNode.getText())); + expandNode.getNode("Error Log").doubleClick(); + } + + /** + * Check that the error message appears in the "Error Log" view. + * + * @param logViewBot + * the view to check + */ + private Boolean isMessageInErrorLog(SWTBotView logViewBot) { + logViewBot.show(); + SWTBotTree treeError = logViewBot.bot().tree(); + String errorMessage = "Invalid ressource access for the metamodel file:/C:/Users/Stephan%20Kranz/workspace/basicfamily/model/basicfamily.ecore"; + for (SWTBotTreeItem treeItem : treeError.getAllItems()) { + if (errorMessage.equals(treeItem.getText())) { + return true; + } + } + return false; + } +} diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java index 5a4fa937bb..0d72b54157 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java @@ -242,6 +242,7 @@ public class AllTestSuite extends TestCase { suite.addTestSuite(DoubleClickToolNavigationOperationTest.class); suite.addTestSuite(BackgroundColorFigureUpdateTests.class); suite.addTestSuite(EdgeMappingTestCase.class); + suite.addTestSuite(InvalidMetamodelRessourceTest.class); } /** |
