Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Merks2023-02-24 11:22:05 +0000
committerEd Merks2023-02-24 11:22:05 +0000
commitc684ed1637394ce3b2fb87a18e19f2fe72c90dfe (patch)
tree99c4b74ea488514b9a5af7c8f168035d0f68be16 /plugins/org.eclipse.emf.ecore/src/org/eclipse/emf
parent6c0fa3abe600d366e1e4ead6aa583aa46e6c0574 (diff)
downloadorg.eclipse.emf-c684ed1637394ce3b2fb87a18e19f2fe72c90dfe.tar.gz
org.eclipse.emf-c684ed1637394ce3b2fb87a18e19f2fe72c90dfe.tar.xz
org.eclipse.emf-c684ed1637394ce3b2fb87a18e19f2fe72c90dfe.zip
[581496] Improve support for locating models registered via
dyanmic_package registrations
Diffstat (limited to 'plugins/org.eclipse.emf.ecore/src/org/eclipse/emf')
-rw-r--r--plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/plugin/DynamicPackageRegistryReader.java35
-rw-r--r--plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/plugin/EcorePlugin.java68
2 files changed, 94 insertions, 9 deletions
diff --git a/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/plugin/DynamicPackageRegistryReader.java b/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/plugin/DynamicPackageRegistryReader.java
index e5f8c7728..0c3b7469f 100644
--- a/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/plugin/DynamicPackageRegistryReader.java
+++ b/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/plugin/DynamicPackageRegistryReader.java
@@ -11,9 +11,12 @@
package org.eclipse.emf.ecore.plugin;
+import java.util.Map;
+
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.RegistryFactory;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
/**
@@ -27,6 +30,11 @@ class DynamicPackageRegistryReader extends RegistryReader
static final String ATT_URI = "uri";
static final String ATT_LOCATION = "location";
+ /**
+ * @since 2.33
+ */
+ protected Map<String, URI> ePackageNsURIToDynamicModelLocationMap;
+
public DynamicPackageRegistryReader()
{
super
@@ -35,6 +43,15 @@ class DynamicPackageRegistryReader extends RegistryReader
EcorePlugin.DYNAMIC_PACKAGE_PPID);
}
+ /**
+ * @since 2.33
+ */
+ public DynamicPackageRegistryReader(Map<String, URI> ePackageNsURIToDynamicModelLocationMap)
+ {
+ this();
+ this.ePackageNsURIToDynamicModelLocationMap = ePackageNsURIToDynamicModelLocationMap;
+ }
+
@Override
protected boolean readElement(IConfigurationElement element, boolean add)
{
@@ -58,12 +75,28 @@ class DynamicPackageRegistryReader extends RegistryReader
EcorePlugin.INSTANCE.log
("Both '" + descriptor.element.getContributor().getName() + "' and '" + element.getContributor().getName() + "' register a package for '" + packageURI + "'");
}
-
+ if (ePackageNsURIToDynamicModelLocationMap != null)
+ {
+ String dynamicModel = element.getAttribute(ATT_LOCATION);
+ if (dynamicModel != null)
+ {
+ URI dynamicModelURI = URI.createURI(dynamicModel);
+ if (dynamicModelURI.isRelative())
+ {
+ dynamicModelURI = URI.createPlatformPluginURI(element.getDeclaringExtension().getContributor().getName() + "/" + dynamicModel, true);
+ }
+ ePackageNsURIToDynamicModelLocationMap.put(packageURI, dynamicModelURI);
+ }
+ }
return true;
}
else
{
EPackage.Registry.INSTANCE.remove(packageURI);
+ if (ePackageNsURIToDynamicModelLocationMap != null)
+ {
+ ePackageNsURIToDynamicModelLocationMap.remove(packageURI);
+ }
return true;
}
}
diff --git a/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/plugin/EcorePlugin.java b/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/plugin/EcorePlugin.java
index 165412140..c3af32b1b 100644
--- a/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/plugin/EcorePlugin.java
+++ b/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/plugin/EcorePlugin.java
@@ -584,6 +584,42 @@ public class EcorePlugin extends EMFPlugin
}
return result;
}
+
+ /**
+ * Returns a map from {@link EPackage#getNsURI() package namespace URI} (represented as a String)
+ * to the location of the dynamic model for the package (represented as a {@link URI URI})
+ * for either the target platform or the environment itself.
+ * If there is no target platform, i.e., if the PDE is not installed, it defaults back to the environment.
+ * It's generally expected that an application using these URIs will also {@link URIConverter#getURIMap() register} the mappings returned by {@link #computePlatformURIMap(boolean)}.
+ * @param targetPlatform whether to get locations for the target platform or for the environment itself; the former is preferred.
+ * @return a map from package namespace to dynamic model location.
+ * @see #computePlatformURIMap(boolean)
+ * @since 2.33
+ */
+ public static Map<String, URI> getEPackageNsURIToDynamicModelLocationMap(boolean targetPlatform)
+ {
+ if (!targetPlatform || !IS_RESOURCES_BUNDLE_AVAILABLE || !PDEHelper.IS_PDE_BUNDLE_AVAILABLE)
+ {
+ if (ePackageNsURIToDynamicModelLocationMap == null)
+ {
+ ePackageNsURIToDynamicModelLocationMap = new HashMap<String, URI>();
+ }
+ return ePackageNsURIToDynamicModelLocationMap;
+ }
+ else
+ {
+ Map<String, URI> nsURIMap = new HashMap<String, URI>();
+ try
+ {
+ PDEHelper.computeModels(null, null, nsURIMap);
+ }
+ catch (Exception exception)
+ {
+ INSTANCE.log(exception);
+ }
+ return nsURIMap;
+ }
+ }
/**
* The platform resource map.
@@ -593,10 +629,16 @@ public class EcorePlugin extends EMFPlugin
/**
* The map from package namespace URIs to the location of the GenModel for that package.
- * @see #getPlatformResourceMap
+ * @see #getEPackageNsURIToGenModelLocationMap(boolean)
*/
private static Map<String, URI> ePackageNsURIToGenModelLocationMap;
+ /**
+ * The map from package namespace URIs to the location of the GenModel for that package.
+ * @see #getEPackageNsURIToDynamicModelLocationMap(boolean)
+ */
+ private static Map<String, URI> ePackageNsURIToDynamicModelLocationMap;
+
/**
* A plugin implementation that handles Ecore plugin registration.
* @see #startup()
@@ -913,7 +955,7 @@ public class EcorePlugin extends EMFPlugin
}.readRegistry();
new GeneratedPackageRegistryReader(getEPackageNsURIToGenModelLocationMap(false)).readRegistry();
- new DynamicPackageRegistryReader().readRegistry();
+ new DynamicPackageRegistryReader(getEPackageNsURIToDynamicModelLocationMap(false)).readRegistry();
new FactoryOverrideRegistryReader().readRegistry();
new ExtensionParserRegistryReader().readRegistry();
new ProtocolParserRegistryReader().readRegistry();
@@ -1171,7 +1213,12 @@ public class EcorePlugin extends EMFPlugin
IS_PDE_BUNDLE_AVAILABLE = isPDEBundleAvailable && !"true".equals(System.getProperty("org.eclipse.emf.common.CommonPlugin.doNotUsePDE"));
}
- private static void computeModels(Map<URI, URI> pluginMap, Map<String, URI> nsURIMap)
+ private static void computeModels(Map<URI, URI> pluginMap, Map<String, URI> nsURIToGenModelLocationMap)
+ {
+ computeModels(pluginMap, nsURIToGenModelLocationMap, null);
+ }
+
+ private static void computeModels(Map<URI, URI> pluginMap, Map<String, URI> nsURIToGenModelLocationMap, Map<String, URI> nsURIToDynamicModelLocationMap)
{
// Cache the workspace for use in the loop.
//
@@ -1273,20 +1320,25 @@ public class EcorePlugin extends EMFPlugin
}
}
- // If we're not computing the nsURI map, we're done with this plugin.
+ // If we're not computing nsURI maps, we're done with this plugin.
//
- if (nsURIMap == null)
+ if (nsURIToGenModelLocationMap == null && nsURIToDynamicModelLocationMap == null)
{
continue LOOP;
}
// Map the nsURI to the logical location URI of the registered GenModel, if we're dealing with a generated package extension point.
//
- // nsURIMap.put(uri.getValue(), logicalLocation.appendSegments(new Path(genModel.getValue()).segments()));
+ if (nsURIToGenModelLocationMap != null && isGenerated)
+ {
+ nsURIToGenModelLocationMap.put(uri, logicalLocation.appendSegments(new Path(modelLocation).segments()));
+ }
+
+ // Map the nsURI to the logical location URI of the registered dynamic model, if we're dealing with a dynamic package extension point.
//
- if (isGenerated)
+ if (nsURIToDynamicModelLocationMap != null && !isGenerated)
{
- nsURIMap.put(uri, logicalLocation.appendSegments(new Path(modelLocation).segments()));
+ nsURIToDynamicModelLocationMap.put(uri, logicalLocation.appendSegments(new Path(modelLocation).segments()));
}
}
}

Back to the top