1 11 package org.eclipse.team.internal.ccvs.core; 12 13 14 import java.io.PrintStream ; 15 import java.lang.reflect.Field ; 16 17 import org.eclipse.core.runtime.*; 18 import org.eclipse.team.internal.core.InfiniteSubProgressMonitor; 19 20 public class Policy { 21 public static PrintStream recorder; 22 23 public static boolean DEBUG_METAFILE_CHANGES = false; 25 public static boolean DEBUG_CVS_PROTOCOL = false; 26 public static boolean DEBUG_THREADING = false; 27 public static boolean DEBUG_DIRTY_CACHING = false; 28 public static boolean DEBUG_SYNC_CHANGE_EVENTS = false; 29 30 static { 31 if (CVSProviderPlugin.getPlugin().isDebugging()) { 33 DEBUG_METAFILE_CHANGES = "true".equalsIgnoreCase(Platform.getDebugOption(CVSProviderPlugin.ID + "/metafiles")); DEBUG_CVS_PROTOCOL = "true".equalsIgnoreCase(Platform.getDebugOption(CVSProviderPlugin.ID + "/cvsprotocol")); DEBUG_THREADING = "true".equalsIgnoreCase(Platform.getDebugOption(CVSProviderPlugin.ID + "/threading")); DEBUG_DIRTY_CACHING = "true".equalsIgnoreCase(Platform.getDebugOption(CVSProviderPlugin.ID + "/dirtycaching")); DEBUG_SYNC_CHANGE_EVENTS = "true".equalsIgnoreCase(Platform.getDebugOption(CVSProviderPlugin.ID + "/syncchangeevents")); } 39 } 40 41 44 public static void checkCanceled(IProgressMonitor monitor) { 45 if (monitor.isCanceled()) 46 throw new OperationCanceledException(); 47 } 48 public static IProgressMonitor monitorFor(IProgressMonitor monitor) { 49 if (monitor == null) 50 return new NullProgressMonitor(); 51 return monitor; 52 } 53 54 public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks) { 55 if (monitor == null) 56 return new NullProgressMonitor(); 57 if (monitor instanceof NullProgressMonitor) 58 return monitor; 59 return new SubProgressMonitor(monitor, ticks); 60 } 61 62 public static IProgressMonitor infiniteSubMonitorFor(IProgressMonitor monitor, int ticks) { 63 if (monitor == null) 64 return new NullProgressMonitor(); 65 if (monitor instanceof NullProgressMonitor) 66 return monitor; 67 return new InfiniteSubProgressMonitor(monitor, ticks); 68 } 69 70 public static boolean isDebugProtocol() { 71 return DEBUG_CVS_PROTOCOL || recorder != null; 72 } 73 74 public static void printProtocolLine(String line) { 75 printProtocol(line, true); 76 } 77 78 public static void printProtocol(String string, boolean newLine) { 79 if (DEBUG_CVS_PROTOCOL) { 80 System.out.print(string); 81 if (newLine) { 82 System.out.println(); 83 } 84 } 85 if (recorder != null) { 86 recorder.print(string); 87 if (newLine) { 88 recorder.println(); 89 } 90 } 91 } 92 93 public static String getMessage(String key) { 94 try { 95 Field f = CVSMessages.class.getDeclaredField(key); 96 Object o = f.get(null); 97 if (o instanceof String ) 98 return (String )o; 99 } catch (SecurityException e) { 100 } catch (NoSuchFieldException e) { 101 } catch (IllegalArgumentException e) { 102 } catch (IllegalAccessException e) { 103 } 104 return null; 105 } 106 } 107 | Popular Tags |