1 11 package org.eclipse.update.internal.core; 12 13 import java.io.File ; 14 import java.io.IOException ; 15 import java.net.URL ; 16 17 import org.eclipse.core.net.proxy.IProxyService; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.core.runtime.Platform; 21 import org.eclipse.core.runtime.Plugin; 22 import org.eclipse.osgi.internal.provisional.verifier.CertificateVerifierFactory; 23 import org.eclipse.update.configuration.IInstallConfiguration; 24 import org.eclipse.update.configurator.ConfiguratorUtils; 25 import org.eclipse.update.configurator.IPlatformConfiguration; 26 import org.eclipse.update.core.IFeature; 27 import org.eclipse.update.core.IImport; 28 import org.eclipse.update.core.JarContentReference; 29 import org.eclipse.update.core.Utilities; 30 import org.eclipse.update.internal.core.connection.ConnectionThreadManagerFactory; 31 import org.osgi.framework.BundleContext; 32 import org.osgi.service.packageadmin.PackageAdmin; 33 import org.osgi.util.tracker.ServiceTracker; 34 35 38 public class UpdateCore extends Plugin { 39 40 public static boolean DEBUG; 42 public static boolean DEBUG_SHOW_INSTALL; 43 public static boolean DEBUG_SHOW_PARSING; 44 public static boolean DEBUG_SHOW_WARNINGS; 45 public static boolean DEBUG_SHOW_CONFIGURATION; 46 public static boolean DEBUG_SHOW_TYPE; 47 public static boolean DEBUG_SHOW_WEB; 48 public static boolean DEBUG_SHOW_IHANDLER; 49 public static boolean DEBUG_SHOW_RECONCILER; 50 51 private static final String PREFIX = "org.eclipse.update.core"; public static final String P_HISTORY_SIZE = PREFIX + ".historySize"; public static final String P_CHECK_SIGNATURE = PREFIX + ".checkSignature"; public static final String P_AUTOMATICALLY_CHOOSE_MIRROR = PREFIX + ".automaticallyChooseMirror"; public static final String P_UPDATE_VERSIONS = PREFIX + ".updateVersions"; public static final String EQUIVALENT_VALUE = "equivalent"; public static final String COMPATIBLE_VALUE = "compatible"; 59 public static int DEFAULT_HISTORY = 100; 61 private static UpdateCore plugin; 63 64 private static UpdateManagerLogWriter log; 66 private static final String LOG_FILE="install.log"; 68 private BundleContext context; 70 private ServiceTracker pkgAdminTracker; 71 private ServiceTracker verifierFactoryTracker; 72 private ServiceTracker proxyTracker; 73 74 private UpdateSession updateSession = null; 76 77 80 public UpdateCore() { 81 plugin = this; 82 } 83 84 85 88 public static UpdateCore getPlugin() { 89 return plugin; 90 } 91 92 93 private boolean getBooleanDebugOption(String flag, boolean dflt) { 94 String result = Platform.getDebugOption(flag); 95 if (result == null) 96 return dflt; 97 else 98 return result.trim().equalsIgnoreCase("true"); } 100 101 104 public static void debug(String s) { 105 StringBuffer msg = new StringBuffer (); 106 msg.append(getPlugin().toString()); 107 msg.append("^"); msg.append(Integer.toHexString(Thread.currentThread().hashCode())); 109 msg.append(" "); msg.append(s); 111 System.out.println(msg.toString()); 112 } 113 114 117 public static void warn(String s) { 118 if (DEBUG && DEBUG_SHOW_WARNINGS) { 119 if (s!=null){ 120 s="WARNING: "+s; } 122 log(s, null); 123 } 124 } 125 126 133 public static void warn(String s, Throwable e) { 134 if (DEBUG && DEBUG_SHOW_WARNINGS){ 135 if (s!=null){ 136 s="UPDATE MANAGER INFO: "+s; } 138 log(s,e); 139 } 140 } 141 142 145 public static void log(IStatus status){ 146 UpdateCore.getPlugin().getLog().log(status); 147 } 148 149 152 public static void log(Throwable e){ 153 log("",e); } 155 156 159 public static void log(String msg, Throwable e){ 160 IStatus status = null; 161 if (e instanceof CoreException) 162 status = ((CoreException)e).getStatus(); 163 else 164 status = Utilities.newCoreException(msg,e).getStatus(); 165 if (status!=null) 166 log(status); 167 } 168 172 public static void log(IInstallConfiguration newConfiguration) { 173 if (log!=null) 174 log.log(newConfiguration); 175 } 176 177 180 private static File getInstallLogFile() throws IOException { 181 182 IPlatformConfiguration config = ConfiguratorUtils.getCurrentPlatformConfiguration(); 183 URL configurationLocation = config.getConfigurationLocation(); 184 if (configurationLocation==null){ 185 warn("Unable to retrieve location for update manager log file"); return null; 187 } 188 File updateStateLocation = null; 190 191 if ("file".equalsIgnoreCase(configurationLocation.getProtocol())) { File path = new File (configurationLocation.getFile()); 193 updateStateLocation = new File (path.getParentFile(), LOG_FILE); 194 } 195 return updateStateLocation; 196 } 197 198 211 212 213 216 public static boolean isPatch(IFeature candidate) { 217 IImport[] imports = candidate.getImports(); 218 219 for (int i = 0; i < imports.length; i++) { 220 IImport iimport = imports[i]; 221 if (iimport.isPatch()) 222 return true; 223 } 224 return false; 225 } 226 227 230 public void start(BundleContext context) throws Exception { 231 super.start(context); 232 this.context = context; 233 234 DEBUG = getBooleanDebugOption("org.eclipse.update.core/debug", false); 236 if (DEBUG) { 237 DEBUG_SHOW_WARNINGS = getBooleanDebugOption("org.eclipse.update.core/debug/warning", false); DEBUG_SHOW_PARSING = getBooleanDebugOption("org.eclipse.update.core/debug/parsing", false); DEBUG_SHOW_INSTALL = getBooleanDebugOption("org.eclipse.update.core/debug/install", false); DEBUG_SHOW_CONFIGURATION = getBooleanDebugOption("org.eclipse.update.core/debug/configuration", false); DEBUG_SHOW_TYPE = getBooleanDebugOption("org.eclipse.update.core/debug/type", false); DEBUG_SHOW_WEB = getBooleanDebugOption("org.eclipse.update.core/debug/web", false); DEBUG_SHOW_IHANDLER = getBooleanDebugOption("org.eclipse.update.core/debug/installhandler", false); DEBUG_SHOW_RECONCILER = getBooleanDebugOption("org.eclipse.update.core/debug/reconciler", false); } 246 247 try { 249 File logFile = getInstallLogFile(); 250 if (logFile!=null) 251 log = new UpdateManagerLogWriter(logFile); 252 } catch (IOException e){ 253 warn("",e); } 255 } 256 259 public void stop(BundleContext context) throws Exception { 260 super.stop(context); 261 262 JarContentReference.shutdown(); Utilities.shutdown(); if (log!=null) 265 log.shutdown(); 266 267 ConnectionThreadManagerFactory.getConnectionManager().shutdown(); 268 269 270 this.context = null; 271 if (pkgAdminTracker != null) { 272 pkgAdminTracker.close(); 273 pkgAdminTracker = null; 274 } 275 if (verifierFactoryTracker != null) { 276 verifierFactoryTracker.close(); 277 verifierFactoryTracker = null; 278 } 279 if (proxyTracker != null) { 280 proxyTracker.close(); 281 proxyTracker = null; 282 } 283 } 284 285 BundleContext getBundleContext() { 286 return context; 287 } 288 289 PackageAdmin getPackageAdmin() { 290 if (pkgAdminTracker == null) { 291 pkgAdminTracker = new ServiceTracker(context, PackageAdmin.class.getName(), null); 292 pkgAdminTracker.open(); 293 } 294 return (PackageAdmin)pkgAdminTracker.getService(); 295 } 296 297 public IProxyService getProxyService() { 298 if (proxyTracker == null) { 299 proxyTracker=new ServiceTracker(getBundle().getBundleContext(), 300 IProxyService.class.getName(), null); 301 proxyTracker.open(); 302 } 303 return (IProxyService)proxyTracker.getService(); 304 } 305 306 307 public CertificateVerifierFactory getVerifierFactory() { 308 if (verifierFactoryTracker == null) { 309 verifierFactoryTracker = new ServiceTracker(context, CertificateVerifierFactory.class.getName(), null); 310 verifierFactoryTracker.open(); 311 } 312 return (CertificateVerifierFactory)verifierFactoryTracker.getService(); 313 } 314 315 public UpdateSession getUpdateSession() { 316 synchronized(UpdateSession.class) { 317 if (updateSession == null) { 318 updateSession = new UpdateSession(); 319 } 320 } 321 return updateSession; 322 } 323 } 324 | Popular Tags |