Skip to content

Commit b521136

Browse files
OSGi Service as Global EPackageRegistry
The default EPackage Registry can be overwritten in mutlple ways (System property or ExtensionPoint). With this, if non of the other mechanisms apply, there now can be a service that acts as the static Registry. Signed-off-by: Juergen Albert <[email protected]>
1 parent 8c230d4 commit b521136

File tree

4 files changed

+514
-5
lines changed

4 files changed

+514
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ 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

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: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
import org.eclipse.emf.ecore.resource.URIConverter;
5858
import org.osgi.framework.BundleActivator;
5959
import org.osgi.framework.BundleContext;
60+
import org.osgi.util.tracker.ServiceTracker;
61+
import org.osgi.util.tracker.ServiceTrackerCustomizer;
6062

6163

6264
/**
@@ -586,13 +588,18 @@ public static Map<String, URI> getEPackageNsURIToDynamicModelLocationMap(boolean
586588
*/
587589
static public class Implementation extends EclipsePlugin
588590
{
589-
/**
591+
592+
593+
private PlainOSGiBundleActivator plainOSGiBundleActivator;
594+
595+
/**
590596
* Creates the singleton instance.
591597
*/
592598
public Implementation()
593599
{
594600
super();
595601
plugin = this;
602+
plainOSGiBundleActivator = new PlainOSGiBundleActivator();
596603
}
597604

598605
/**
@@ -656,10 +663,60 @@ public Implementation()
656663
public void start(BundleContext context) throws Exception
657664
{
658665
super.start(context);
659-
ExtensionProcessor.internalProcessExtensions();
666+
try {
667+
ExtensionProcessor.internalProcessExtensions();
668+
} catch (NoClassDefFoundError e) {
669+
// If EMF runs in a non Equinox OSGi Framework, it occasionally runs in some NoClassDefFoundError Exceptions, that can safely be ignored.
670+
}
671+
plainOSGiBundleActivator.start(context);
672+
}
673+
674+
/*
675+
* (non-Javadoc)
676+
* @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
677+
*/
678+
@Override
679+
public void stop(BundleContext context) throws Exception {
680+
super.stop(context);
681+
plainOSGiBundleActivator.stop(context);
682+
}
683+
684+
/**
685+
* In Case we are not running in Eclipse, this BundleActivator will be used
686+
* @since 2.40
687+
*/
688+
public static class PlainOSGiBundleActivator implements BundleActivator {
689+
690+
private ServiceTracker<EPackage.Registry, Object> osgiEpackageRegistryTracker = null;
660691

692+
/*
693+
* (non-Javadoc)
694+
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
695+
*/
696+
@SuppressWarnings("unchecked")
697+
@Override
698+
public void start(BundleContext context) throws Exception {
699+
if(getDefaultRegistryImplementation() != null && getDefaultRegistryImplementation() instanceof OSGiDelegatEPackageRegistry)
700+
{
701+
osgiEpackageRegistryTracker = new ServiceTracker<>(context, OSGiDelegatEPackageRegistry.FILTER, (ServiceTrackerCustomizer<EPackage.Registry, Object>) getDefaultRegistryImplementation());
702+
osgiEpackageRegistryTracker.open();
703+
}
661704
}
662705

706+
/*
707+
* (non-Javadoc)
708+
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
709+
*/
710+
@Override
711+
public void stop(BundleContext context) throws Exception {
712+
if(osgiEpackageRegistryTracker != null)
713+
{
714+
osgiEpackageRegistryTracker.close();
715+
}
716+
}
717+
718+
}
719+
663720
/**
664721
* @since 2.10
665722
*/
@@ -668,7 +725,12 @@ public static final class Activator extends EMFPlugin.OSGiDelegatingBundleActiva
668725
@Override
669726
protected BundleActivator createBundle()
670727
{
671-
return new Implementation();
728+
try
729+
{
730+
return new Implementation();
731+
} catch (Throwable t) {
732+
return new PlainOSGiBundleActivator();
733+
}
672734
}
673735
}
674736
}
@@ -1098,6 +1160,11 @@ public String getSymbolicName()
10981160
*/
10991161
public static EPackage.Registry getDefaultRegistryImplementation()
11001162
{
1163+
if(defaultRegistryImplementation == null && EMFPlugin.IS_OSGI_RUNNING)
1164+
{
1165+
OSGiDelegatEPackageRegistry delegatorRegsitry = new OSGiDelegatEPackageRegistry();
1166+
defaultRegistryImplementation = delegatorRegsitry;
1167+
}
11011168
return defaultRegistryImplementation;
11021169
}
11031170

0 commit comments

Comments
 (0)