-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add EMF-packages declared in MANIFEST.MF to EPackage-registry too #52
base: master
Are you sure you want to change the base?
Add EMF-packages declared in MANIFEST.MF to EPackage-registry too #52
Conversation
Hi Hannes, for a handling of EMF in a OSGi environment without a need of an extension registry or Equinox as framework we already have that: https://github.com/geckoprojects-org/org.gecko.emf It is a service based EPackage- and ResourceFactory -Registry, where you can inject Epackages as service as well as a ResourceSet. This project is currently in move to the new Eclipse Fennec project. It also contains an extender, that reads models described in the Manifest. I dont know from scratch, if we already support the capabilities, but its not that hard to add this feature. Maybe this goes in a similar direction? |
Hi Mark, Would adding this directly to EMF be a benefit for Gecko-EMF/Eclipse Fennec or could it even be harmful? |
eb6e412
to
670203e
Compare
In general I support this idea. We have it in https://github.com/geckoprojects-org/org.gecko.emf/tree/main/org.gecko.emf.osgi.extender I suggest looking into the extension registry implementation. When does it start and track bundles for plugin.xml's. I believe they use the resolved state. In general we should't have to care about start ordering. Just as a comment |
670203e
to
853a828
Compare
The tracker and automatic registration can only be active globally or not at all. At least I cannot tell how to selectively disabled it. Of course one can simply not have the corresponding capabilities in the MANIFEST.MF respectively not let EMF generate it. Regarding dynamics: The Eclipse extension registry is static. I have to admit I cannot tell what happens if bundles are installed into or uninstalled from an Equinox runtime at a later point of time. At least I haven't found any code in EMF that removes any registered packages from the registry when a bundle is 'removed'. ... at least until now. The new Tracker, will also remove registrations of Btw. @maho7791 can you tell if a bundle gets a new classloader when it's stopped and (re-)started or only if it is uninstalled and (re-)installed? Since a new Classloader means a new class object I think the registration should be removed in that case, also to avoid keeping references to 'dead' classloaders or bundles.
Yes, absolutely. Agree and the tracker tracking all bundles in state
|
Lines 89 to 98 in 4fb5fe9
|
You have to assume that you get a new Classloader, as some rewiring might happen, which may result in a new classloader. |
Globally deactivation is fine as well.
A bundle gets a new Classloader instance when it reaches the resolved state. Stopping and starting a bundle may cause a re-resolve, So there might be a new Classloader instance after a new resolve was triggered. In any case the BundleContext will get a new instance after stopping and starting again.
I just want you to keep in mind, not to end up in situations where some consumers of packages cannot find them, because they are not already registered. When you use the static accessors for generated factories like PersonFactory.eInstance.createPerson(), the EPackage is registered automatically into the static EPackageRegistry. This is done by the generated code. If you want to load an EObject using ResourceSet.getEObject(URI.createURI("/tmp/test.person") you will sooner or later need the ResourceFactory for file extension person and the PersonPackage from the corresponding registries. If they aret not already registered, the load will fail. This means, this way of registration of the EPackages can cause start order problems. You can avoid this with starting o.e.e.ecore a early as possible, in the best case before any code can call e.g. ResourceSet.getEObject. But we dont want that. Assume you have bundles in that order: A, Ecore, M1 with model 1, M2 with model person. Let A call 'ResourceSet.getEObject(URI.createURI("/tmp/test.person")' whereas bundle M2 contains the person.ecore. What happens:
This cannot happen with the Extension Registry. Because any access to it is based on the IExtensionRegistryService. Now the same with the extension registry:
After some thinking, It feels like the BundleTracker is not the way to solve it. We can use it with our approach, because, we can delay an ResourceSet injection into an DS component until the requested EPackage is registered. |
853a828
to
b5d7425
Compare
b5d7425
to
8c5da88
Compare
I actually think that it should work well by default without interfering negatively without the need to disable it at all.
If we would do it absolutely correct we would probably have to remove and re-register all
I have checked the behavior of |
This is adds a OSGi Bundle-Tracker that adds the EMF-packages declared in a MANIFEST.MF as provides OSGi capabilities (which EMF can already generated) to the EPackage.Registry automatically at runtime. This makes it obsolete to declared
EPackages
in theplugin.xml
(although the latter has precedence for compatibility).Outside of a OSGi runtime the corresponding header of all MANIFEST.MF files discoverable by the provided classloader are read 'manually' to ensure EPackages are then registered too.
@merks that's the change I talked to about before Christmas and you said that @juergen-albert and @maho7791 are porbably interested in this as well.
This is currently a draft that needs more testing, although the part for OSGi runtimes has already been tested in our application, and ideally also tests. Ed, can you recommend a place for that?