diff options
author | Alexandra Buzila | 2020-11-25 16:45:18 +0000 |
---|---|---|
committer | Vincent Lorenzo | 2021-03-26 08:31:53 +0000 |
commit | 61273267dbcc345740b17f1a00bc3f1c5557ca29 (patch) | |
tree | e036d507bf44509e9952c953d4992961046d4487 /plugins/infra/emf | |
parent | c48c85cce492e090e803075bb4c77bb53d81a11e (diff) | |
download | org.eclipse.papyrus-61273267dbcc345740b17f1a00bc3f1c5557ca29.tar.gz org.eclipse.papyrus-61273267dbcc345740b17f1a00bc3f1c5557ca29.tar.xz org.eclipse.papyrus-61273267dbcc345740b17f1a00bc3f1c5557ca29.zip |
Bug 568495 - Static Profile Improvements
- validate the 'org.eclipse.emf.ecore.generated_package',
'org.eclipse.uml2.uml.generated_package' and
'org.eclipse.papyrus.uml.extensionpoints.UMLProfile' extension points
and add quick fixes for validation problems
- externalize strings
Change-Id: I54e02c4ca805e0f34c9b301c8a3ed25b55a51f63
Signed-off-by: Alexandra Buzila <abuzila@eclipsesource.com>
Also-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
Diffstat (limited to 'plugins/infra/emf')
-rw-r--r-- | plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF | 3 | ||||
-rw-r--r-- | plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ResourceUtils.java | 77 |
2 files changed, 77 insertions, 3 deletions
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF index 0208c8a64de..184e930d44a 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF @@ -19,7 +19,8 @@ Require-Bundle: org.eclipse.core.expressions;bundle-version="[3.6.0,4.0.0)", org.eclipse.papyrus.infra.core.log;bundle-version="[2.0.0,3.0.0)", org.eclipse.papyrus.infra.core.sashwindows.di;bundle-version="[2.0.0,3.0.0)", org.eclipse.papyrus.infra.tools;bundle-version="[4.0.0,5.0.0)", - org.eclipse.uml2.types;bundle-version="[2.5.0,3.0.0)" + org.eclipse.uml2.types;bundle-version="[2.5.0,3.0.0)", + org.eclipse.pde.core;bundle-version="[3.14.100,4.0.0)" Bundle-Vendor: Eclipse Modeling Project Bundle-ActivationPolicy: lazy Bundle-Version: 4.1.0.qualifier diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ResourceUtils.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ResourceUtils.java index 83eb3960660..038c00c26f3 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ResourceUtils.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ResourceUtils.java @@ -15,30 +15,48 @@ *****************************************************************************/ package org.eclipse.papyrus.infra.emf.utils; +import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Map; +import java.util.Map.Entry; +import java.util.Objects; import java.util.Set; +import java.util.stream.Collectors; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; 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.impl.URIMappingRegistryImpl; import org.eclipse.emf.ecore.xmi.XMIResource; import org.eclipse.emf.ecore.xmi.XMLResource; +import org.eclipse.pde.core.plugin.IPluginExtension; +import org.eclipse.pde.core.plugin.IPluginModelBase; +import org.eclipse.pde.core.plugin.IPluginObject; +import org.eclipse.pde.core.plugin.PluginRegistry; +import org.eclipse.pde.internal.core.text.plugin.PluginElementNode; /** * * This class provides methods for EMF Resource * */ +@SuppressWarnings("restriction") public class ResourceUtils { + private static final String ECORE_URI_MAPPING_EXTENSION_POINT = "org.eclipse.emf.ecore.uri_mapping"; //$NON-NLS-1$ + private static final String PATH_SEPARATOR = "/"; + + private ResourceUtils() { // to prevent instanciation } @@ -72,7 +90,7 @@ public class ResourceUtils { * */ public static Collection<String> getAllResourceIds(final XMIResource resource) { - final Set<String> ids = new HashSet<String>(); + final Set<String> ids = new HashSet<>(); final Iterator<EObject> iterator = resource.getAllContents(); while (iterator.hasNext()) { final EObject current = iterator.next(); @@ -91,7 +109,7 @@ public class ResourceUtils { * @return */ public static Map<String, Object> getSaveOptions() { - Map<String, Object> saveOptions = new HashMap<String, Object>(); + Map<String, Object> saveOptions = new HashMap<>(); // default save options. saveOptions.put(XMLResource.OPTION_DECLARE_XML, Boolean.TRUE); @@ -108,4 +126,59 @@ public class ResourceUtils { return saveOptions; } + /** + * Return an encoded path string that can be used as a path attribute in a an extension for the given file. + * If an Ecore URI mapping exists for the path, it will be used as a path segment. + * Otherwise, a project-relative encoded path will be returned. + */ + public static String mapAndEncodePath(IFile file) { + // check if we have a mapping that we can use + URI pluginURI = URI.createPlatformPluginURI(file.getProject().getName() + PATH_SEPARATOR + file.getProjectRelativePath().toString(), true); + String path = pluginURI.toString(); + + // check local mappings first + for (Entry<String, String> entry : getLocalUriMappings(file.getProject()).entrySet()) { + String targetURI = entry.getValue(); + if (targetURI != null && targetURI.endsWith(PATH_SEPARATOR) && path.startsWith(targetURI)) { + return path.replaceFirst(targetURI, entry.getKey()); + } + } + // check registered mappings + for (Entry<URI, URI> entry : URIMappingRegistryImpl.INSTANCE.entrySet()) { + String targetURI = entry.getValue().toString(); + if (targetURI != null && targetURI.endsWith(PATH_SEPARATOR) && path.startsWith(targetURI)) { + return path.replaceFirst(targetURI, entry.getKey().toString()); + } + } + // no mapping were found - fallback to project relative path + IPath relativePath = file.getProjectRelativePath(); + return getStringURI(relativePath); + } + + /** Return the `org.eclipse.emf.ecore.uri_mapping` extension declarations in the given project. */ + public static Map<String, String> getLocalUriMappings(IProject project) { + HashMap<String, String> localMappings = new HashMap<>(); + final IPluginModelBase model = PluginRegistry.findModel(project.getName()); + for (IPluginExtension extension : model.getExtensions().getExtensions()) { + if (!Objects.equals(extension.getPoint(), ECORE_URI_MAPPING_EXTENSION_POINT)) { + continue; + } + List<IPluginObject> pluginObjects = Arrays.stream(extension.getChildren()).filter(child -> Objects.equals("mapping", child.getName())).collect(Collectors.toList()); //$NON-NLS-1$ + pluginObjects.forEach(pluginObject -> { + if ((pluginObject instanceof PluginElementNode)) { + PluginElementNode node = (PluginElementNode) pluginObject; + localMappings.put(node.getAttribute("source").getValue(), node.getAttribute("target").getValue()); //$NON-NLS-1$ //$NON-NLS-2$ + } + }); + } + return localMappings; + } + + /** Returns an encoded string representation of the path. */ + public static String getStringURI(IPath path) { + return Arrays.stream(path.segments()) + .map(segment -> URI.encodeSegment(segment, false)) + .collect(Collectors.joining(PATH_SEPARATOR)); + } + } |