1 11 package org.eclipse.jdt.internal.apt.pluggable.core; 12 13 import java.text.SimpleDateFormat ; 14 import java.util.Date ; 15 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.core.runtime.Platform; 18 import org.eclipse.core.runtime.Plugin; 19 import org.eclipse.core.runtime.Status; 20 import org.osgi.framework.BundleContext; 21 22 28 public class Apt6Plugin extends Plugin { 29 30 private static final SimpleDateFormat TRACE_DATE_FORMAT = new SimpleDateFormat ("HH:mm:ss.SSS"); 32 public static final String PLUGIN_ID = "org.eclipse.jdt.apt.pluggable.core"; 34 37 public static final int STATUS_EXCEPTION = 1; 38 39 public static boolean DEBUG = false; 41 public final static String APT_DEBUG_OPTION = Apt6Plugin.PLUGIN_ID + "/debug"; 43 private static Apt6Plugin thePlugin = null; 45 public Apt6Plugin() { 46 } 47 48 @Override 49 public void start(BundleContext context) throws Exception { 50 super.start(context); 51 thePlugin = this; 52 initDebugTracing(); 53 } 54 55 private void initDebugTracing() { 56 String option = Platform.getDebugOption(APT_DEBUG_OPTION); 57 if (option != null) { 58 DEBUG = option.equalsIgnoreCase("true"); } 60 } 61 62 public static Apt6Plugin getPlugin() { 63 return thePlugin; 64 } 65 66 70 public static void log(IStatus status) { 71 thePlugin.getLog().log(status); 72 } 73 74 78 public static void log(Throwable e, String message) { 79 log(new Status(IStatus.ERROR, PLUGIN_ID, STATUS_EXCEPTION, message, e)); 80 } 81 82 86 public static void logWarning(Throwable e, String message) { 87 log(createWarningStatus(e, message)); 88 } 89 90 94 public static Status createStatus(Throwable e, String message) { 95 return new Status(IStatus.ERROR, PLUGIN_ID, STATUS_EXCEPTION, message, e); 96 } 97 98 102 public static Status createWarningStatus(Throwable e, String message) { 103 return new Status(IStatus.WARNING, PLUGIN_ID, STATUS_EXCEPTION, message, e); 104 } 105 106 110 public static Status createInfoStatus(Throwable e, String message) { 111 return new Status(IStatus.INFO, PLUGIN_ID, STATUS_EXCEPTION, message, e); 112 } 113 114 public static void trace(final String msg) { 115 if (DEBUG) { 116 StringBuffer sb = new StringBuffer (); 117 sb.append('['); 118 synchronized (TRACE_DATE_FORMAT) { 120 sb.append(TRACE_DATE_FORMAT.format(new Date ())); 121 } 122 sb.append('-'); 123 String threadName = Thread.currentThread().getName(); 125 int dot = threadName.lastIndexOf('.'); 126 if (dot < 0) { 127 sb.append(threadName); 128 } else { 129 sb.append(threadName.substring(dot + 1)); 130 } 131 sb.append(']'); 132 sb.append(msg); 133 System.out.println(sb); 134 } 135 } 136 137 } 138 | Popular Tags |