diff options
author | Vincent Lorenzo | 2017-01-17 15:28:23 +0000 |
---|---|---|
committer | Vincent Lorenzo | 2017-01-17 16:16:09 +0000 |
commit | 3642411bd315d2b3c4f2f3162856357c5fe7547b (patch) | |
tree | a4f62fc63bb0ec219af6f10a27b4d970ba48cc90 /extraplugins | |
parent | 2ff7b6dde56a5f78f3eb73e6ec65ccd24885647d (diff) | |
download | org.eclipse.papyrus-3642411bd315d2b3c4f2f3162856357c5fe7547b.tar.gz org.eclipse.papyrus-3642411bd315d2b3c4f2f3162856357c5fe7547b.tar.xz org.eclipse.papyrus-3642411bd315d2b3c4f2f3162856357c5fe7547b.zip |
Bug 510586: [Importer][Rhapsody] The tool to update Rhapsody metamodel from example is broken
Bug 510585: [Imported][Rhapsody] files *.umlrhapsody must provide a way to distinguish user file from Rhapsody file
Change-Id: I36b8edde7f4034c1309e8484528daf982ed554f9
Signed-off-by: Sebastien Revol <sebastien.revol@cea.fr>
Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
Diffstat (limited to 'extraplugins')
4 files changed, 114 insertions, 22 deletions
diff --git a/extraplugins/migration/rhapsody/developer/org.eclipse.papyrus.migration.rhapsody.dev.api.discovery/src/org/eclipse/papyrus/migration/rhapsody/dev/api/discovery/MetamodelFactorizer.java b/extraplugins/migration/rhapsody/developer/org.eclipse.papyrus.migration.rhapsody.dev.api.discovery/src/org/eclipse/papyrus/migration/rhapsody/dev/api/discovery/MetamodelFactorizer.java index 56109f822a7..ea5812ff928 100644 --- a/extraplugins/migration/rhapsody/developer/org.eclipse.papyrus.migration.rhapsody.dev.api.discovery/src/org/eclipse/papyrus/migration/rhapsody/dev/api/discovery/MetamodelFactorizer.java +++ b/extraplugins/migration/rhapsody/developer/org.eclipse.papyrus.migration.rhapsody.dev.api.discovery/src/org/eclipse/papyrus/migration/rhapsody/dev/api/discovery/MetamodelFactorizer.java @@ -239,20 +239,33 @@ public class MetamodelFactorizer { return ret; } - private static EClass findCommonSuperType(List<EClass> types) { + private static List<EClass> findCommonSuperTypes(List<EClass> types) { Iterator<EClass> typeIter = types.iterator(); EClass firstType = typeIter.next(); - List<EClass> ret = new ArrayList<>(firstType.getESuperTypes()); + List<EClass> ret = new ArrayList<>(firstType.getEAllSuperTypes()); + ret.add(firstType); while (typeIter.hasNext() && !ret.isEmpty()){ EClass nextType = typeIter.next(); + ret.add(nextType); ret.retainAll(nextType.getEAllSuperTypes()); } - if (!ret.isEmpty()){ - return ret.get(0); + + //we have here the intersection of all common super types. + //we now remove shared "grand-super-types" (super types of super types) + + Set<EClass> grandSuperTypes = new HashSet<EClass>(); + for (EClass superType : ret){ + for (EClass grandSuperType : superType.getEAllSuperTypes()){ + if (ret.contains(grandSuperType)){ + grandSuperTypes.add(grandSuperType); + } + } } - - return null; + + ret.removeAll(grandSuperTypes); + + return ret; } /** @@ -375,20 +388,15 @@ public class MetamodelFactorizer { */ private static EClass findOrCreateCommonFeatureType(EStructuralFeature finalRef, List<EClass> types) { - EClass commonSuperType = findCommonSuperType(types); - if (commonSuperType != null){ - return commonSuperType; + List<EClass> commonSuperType = findCommonSuperTypes(types); + + //if there is already exactly one common superType, we use it + if (commonSuperType.size() == 1){ + return commonSuperType.get(0); } - // List<EClass> commonSuperTypes = collectCommonL1SuperTypes(types); - // - // //in this implem, we reuse an existing type only if the list of existing types is exactly the list of the subtypes of a common ancestor - // for (EClass superType : commonSuperTypes){ - // List<EClass> specializations = collectCommonL1Specializations(superType); - // if (specializations.size() == types.size()){ - // return superType; - // } - // } + //if there are 0 common super types or more than one, we create a new type, or check if this type already exists + //considering that all the features with the same name have the same type... (strong hypothesis...) EPackage targetEPack = finalRef.getEContainingClass().getEPackage(); String eClassName = capitalize(finalRef.getName())+"Type"; //eClassName = finalRef.getEContainingClass().getName() + "_"+ eClassName; diff --git a/extraplugins/migration/rhapsody/developer/org.eclipse.papyrus.migration.rhapsody.dev.api.discovery/src/org/eclipse/papyrus/migration/rhapsody/dev/api/discovery/RhapsodyMetamodelGenerator.java b/extraplugins/migration/rhapsody/developer/org.eclipse.papyrus.migration.rhapsody.dev.api.discovery/src/org/eclipse/papyrus/migration/rhapsody/dev/api/discovery/RhapsodyMetamodelGenerator.java index e92f7c5cff2..797ca7211d1 100644 --- a/extraplugins/migration/rhapsody/developer/org.eclipse.papyrus.migration.rhapsody.dev.api.discovery/src/org/eclipse/papyrus/migration/rhapsody/dev/api/discovery/RhapsodyMetamodelGenerator.java +++ b/extraplugins/migration/rhapsody/developer/org.eclipse.papyrus.migration.rhapsody.dev.api.discovery/src/org/eclipse/papyrus/migration/rhapsody/dev/api/discovery/RhapsodyMetamodelGenerator.java @@ -117,6 +117,9 @@ public class RhapsodyMetamodelGenerator { * @param content */ private EClass transform(RpyNode node) { + if (node.getName() == null || node.getName().isEmpty()){ + return null; + } EClass eClass = eClassMap.get(node.getName()); if (eClass == null){ eClass = EcoreFactory.eINSTANCE.createEClass(); @@ -148,7 +151,7 @@ public class RhapsodyMetamodelGenerator { */ private void transformOwningHandlerIfDifferent(RpyNode referencedNode, RpyFeature rpyFeature) { RpyFileHandler referencedNodeHandler = projectHandler.getOwningFileHandler(referencedNode); - if (referencedNodeHandler != projectHandler.getOwningFileHandler((RpyNode)rpyFeature.eContainer()) && !transformedFileHandlers.contains(referencedNodeHandler)){ + if (referencedNodeHandler != null && referencedNodeHandler != projectHandler.getOwningFileHandler((RpyNode)rpyFeature.eContainer()) && !transformedFileHandlers.contains(referencedNodeHandler)){ transformedFileHandlers.add(referencedNodeHandler); transform(referencedNodeHandler); } diff --git a/extraplugins/migration/rhapsody/org.eclipse.papyrus.migration.rhapsody/src/org/eclipse/papyrus/migration/rhapsody/importer/UMLRhapsodyImporter.java b/extraplugins/migration/rhapsody/org.eclipse.papyrus.migration.rhapsody/src/org/eclipse/papyrus/migration/rhapsody/importer/UMLRhapsodyImporter.java index 1435c78ce58..70f3f21b085 100755 --- a/extraplugins/migration/rhapsody/org.eclipse.papyrus.migration.rhapsody/src/org/eclipse/papyrus/migration/rhapsody/importer/UMLRhapsodyImporter.java +++ b/extraplugins/migration/rhapsody/org.eclipse.papyrus.migration.rhapsody/src/org/eclipse/papyrus/migration/rhapsody/importer/UMLRhapsodyImporter.java @@ -14,13 +14,18 @@ package org.eclipse.papyrus.migration.rhapsody.importer; import java.io.IOException; +import java.net.URL; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.eclipse.core.runtime.FileLocator; import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EAnnotation; import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EObject; @@ -48,6 +53,7 @@ import org.eclipse.papyrus.migration.rhapsody.parser.rpySyntax.SimpleValueList; import org.eclipse.papyrus.migration.rhapsody.rhapsodymetamodel.IProject; import org.eclipse.papyrus.migration.rhapsody.rhapsodymetamodel.UMLRhapsodyFactory; import org.eclipse.papyrus.migration.rhapsody.rhapsodymetamodel.UMLRhapsodyPackage; +import org.eclipse.papyrus.migration.rhapsody.utils.RhapsodyShareFolderUtils; /** @@ -129,7 +135,7 @@ public class UMLRhapsodyImporter { */ private EObject transform(RpyFileHandler rpyFileHandler) { Resource outputRes = getResource(rpyFileHandler); - if (outputRes.getContents().isEmpty()){ + if (outputRes.getContents().isEmpty() || outputRes.getContents().get(0) instanceof EAnnotation){ RpyFile rpyFile = rpyFileHandler.getRpyFile(); List<EObject> roots= new ArrayList<EObject>(); @@ -141,7 +147,7 @@ public class UMLRhapsodyImporter { } } } - outputRes.getContents().addAll(roots); + outputRes.getContents().addAll(0, roots); } if (outputRes.getContents().isEmpty()){ return null; @@ -328,12 +334,41 @@ public class UMLRhapsodyImporter { if (inURI != null){ URI outURI = URI.createFileURI(targetPath).appendSegment(inURI.trimFileExtension().lastSegment()).appendFileExtension(RhapsodyFileUtils.UML_RHAPSODY_FILE); ret= resSet.createResource(outURI); + addSharedResourceAnnotationIfNeeded(inURI, ret); fileToResourceMap.put(rpyFileHandler, ret); } } return ret; } + /** + * @param inURI + * @param ret + */ + private void addSharedResourceAnnotationIfNeeded(URI inURI, Resource ret) { + String sharedFolderURIString = RhapsodyShareFolderUtils.getRhapsodyShareFolder(); + if (sharedFolderURIString != null){ + URL inURL; + try { + inURL = FileLocator.toFileURL(new URL(inURI.toString())); + if (inURL != null) { + Path inURIPath = Paths.get(inURL.toURI()); + Path sharedFolderPath = Paths.get(sharedFolderURIString); + if(inURIPath.toAbsolutePath().startsWith(sharedFolderPath.toAbsolutePath())){ + EAnnotation annotation = RhapsodyShareFolderUtils.createRhapsodyLibraryResourceEAnnotation(); + ret.getContents().add(annotation); + } + } + + } catch (Exception e) { + //should never happen since the file from inURI has already been loaded + } + + } + + + } + diff --git a/extraplugins/migration/rhapsody/org.eclipse.papyrus.migration.rhapsody/src/org/eclipse/papyrus/migration/rhapsody/utils/RhapsodyShareFolderUtils.java b/extraplugins/migration/rhapsody/org.eclipse.papyrus.migration.rhapsody/src/org/eclipse/papyrus/migration/rhapsody/utils/RhapsodyShareFolderUtils.java index b8717032b0e..92dc8760cd4 100755 --- a/extraplugins/migration/rhapsody/org.eclipse.papyrus.migration.rhapsody/src/org/eclipse/papyrus/migration/rhapsody/utils/RhapsodyShareFolderUtils.java +++ b/extraplugins/migration/rhapsody/org.eclipse.papyrus.migration.rhapsody/src/org/eclipse/papyrus/migration/rhapsody/utils/RhapsodyShareFolderUtils.java @@ -21,6 +21,10 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EcoreFactory; +import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.osgi.util.NLS; @@ -56,6 +60,16 @@ public class RhapsodyShareFolderUtils { private static final String RHAPSODY_HOME_VARIABLE_NAME = "RhapsodyHome"; //$NON-NLS-1$ + /** + * text used for EAnnotation created during the Rhapsody import + */ + public static final String RHAPSODY_IMPORTER_EANNOTATION_SOURCE = "RhapsodyImporter";//$NON-NLS-1$ + + /** + * String used to define if the created resource represents a Rhapsody Library (<code>true</code>) or a user resource (<code>false</code>) + */ + public static final String RHAPSODY_IMPORTER_IS_RHAPSODY_LIBRARY_RESOURCE_KEY = "IsRhapsodyLibraryResource";//$NON-NLS-1$ + /** * Constructor. @@ -111,7 +125,7 @@ public class RhapsodyShareFolderUtils { if (!finalResult) { final MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), SELECT_FOLDER_TITLE, null, MESSAGE, MessageDialog.QUESTION, 0, new String[] { Messages.RhapsodyShareFolderUtils_Retry, IDialogConstants.CANCEL_LABEL }); int res = dialog.open(); - if (IDialogConstants.OK_ID==res) { + if (IDialogConstants.OK_ID == res) { finalResult = checkRhapsodyShareFolderAndAskForItWhenRequired(); } } @@ -294,4 +308,36 @@ public class RhapsodyShareFolderUtils { } return new Status(IStatus.OK, Activator.PLUGIN_ID, NLS.bind("The required folder \"{0}\" doesn't exist in the \"{1}\" folder.", name, SHARE)); //$NON-NLS-1$ } + + /** + * + * @return + * a EAnnotation defining that the resource is a Rhapsody Library + */ + public static EAnnotation createRhapsodyLibraryResourceEAnnotation() { + final EAnnotation result = EcoreFactory.eINSTANCE.createEAnnotation(); + result.setSource(RHAPSODY_IMPORTER_EANNOTATION_SOURCE); + result.getDetails().put(RHAPSODY_IMPORTER_IS_RHAPSODY_LIBRARY_RESOURCE_KEY, Boolean.TRUE.toString()); + return result; + } + + /** + * + * @param resource + * a resource + * @return + * <code>true</code> if the resource represents a Rhapsody Library. <code>false</code> otherwise + */ + public static boolean isRhapsodyLibraryResource(final Resource resource) { + for (EObject content : resource.getContents()) { + if (content instanceof EAnnotation) { + EAnnotation annotation = (EAnnotation) content; + if (RHAPSODY_IMPORTER_EANNOTATION_SOURCE.equals(annotation.getSource())) { + return Boolean.TRUE.toString().equals(annotation.getDetails().get(RHAPSODY_IMPORTER_IS_RHAPSODY_LIBRARY_RESOURCE_KEY)); + } + } + } + return false; + } + } |