1 11 package org.eclipse.ant.core; 12 13 import java.net.URL ; 14 import java.net.URLClassLoader ; 15 import java.util.Arrays ; 16 import java.util.List ; 17 18 import org.eclipse.ant.internal.core.AntClassLoader; 19 import org.eclipse.ant.internal.core.AntCoreUtil; 20 import org.eclipse.core.runtime.IConfigurationElement; 21 import org.eclipse.core.runtime.IExtensionPoint; 22 import org.eclipse.core.runtime.IStatus; 23 import org.eclipse.core.runtime.Platform; 24 import org.eclipse.core.runtime.Plugin; 25 import org.eclipse.core.runtime.Status; 26 import org.osgi.framework.BundleContext; 27 28 32 public class AntCorePlugin extends Plugin { 33 34 38 public static final int INTERNAL_ERROR = 120; 39 40 43 private static AntCorePlugin plugin; 44 45 48 private AntCorePreferences preferences; 49 50 54 public static final String PI_ANTCORE = "org.eclipse.ant.core"; 56 60 public static final String PT_TASKS = "antTasks"; 62 66 public static final String PT_EXTRA_CLASSPATH = "extraClasspathEntries"; 68 72 public static final String PT_TYPES = "antTypes"; 74 80 public static final String PT_PROPERTIES = "antProperties"; 82 88 public static final String ANT_BUILDFILE_CONTENT_TYPE = PI_ANTCORE + ".antBuildFile"; 90 94 public static final String CLASS = "class"; 96 100 public static final String NAME = "name"; 102 106 public static final String LIBRARY = "library"; 108 113 public static final String HEADLESS = "headless"; 115 120 public static final String ECLIPSE_RUNTIME = "eclipseRuntime"; 122 127 public static final String URI = "uri"; 129 134 public static final String VALUE = "value"; 136 142 public static final String ECLIPSE_PROGRESS_MONITOR = "eclipse.progress.monitor"; 144 148 public static final int ERROR_RUNNING_BUILD = 1; 149 150 154 public static final int ERROR_MALFORMED_URL = 2; 155 156 160 public static final int ERROR_LIBRARY_NOT_SPECIFIED = 3; 161 162 172 public AntCorePlugin() { 173 plugin = this; 174 } 175 176 180 public void stop(BundleContext context) throws Exception { 181 super.stop(context); 182 AntCoreUtil.setBundleContext(null); 183 if (preferences != null) { 184 savePluginPreferences(); 185 } 186 } 187 188 192 public void start(BundleContext context) throws Exception { 193 super.start(context); 194 AntCoreUtil.setBundleContext(context); 195 } 196 197 203 private List extractExtensions(String pointName) { 204 IExtensionPoint extensionPoint= Platform.getExtensionRegistry().getExtensionPoint(AntCorePlugin.PI_ANTCORE, pointName); 205 if (extensionPoint == null) { 206 return null; 207 } 208 IConfigurationElement[] extensions = extensionPoint.getConfigurationElements(); 209 return Arrays.asList(extensions); 210 } 211 212 217 public AntCorePreferences getPreferences() { 218 if (preferences == null) { 219 preferences = new AntCorePreferences(extractExtensions(PT_TASKS), extractExtensions(PT_EXTRA_CLASSPATH), extractExtensions(PT_TYPES), extractExtensions(PT_PROPERTIES), false); 220 } 221 return preferences; 222 } 223 224 231 public void setRunningHeadless(boolean headless) { 232 preferences = new AntCorePreferences(extractExtensions(PT_TASKS), extractExtensions(PT_EXTRA_CLASSPATH), extractExtensions(PT_TYPES), extractExtensions(PT_PROPERTIES), headless); 233 } 234 235 240 public static AntCorePlugin getPlugin() { 241 return plugin; 242 } 243 244 249 public ClassLoader getNewClassLoader() { 250 AntCorePreferences corePreferences = getPreferences(); 251 return getNewClassLoader(false, corePreferences.getURLs()); 252 } 253 254 260 public URLClassLoader getNewClassLoader(URL [] urls) { 261 return getNewClassLoader(false, urls); 262 } 263 264 272 public ClassLoader getNewClassLoader(boolean allowLoading) { 273 AntCorePreferences corePreferences = getPreferences(); 274 URL [] urls = corePreferences.getURLs(); 275 return getNewClassLoader(allowLoading, urls); 276 } 277 278 288 public URLClassLoader getNewClassLoader(boolean allowLoading, URL [] urls) { 289 AntCorePreferences corePreferences = getPreferences(); 290 ClassLoader [] pluginLoaders = corePreferences.getPluginClassLoaders(); 291 AntClassLoader loader= new AntClassLoader(urls, pluginLoaders); 292 loader.allowPluginClassLoadersToLoadAnt(allowLoading); 293 return loader; 294 } 295 296 302 public static void log(Throwable t) { 303 IStatus status= new Status(IStatus.ERROR, PI_ANTCORE, INTERNAL_ERROR, "Error logged from Ant Core: ", t); getPlugin().getLog().log(status); 305 } 306 } 307 | Popular Tags |