Project: JDT
Bug 78168 Cannot get preferences when running 'headless' (i.e. through Ant)
Reported: 2004-11-09 10:43:19 | Status: verified fixed

I'm a member of the Rational Studio Architect team and have been tasked with ensuring that our transformations can be run through Ant in headless mode. I'm having a problem with our "Uml to Java" transform because it wants to use the code 'templates' defined in the JDT's prefstore when performing its code generation (reasonable, IMO). It does this by trying to use the JDT's 'CodeGeneration' class. However, the jdt.ui plugin (the owner of CodeGeneration class) fails to load. The reason is that the JavaWorkBenchAdapter creates a new instance of the JavaElementImageProvider which has initializer code that does a 'getWorkbench.getSharedImages()' which, through AbstractUIPlugin, calls 'PlatformUI.getWorkbench()' which, in turn, throws an 'IllegalStateException'...we're boned. <soapbox on> BTW, a quick hack shows that out of ALL of eclipse only 4 plugins fail to load in a headless environment: org.eclipse.cdt.debug.ui org.eclipse.cdt.ui org.eclipse.jdt.ui org.eclipse.team.cvs.ui For performance reasons(since plugins load during class instantiations) I'd expect that we'd want the Plugin initialization to be as lightweight as possible. Perhaps changing to a philosophy where ALL plugins (including UI) should at least LOAD headless would not only solve this issue but increase performance as well. Note that in this case we certainly don't need 'shared images' so this initialization is wasted on us. Certainly if we load a UI plugin headless and then attempt to do GUI stuff (i.e. displaying a dialog...) then we shoot ourselves in the foot (at least...;-) and pay the price. <soapbox off>

Files changed in fix:
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaElementAdapterFactory.java