1 11 package org.eclipse.core.internal.utils; 12 13 import java.util.Date ; 14 import org.eclipse.core.resources.ResourcesPlugin; 15 import org.eclipse.core.runtime.*; 16 import org.osgi.framework.Bundle; 17 18 public class Policy { 19 public static final boolean buildOnCancel = false; 20 public static boolean DEBUG = false; 22 23 public static boolean DEBUG_AUTO_REFRESH = false; 24 25 public static boolean DEBUG_BUILD_DELTA = false; 27 public static boolean DEBUG_BUILD_FAILURE = false; 28 public static boolean DEBUG_BUILD_INTERRUPT = false; 29 public static boolean DEBUG_BUILD_INVOKING = false; 30 public static boolean DEBUG_BUILD_NEEDED = false; 31 public static boolean DEBUG_BUILD_NEEDED_STACK = false; 32 public static boolean DEBUG_BUILD_STACK = false; 33 34 public static boolean DEBUG_CONTENT_TYPE = false; 35 public static boolean DEBUG_CONTENT_TYPE_CACHE = false; 36 public static boolean DEBUG_HISTORY = false; 37 public static boolean DEBUG_NATURES = false; 38 public static boolean DEBUG_PREFERENCES = false; 39 public static boolean DEBUG_RESTORE = false; 41 public static boolean DEBUG_RESTORE_MARKERS = false; 42 public static boolean DEBUG_RESTORE_MASTERTABLE = false; 43 44 public static boolean DEBUG_RESTORE_METAINFO = false; 45 public static boolean DEBUG_RESTORE_SNAPSHOTS = false; 46 public static boolean DEBUG_RESTORE_SYNCINFO = false; 47 public static boolean DEBUG_RESTORE_TREE = false; 48 public static boolean DEBUG_SAVE = false; 50 public static boolean DEBUG_SAVE_MARKERS = false; 51 public static boolean DEBUG_SAVE_MASTERTABLE = false; 52 53 public static boolean DEBUG_SAVE_METAINFO = false; 54 public static boolean DEBUG_SAVE_SYNCINFO = false; 55 public static boolean DEBUG_SAVE_TREE = false; 56 public static boolean DEBUG_STRINGS = false; 57 public static int endOpWork = 1; 58 public static final long MAX_BUILD_DELAY = 1000; 59 60 public static final long MIN_BUILD_DELAY = 100; 61 public static int opWork = 99; 62 public static final int totalWork = 100; 63 64 static { 65 if (ResourcesPlugin.getPlugin().isDebugging()) { 67 DEBUG = true; 68 String sTrue = Boolean.TRUE.toString(); 69 DEBUG_AUTO_REFRESH = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/refresh")); 71 DEBUG_BUILD_DELTA = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/build/delta")); DEBUG_BUILD_FAILURE = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/build/failure")); DEBUG_BUILD_INVOKING = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/build/invoking")); DEBUG_BUILD_INTERRUPT = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/build/interrupt")); DEBUG_BUILD_NEEDED = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/build/needbuild")); DEBUG_BUILD_NEEDED_STACK = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/build/needbuildstack")); DEBUG_BUILD_STACK = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/build/stacktrace")); 79 DEBUG_CONTENT_TYPE = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/contenttype")); DEBUG_CONTENT_TYPE_CACHE = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/contenttype/cache")); DEBUG_HISTORY = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/history")); DEBUG_NATURES = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/natures")); DEBUG_PREFERENCES = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/preferences")); 85 DEBUG_RESTORE = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/restore")); DEBUG_RESTORE_MARKERS = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/restore/markers")); DEBUG_RESTORE_MASTERTABLE = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/restore/mastertable")); DEBUG_RESTORE_METAINFO = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/restore/metainfo")); DEBUG_RESTORE_SNAPSHOTS = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/restore/snapshots")); DEBUG_RESTORE_SYNCINFO = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/restore/syncinfo")); DEBUG_RESTORE_TREE = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/restore/tree")); 93 DEBUG_SAVE = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/save")); DEBUG_SAVE_MARKERS = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/save/markers")); DEBUG_SAVE_MASTERTABLE = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/save/mastertable")); DEBUG_SAVE_METAINFO = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/save/metainfo")); DEBUG_SAVE_SYNCINFO = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/save/syncinfo")); DEBUG_SAVE_TREE = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/save/tree")); 100 DEBUG_STRINGS = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/strings")); } 102 } 103 104 public static void checkCanceled(IProgressMonitor monitor) { 105 if (monitor.isCanceled()) 106 throw new OperationCanceledException(); 107 } 108 109 113 public static void debug(String message) { 114 StringBuffer buffer = new StringBuffer (); 115 buffer.append(new Date (System.currentTimeMillis())); 116 buffer.append(" - ["); buffer.append(Thread.currentThread().getName()); 118 buffer.append("] "); buffer.append(message); 120 System.out.println(buffer.toString()); 121 } 122 123 public static void log(int severity, String message, Throwable t) { 124 if (message == null) 125 message = ""; log(new Status(severity, ResourcesPlugin.PI_RESOURCES, 1, message, t)); 127 } 128 129 public static void log(IStatus status) { 130 final Bundle bundle = Platform.getBundle(ResourcesPlugin.PI_RESOURCES); 131 if (bundle == null) 132 return; 133 Platform.getLog(bundle).log(status); 134 } 135 136 140 public static void log(Throwable t) { 141 log(IStatus.ERROR, "Internal Error", t); } 143 144 public static IProgressMonitor monitorFor(IProgressMonitor monitor) { 145 return monitor == null ? new NullProgressMonitor() : monitor; 146 } 147 148 public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks) { 149 if (monitor == null) 150 return new NullProgressMonitor(); 151 if (monitor instanceof NullProgressMonitor) 152 return monitor; 153 return new SubProgressMonitor(monitor, ticks); 154 } 155 156 public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks, int style) { 157 if (monitor == null) 158 return new NullProgressMonitor(); 159 if (monitor instanceof NullProgressMonitor) 160 return monitor; 161 return new SubProgressMonitor(monitor, ticks, style); 162 } 163 164 } 165 | Popular Tags |