1 11 12 package org.eclipse.core.runtime.internal.adaptor; 13 14 import java.io.*; 15 import java.net.URLConnection ; 16 import java.util.*; 17 import org.eclipse.core.runtime.adaptor.*; 18 import org.eclipse.osgi.baseadaptor.*; 19 import org.eclipse.osgi.baseadaptor.hooks.AdaptorHook; 20 import org.eclipse.osgi.framework.internal.core.Constants; 21 import org.eclipse.osgi.framework.internal.core.FrameworkProperties; 22 import org.eclipse.osgi.framework.log.FrameworkLog; 23 import org.eclipse.osgi.internal.baseadaptor.AdaptorUtil; 24 import org.eclipse.osgi.service.datalocation.Location; 25 import org.osgi.framework.BundleContext; 26 import org.osgi.framework.BundleException; 27 28 public class EclipseLogHook implements HookConfigurator, AdaptorHook { 29 private static final String LOG_EXT = ".log"; BaseAdaptor adaptor; 32 33 public void addHooks(HookRegistry hookRegistry) { 34 hookRegistry.addAdaptorHook(this); 35 } 36 37 public void initialize(BaseAdaptor adaptor) { 38 this.adaptor = adaptor; 39 } 40 41 public void frameworkStart(BundleContext context) throws BundleException { 42 AdaptorUtil.register(FrameworkLog.class.getName(), adaptor.getFrameworkLog(), context); 43 registerPerformanceLog(context); 44 } 45 46 public void frameworkStop(BundleContext context) throws BundleException { 47 } 49 50 public void frameworkStopping(BundleContext context) { 51 53 } 54 55 public void addProperties(Properties properties) { 56 } 58 59 public URLConnection mapLocationToURLConnection(String location) throws IOException { 60 return null; 62 } 63 64 public void handleRuntimeError(Throwable error) { 65 67 } 68 69 public boolean matchDNChain(String pattern, String [] dnChain) { 70 return false; 72 } 73 74 public FrameworkLog createFrameworkLog() { 75 FrameworkLog frameworkLog; 76 String logFileProp = FrameworkProperties.getProperty(EclipseStarter.PROP_LOGFILE); 77 if (logFileProp != null) { 78 frameworkLog = new EclipseLog(new File(logFileProp)); 79 } else { 80 Location location = LocationManager.getConfigurationLocation(); 81 File configAreaDirectory = null; 82 if (location != null) 83 configAreaDirectory = new File(location.getURL().getFile()); 85 86 if (configAreaDirectory != null) { 87 String logFileName = Long.toString(System.currentTimeMillis()) + EclipseLogHook.LOG_EXT; 88 File logFile = new File(configAreaDirectory, logFileName); 89 FrameworkProperties.setProperty(EclipseStarter.PROP_LOGFILE, logFile.getAbsolutePath()); 90 frameworkLog = new EclipseLog(logFile); 91 } else 92 frameworkLog = new EclipseLog(); 93 } 94 if ("true".equals(FrameworkProperties.getProperty(EclipseStarter.PROP_CONSOLE_LOG))) frameworkLog.setConsoleLog(true); 96 return frameworkLog; 97 } 98 99 private void registerPerformanceLog(BundleContext context) { 100 Object service = createPerformanceLog(); 101 String serviceName = FrameworkLog.class.getName(); 102 Hashtable serviceProperties = new Hashtable(7); 103 Dictionary headers = context.getBundle().getHeaders(); 104 105 serviceProperties.put(Constants.SERVICE_VENDOR, headers.get(Constants.BUNDLE_VENDOR)); 106 serviceProperties.put(Constants.SERVICE_RANKING, new Integer (Integer.MIN_VALUE)); 107 serviceProperties.put(Constants.SERVICE_PID, context.getBundle().getBundleId() + '.' + service.getClass().getName()); 108 serviceProperties.put(FrameworkLog.SERVICE_PERFORMANCE, Boolean.TRUE.toString()); 109 110 context.registerService(serviceName, service, serviceProperties); 111 } 112 113 private FrameworkLog createPerformanceLog() { 114 String logFileProp = FrameworkProperties.getProperty(EclipseStarter.PROP_LOGFILE); 115 if (logFileProp != null) { 116 int lastSlash = logFileProp.lastIndexOf(File.separatorChar); 117 if (lastSlash > 0) { 118 String logFile = logFileProp.substring(0, lastSlash + 1) + "performance.log"; return new EclipseLog(new File(logFile)); 120 } 121 } 122 return new EclipseLog(new PrintWriter(System.err)); 124 } 125 } 126 | Popular Tags |