Bug 78168 Cannot get preferences when running 'headless' (i.e. through Ant)
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>
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaElementAdapterFactory.java
/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.internal.ui;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.ui.IContainmentAdapter;
import org.eclipse.ui.IContributorResourceAdapter;
import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.model.IWorkbenchAdapter;
import org.eclipse.ui.views.properties.FilePropertySource;
import org.eclipse.ui.views.properties.IPropertySource;