Skip to content

Commit 853a828

Browse files
committed
Register EMF-packages declared in MANIFEST.MF in EPackage-registry
if they are not already registered through an Eclipse Extension in a plugin.xml. Add an OSGi Bundle-Tracker that registers the EPackages declared in the MANIFEST.MF of a bundle by reading the provided capabilities in the 'org.eclipse.emf.ecore.generated_package' namespace. EMF can already generate these capabilities as of Bug 581348 [1] The EPackages declared in the MANIFEST are processed after the EPackages potentially declared in a plugin.xml and existing registrations with an equal URI are not overridden to grand registration in plugin.xml files precedence and to ensure backwards compatibility. If EMF is not executed in a OSGi runtime the corresponding header of all MANIFEST.MF files discoverable by the provided classloader are read directly to ensure EPackages are then registered too. [1] - https://bugs.eclipse.org/581348
1 parent 4fb5fe9 commit 853a828

File tree

8 files changed

+299
-25
lines changed

8 files changed

+299
-25
lines changed

features/org.eclipse.emf.ecore-feature/feature.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<feature
33
id="org.eclipse.emf.ecore"
44
label="%featureName"
5-
version="2.39.0.qualifier"
5+
version="2.40.0.qualifier"
66
provider-name="%providerName"
77
license-feature="org.eclipse.emf.license"
88
license-feature-version="2.11.0">

features/org.eclipse.emf.ecore-feature/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<groupId>org.eclipse.emf.features</groupId>
1414
<artifactId>org.eclipse.emf.ecore</artifactId>
15-
<version>2.39.0-SNAPSHOT</version>
15+
<version>2.40.0-SNAPSHOT</version>
1616
<packaging>eclipse-feature</packaging>
1717

1818
</project>

plugins/org.eclipse.emf.codegen.ecore/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.9.0,4.0.0)",
2323
org.eclipse.core.resources;bundle-version="[3.8.0,4.0.0)",
2424
org.eclipse.jdt.core;bundle-version="[3.9.0,4.0.0)",
2525
org.eclipse.jdt.launching;bundle-version="[3.5.0,4.0.0)",
26-
org.eclipse.emf.ecore;bundle-version="[2.38.0,3.0.0)";visibility:=reexport,
26+
org.eclipse.emf.ecore;bundle-version="[2.39.0,3.0.0)";visibility:=reexport,
2727
org.eclipse.emf.codegen;bundle-version="[2.25.0,3.0.0)";visibility:=reexport,
2828
org.eclipse.emf.ecore.xmi;bundle-version="[2.38.0,3.0.0)",
2929
org.eclipse.text;bundle-version="[3.5.0,4.0.0)"

plugins/org.eclipse.emf.ecore.xcore/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Bundle-SymbolicName: org.eclipse.emf.ecore.xcore;singleton:=true
99
Bundle-Activator: org.eclipse.emf.ecore.xcore.XcorePlugin$Implementation
1010
Bundle-ActivationPolicy: lazy
1111
Require-Bundle: org.eclipse.xtext;bundle-version="[2.13.0,3.0.0)";visibility:=reexport,
12-
org.eclipse.emf.ecore;bundle-version="[2.38.0,3.0.0)";visibility:=reexport,
12+
org.eclipse.emf.ecore;bundle-version="[2.39.0,3.0.0)";visibility:=reexport,
1313
org.eclipse.xtext.util;bundle-version="[2.18.0,3.0.0)",
1414
org.antlr.runtime;bundle-version="[3.2.0,3.2.1)",
1515
org.eclipse.xtext.xbase;bundle-version="[2.18.0,3.0.0)";visibility:=reexport,

