1 11 package org.eclipse.pde.internal; 12 13 import java.io.*; 14 import java.lang.reflect.*; 15 import java.net.*; 16 17 import org.eclipse.core.resources.*; 18 import org.eclipse.core.runtime.*; 19 import org.eclipse.pde.internal.builders.*; 20 import org.osgi.framework.*; 21 22 23 public class PDE extends Plugin { 24 public static final String PLUGIN_ID = "org.eclipse.pde"; 26 public static final String MANIFEST_BUILDER_ID = 27 PLUGIN_ID + "." + "ManifestBuilder"; public static final String SCHEMA_BUILDER_ID = 29 PLUGIN_ID + "." + "SchemaBuilder"; public static final String PLUGIN_NATURE = PLUGIN_ID + "." + "PluginNature"; public static final String FEATURE_NATURE = PLUGIN_ID + "." + "FeatureNature"; public static final String SITE_NATURE = PLUGIN_ID + "." + "UpdateSiteNature"; public static final String FEATURE_BUILDER_ID = 34 PLUGIN_ID + "." + "FeatureBuilder"; public static final String SITE_BUILDER_ID = 36 PLUGIN_ID + "." + "UpdateSiteBuilder"; 38 private static PDE fInstance; 40 41 private BundleContext fBundleContext; 42 43 private FeatureRebuilder fFeatureRebuilder; 44 45 public PDE() { 46 fInstance = this; 47 } 48 public BundleContext getBundleContext(){ 49 return fBundleContext; 50 } 51 54 public void start(BundleContext context) throws Exception { 55 fBundleContext = context; 56 super.start(context); 57 CompilerFlags.initializeDefaults(); 58 fFeatureRebuilder = new FeatureRebuilder(); 59 fFeatureRebuilder.start(); 60 } 61 62 65 public void stop(BundleContext context) throws Exception { 66 fFeatureRebuilder.stop(); 67 fFeatureRebuilder = null; 68 super.stop(context); 69 fInstance = null; 70 fBundleContext = null; 71 } 72 73 public URL getInstallURL() { 74 try { 75 return Platform.resolve(getDefault().getBundle().getEntry("/")); } catch (IOException e) { 77 return null; 78 } 79 } 80 81 public static boolean hasPluginNature(IProject project) { 82 try { 83 return project.hasNature(PLUGIN_NATURE); 84 } catch (CoreException e) { 85 log(e); 86 return false; 87 } 88 } 89 90 public static boolean hasFeatureNature(IProject project) { 91 try { 92 return project.hasNature(FEATURE_NATURE); 93 } catch (CoreException e) { 94 log(e); 95 return false; 96 } 97 } 98 99 public static boolean hasUpdateSiteNature(IProject project) { 100 try { 101 return project.hasNature(SITE_NATURE); 102 } catch (CoreException e) { 103 log(e); 104 return false; 105 } 106 } 107 108 public static PDE getDefault() { 109 return fInstance; 110 } 111 112 public static String getPluginId() { 113 return getDefault().getBundle().getSymbolicName(); 114 } 115 116 public static IWorkspace getWorkspace() { 117 return ResourcesPlugin.getWorkspace(); 118 } 119 120 public static void log(IStatus status) { 121 ResourcesPlugin.getPlugin().getLog().log(status); 122 } 123 124 public static void logErrorMessage(String message) { 125 log(new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, message, null)); 126 } 127 128 public static void logException( 129 Throwable e, 130 final String title, 131 String message) { 132 if (e instanceof InvocationTargetException) { 133 e = ((InvocationTargetException) e).getTargetException(); 134 } 135 IStatus status = null; 136 if (e instanceof CoreException) 137 status = ((CoreException) e).getStatus(); 138 else { 139 if (message == null) 140 message = e.getMessage(); 141 if (message == null) 142 message = e.toString(); 143 status = new Status(IStatus.ERROR, getPluginId(), IStatus.OK, message, e); 144 } 145 ResourcesPlugin.getPlugin().getLog().log(status); 146 } 147 148 public static void logException(Throwable e) { 149 logException(e, null, null); 150 } 151 152 public static void log(Throwable e) { 153 if (e instanceof InvocationTargetException) 154 e = ((InvocationTargetException) e).getTargetException(); 155 IStatus status = null; 156 if (e instanceof CoreException) 157 status = ((CoreException) e).getStatus(); 158 else 159 status = 160 new Status(IStatus.ERROR, getPluginId(), IStatus.OK, e.getMessage(), e); 161 log(status); 162 } 163 } 164 | Popular Tags |