Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 348922 - Can't use a standalone generator if it's deployed in OSGi
Summary: Can't use a standalone generator if it's deployed in OSGi
Status: RESOLVED FIXED
Alias: None
Product: Acceleo
Classification: Modeling
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC All
: P3 normal
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 458751
  Show dependency tree
 
Reported: 2011-06-09 11:44 EDT by Cedric Brun CLA
Modified: 2015-11-30 04:56 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Cedric Brun CLA 2011-06-09 11:44:04 EDT
You might find the title confusing, here is an explanation :

I'm building an RCP headless application, thanks to PDE and Eclipse I can easily export my application as a standalone app containing all the jars I need.

Part of this application is an Acceleo 3.1 *standalone* generator. It depends on really few things then. Problem is, as I'm calling it from a context where Eclipse is running it requires me to have the JDT and PDE and I ends up with NoClassDef.  

Caused by: org.osgi.framework.BundleException: Exception in org.eclipse.acceleo.common.AcceleoCommonPlugin.start() of bundle org.eclipse.acceleo.common.
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:734)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
        at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
        at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:299)
        at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:440)
        at org.eclipse.osgi.internal.loader.BundleLoader.setLazyTrigger(BundleLoader.java:268)
        at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:107)
        ... 26 more
Caused by: java.lang.NoClassDefFoundError: org/eclipse/jdt/core/JavaModelException
        at org.eclipse.acceleo.common.AcceleoCommonPlugin.start(AcceleoCommonPlugin.java:238)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
        ... 32 more

I guess it's not going to the "standalone paths" but the plugin ones. Not sure why JDT is getting loaded during the AcceleoCommonPlugin.start().

may be org.eclipse.emf.common.EMFPlugin.IS_ECLIPSE_RUNNING usages within Acceleo should be changed in something I could hi-jack from the API...
Comment 1 Cedric Brun CLA 2011-06-09 12:19:57 EDT
I tried on a local copy of Acceleo and bypassing the ECLIPSE_IS_RUNNING did work if I also change the acceleo.common Manifest to avoid calling "start" if one of its class is loaded.
Comment 2 Sebastien Revol CLA 2014-09-16 04:35:58 EDT
Hi, 
sorry to reanimate this old bug, but I'm exactly in the situation described here.
We have developped an infrastructure to easily deploy minimal RCPs for standalone batch tools, allowing to keep the benefits of  OSGI/Equinox infrastructure (extension points, EMF related registry initializations etc.).

Our executable are generally something like 5MB and can work without data and user configuration areas (with @none related arguments). 
But if we want to embed acceleo generators, our RCP are immediatly growing to something like 120MB due to JDT core and workbench related dependencies.
Those dependencies are stated as optional, but if we don't embed them in the RCP, we get exceptions like :

classNotfoundException
org.eclipse.jdt.core.JavaModelException cannot be found by acceleo.common_3.4.2....


FYI, EMF proposes a specific vmarg : -Dorg.eclipse.emf.ecore.plugin.EcorePlugin.doNotLoadResourcePlugin=true that allows run an OSGI based standalone application without using workspace related code. 

Do you think you could propose the same approach?

Thanks in advance,
Best regards,

Seb
Comment 3 Cedric Brun CLA 2015-02-02 05:29:31 EST
Hi, and thank you for bumping this bugzilla up with your comment.
That's, indeed, the same problem.

There are different "levels" of support we can get

1- making sure the generator does not depend on JDT/PDE: we could review all the code path and make sure that's effectivement the case *at runtime* (and avoid those NoClassDefFound) but it's always brittle over time. I would go with extracting this code into a specific plugin so that by construction we are sure Acceleo will not call this code. 
2a- avoiding the workspace depenncy at runtime :
we could "guard" the code just like EMF does with org.eclipse.emf.ecore.plugin.EcorePlugin.doNotLoadResourcePlugin=true , and refactor to make sure any code currently made ResourcesPlugin.getWorkspace().getRoot() is replaced with a proper API which takes in account the fact that the workspace might not even be there.  
2b - removing the workspace dependency at build time : Now when I remove the o.e.core.resources dependencies and look at the code, only 4 classes in org.eclipse.acceleo.engine are actually depending on the Workspace API. We could probably go the "cleaner/more sustainable" route and extract those in a specific plugin then with the benefit that "out of the box" using P2 a generator would not bring those extra dependencies (not even the workspace !). We would still depend on core.runtime though but that's probably not a problem. "org.eclipse.acceleo.engine.generation.strategy.WorkspaceAwareStrategy" would have to move into this plugin (which would also remove the optional SWT dependency on o.e.acceleo.engine)

Now, regarding API compatibility. At first sight the changes in o.e.acceleo.common can be made without impacting public API. Moving WorkspaceAwareStrategy is an API break. I would say all the other changes could be made without breaking the API.

All in all, we could propose the same approach EMF does but we could also propose a better one by splitting this code (2b).
Comment 4 Eclipse Genie CLA 2015-04-27 05:23:47 EDT
New Gerrit change created: https://git.eclipse.org/r/46536

WARNING: this patchset contains 3747 new lines of code and may require a Contribution Questionnaire (CQ) if the author is not a committer on the project. Please see:https://wiki.eclipse.org/Project_Management_Infrastructure/Creating_A_Contribution_Questionnaire
Comment 6 Eclipse Genie CLA 2015-08-05 07:52:57 EDT
New Gerrit change created: https://git.eclipse.org/r/53223
Comment 8 Cedric Brun CLA 2015-08-24 11:19:12 EDT
(In reply to Sebastien Revol from comment #2)
> Hi, 
> sorry to reanimate this old bug, but I'm exactly in the situation described
> here.
> We have developped an infrastructure to easily deploy minimal RCPs for
> standalone batch tools, allowing to keep the benefits of  OSGI/Equinox
> infrastructure (extension points, EMF related registry initializations etc.).
> 
> [...]
> 
> Seb

Sebastien, all the changes are in and available through the following upadte-site:

http://download.eclipse.org/acceleo/updates/nightly/streams/3.6.x

Would that be possible to give it a try and confirm the problem is gone for your use case too ?
Comment 9 Cedric Brun CLA 2015-11-30 04:56:33 EST
This has been fixed starting with Acceleo 3.6.2.