plugins/org.eclipse.emf.ecore/META-INF/MANIFEST.MF

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.emf.ecore;singleton:=true
5-
Bundle-Version: 2.38.0.qualifier
5+
Bundle-Version: 2.39.0.qualifier
66
Bundle-ClassPath: .
77
Bundle-Activator: org.eclipse.emf.ecore.plugin.EcorePlugin$Implementation$Activator
88
Bundle-Vendor: %providerName
99
Bundle-Localization: plugin
1010
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
11-
Export-Package: org.eclipse.emf.ecore;version="2.38.0",
12-
org.eclipse.emf.ecore.impl;version="2.38.0",
13-
org.eclipse.emf.ecore.plugin;version="2.38.0",
14-
org.eclipse.emf.ecore.resource;version="2.38.0",
15-
org.eclipse.emf.ecore.resource.impl;version="2.38.0",
16-
org.eclipse.emf.ecore.util;version="2.38.0",
17-
org.eclipse.emf.ecore.xml.namespace;version="2.38.0",
18-
org.eclipse.emf.ecore.xml.namespace.impl;version="2.38.0",
19-
org.eclipse.emf.ecore.xml.namespace.util;version="2.38.0",
20-
org.eclipse.emf.ecore.xml.type;version="2.38.0",
21-
org.eclipse.emf.ecore.xml.type.impl;version="2.38.0",
22-
org.eclipse.emf.ecore.xml.type.internal;version="2.38.0",
23-
org.eclipse.emf.ecore.xml.type.util;version="2.38.0"
11+
Export-Package: org.eclipse.emf.ecore;version="2.39.0",
12+
org.eclipse.emf.ecore.impl;version="2.39.0",
13+
org.eclipse.emf.ecore.plugin;version="2.39.0",
14+
org.eclipse.emf.ecore.resource;version="2.39.0",
15+
org.eclipse.emf.ecore.resource.impl;version="2.39.0",
16+
org.eclipse.emf.ecore.util;version="2.39.0",
17+
org.eclipse.emf.ecore.xml.namespace;version="2.39.0",
18+
org.eclipse.emf.ecore.xml.namespace.impl;version="2.39.0",
19+
org.eclipse.emf.ecore.xml.namespace.util;version="2.39.0",
20+
org.eclipse.emf.ecore.xml.type;version="2.39.0",
21+
org.eclipse.emf.ecore.xml.type.impl;version="2.39.0",
22+
org.eclipse.emf.ecore.xml.type.internal;version="2.39.0",
23+
org.eclipse.emf.ecore.xml.type.util;version="2.39.0"
2424
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.9.0,4.0.0)";resolution:=optional;x-installation:=greedy,
25-
org.eclipse.emf.common;bundle-version="[2.40.0,3.0.0)";visibility:=reexport,
25+
org.eclipse.emf.common;bundle-version="[2.41.0,3.0.0)";visibility:=reexport,
2626
org.eclipse.core.resources;bundle-version="[3.8.0,4.0.0)";resolution:=optional
2727
Provide-Capability: org.eclipse.emf.ecore.generated_package;uri="http://www.eclipse.org/emf/2002/Ecore";class=org.eclipse.emf.ecore.EcorePackage;genModel="model/Ecore.genmodel",
2828
org.eclipse.emf.ecore.generated_package;uri="http://www.w3.org/XML/1998/namespace";class=org.eclipse.emf.ecore.xml.namespace.XMLNamespacePackage;genModel="model/XMLNamespace.genmodel",

plugins/org.eclipse.emf.ecore/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<groupId>org.eclipse.emf</groupId>
1414
<artifactId>org.eclipse.emf.ecore</artifactId>
15-
<version>2.38.0-SNAPSHOT</version>
15+
<version>2.39.0-SNAPSHOT</version>
1616
<packaging>eclipse-plugin</packaging>
1717

1818
</project>

plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/plugin/EcorePlugin.java

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.eclipse.emf.ecore.resource.URIConverter;
5858
import org.osgi.framework.BundleActivator;
5959
import org.osgi.framework.BundleContext;
60+
import org.osgi.framework.BundleException;
6061

6162

6263
/**
@@ -586,6 +587,7 @@ public static Map<String, URI> getEPackageNsURIToDynamicModelLocationMap(boolean
586587
*/
587588
static public class Implementation extends EclipsePlugin
588589
{
590+
private ManifestEPackageTracker ePackageTracker;
589591
/**
590592
* Creates the singleton instance.
591593
*/
@@ -658,6 +660,18 @@ public void start(BundleContext context) throws Exception
658660
super.start(context);
659661
ExtensionProcessor.internalProcessExtensions();
660662

663+
ePackageTracker = new ManifestEPackageTracker(context);
664+
ePackageTracker.open();
665+
}
666+
667+
@Override
668+
public void stop(BundleContext context) throws Exception
669+
{
670+
super.stop(context);
671+
if (ePackageTracker != null)
672+
{
673+
ePackageTracker.close();
674+
}
661675
}
662676

663677
/**
@@ -840,6 +854,8 @@ public IExtensionRegistry getRegistry()
840854
// Process the extension for the registry.
841855
//
842856
ExtensionProcessor.internalProcessExtensions();
857+
858+
ExtensionProcessor.internalProcessManifests(classLoader);
843859
}
844860
}
845861

@@ -910,12 +926,47 @@ protected boolean readElement(IConfigurationElement element)
910926
new ConversionDelegateFactoryRegistryReader().readRegistry();
911927
new AnnotationValidatorRegistryReader().readRegistry();
912928
}
929+
930+
private static void internalProcessManifests(ClassLoader classLoader)
931+
{
932+
if (!IS_OSGI_RUNNING)
933+
{ // not in a OSGi runtime, process raw MANIFEST.MF
934+
try
935+
{
936+
List<URI> manifests = getManifests(classLoader);
937+
for (URI manifest : manifests)
938+
{
939+
ManifestEPackageTracker.registerManifestPackagesIfAbsent(manifest, classLoader);
940+
}
941+
}
942+
catch (IOException | BundleException e)
943+
{
944+
e.printStackTrace(); //TODO: handle
945+
}
946+
}
947+
}
913948
}
914949

915950
/**
916951
* Determine all the available plugin.xml resources.
917952
*/
918953
private static List<URI> getPluginXMLs(ClassLoader classLoader)
954+
{
955+
return getClasspathResource(classLoader, "plugin.xml");
956+
}
957+
958+
/**
959+
* Determine all the available {@code META-INF/MANIFEST.MF} resources.
960+
*/
961+
private static List<URI> getManifests(ClassLoader classLoader)
962+
{
963+
return getClasspathResource(classLoader, "META-INF/MANIFEST.MF");
964+
}
965+
966+
/**
967+
* Determine all the available plugin.xml resources.
968+
*/
969+
private static List<URI> getClasspathResource(ClassLoader classLoader, String resourcePath)
919970
{
920971
List<URI> result = new ArrayList<URI>();
921972

@@ -958,13 +1009,13 @@ private static List<URI> getPluginXMLs(ClassLoader classLoader)
9581009
{
9591010
// Determine if there is a plugin.xml at the root of the folder.
9601011
//
961-
File pluginXML = new File(file, "plugin.xml");
1012+
File pluginXML = new File(file, resourcePath);
9621013
if (!pluginXML.exists())
9631014
{
9641015
// If not, check if there is one in the parent folder.
9651016
//
9661017
File parentFile = file.getParentFile();
967-
pluginXML = new File(parentFile, "plugin.xml");
1018+
pluginXML = new File(parentFile, resourcePath);
9681019
if (pluginXML.isFile())
9691020
{
9701021
// If there is, then we have plugin.xml files that aren't on the classpath.
@@ -975,7 +1026,7 @@ else if (parentFile != null)
9751026
{
9761027
// The parent has a parent, check if there is one in the parent's parent folder.
9771028
//
978-
pluginXML = new File(parentFile.getParentFile(), "plugin.xml");
1029+
pluginXML = new File(parentFile.getParentFile(), resourcePath);
9791030
if (pluginXML.isFile())
9801031
{
9811032
// If there is, then we have plugin.xml files that aren't on the classpath.
@@ -1014,7 +1065,7 @@ else if (file.isFile())
10141065
// Look for a plugin.xml entry...
10151066
//
10161067
jarFile = new JarFile(classpathEntry);
1017-
ZipEntry entry = jarFile.getEntry("plugin.xml");
1068+
ZipEntry entry = jarFile.getEntry(resourcePath);
10181069
if (entry != null)
10191070
{
10201071
// If we find one, create a URI for it.
@@ -1052,7 +1103,7 @@ else if (file.isFile())
10521103
result.clear();
10531104
try
10541105
{
1055-
for (Enumeration<URL> resources = classLoader.getResources("plugin.xml"); resources.hasMoreElements(); )
1106+
for (Enumeration<URL> resources = classLoader.getResources(resourcePath); resources.hasMoreElements(); )
10561107
{
10571108
// Create a URI for each plugin.xml found by the class loader.
10581109
//

0 commit comments

Comments
 (0)