KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > utils > Policy


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.utils;
12
13 import java.util.Date JavaDoc;
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     //general debug flag for the plugin
21
public static boolean DEBUG = false;
22
23     public static boolean DEBUG_AUTO_REFRESH = false;
24
25     //debug constants
26
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     // Get timing information for restoring data
40
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     // Get timing information for save and snapshot data
49
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         //init debug options
66
if (ResourcesPlugin.getPlugin().isDebugging()) {
67             DEBUG = true;
68             String JavaDoc sTrue = Boolean.TRUE.toString();
69             DEBUG_AUTO_REFRESH = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/refresh")); //$NON-NLS-1$
70

71             DEBUG_BUILD_DELTA = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/build/delta")); //$NON-NLS-1$
72
DEBUG_BUILD_FAILURE = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/build/failure")); //$NON-NLS-1$
73
DEBUG_BUILD_INVOKING = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/build/invoking")); //$NON-NLS-1$
74
DEBUG_BUILD_INTERRUPT = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/build/interrupt")); //$NON-NLS-1$
75
DEBUG_BUILD_NEEDED = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/build/needbuild")); //$NON-NLS-1$
76
DEBUG_BUILD_NEEDED_STACK = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/build/needbuildstack")); //$NON-NLS-1$
77
DEBUG_BUILD_STACK = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/build/stacktrace")); //$NON-NLS-1$
78

79             DEBUG_CONTENT_TYPE = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/contenttype")); //$NON-NLS-1$
80
DEBUG_CONTENT_TYPE_CACHE = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/contenttype/cache")); //$NON-NLS-1$
81
DEBUG_HISTORY = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/history")); //$NON-NLS-1$
82
DEBUG_NATURES = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/natures")); //$NON-NLS-1$
83
DEBUG_PREFERENCES = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/preferences")); //$NON-NLS-1$
84

85             DEBUG_RESTORE = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/restore")); //$NON-NLS-1$
86
DEBUG_RESTORE_MARKERS = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/restore/markers")); //$NON-NLS-1$
87
DEBUG_RESTORE_MASTERTABLE = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/restore/mastertable")); //$NON-NLS-1$
88
DEBUG_RESTORE_METAINFO = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/restore/metainfo")); //$NON-NLS-1$
89
DEBUG_RESTORE_SNAPSHOTS = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/restore/snapshots")); //$NON-NLS-1$
90
DEBUG_RESTORE_SYNCINFO = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/restore/syncinfo")); //$NON-NLS-1$
91
DEBUG_RESTORE_TREE = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/restore/tree")); //$NON-NLS-1$
92

93             DEBUG_SAVE = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/save")); //$NON-NLS-1$
94
DEBUG_SAVE_MARKERS = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/save/markers")); //$NON-NLS-1$
95
DEBUG_SAVE_MASTERTABLE = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/save/mastertable")); //$NON-NLS-1$
96
DEBUG_SAVE_METAINFO = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/save/metainfo")); //$NON-NLS-1$
97
DEBUG_SAVE_SYNCINFO = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/save/syncinfo")); //$NON-NLS-1$
98
DEBUG_SAVE_TREE = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/save/tree")); //$NON-NLS-1$
99

100             DEBUG_STRINGS = sTrue.equalsIgnoreCase(Platform.getDebugOption(ResourcesPlugin.PI_RESOURCES + "/strings")); //$NON-NLS-1$
101
}
102     }
103
104     public static void checkCanceled(IProgressMonitor monitor) {
105         if (monitor.isCanceled())
106             throw new OperationCanceledException();
107     }
108
109     /**
110      * Print a debug message to the console.
111      * Pre-pend the message with the current date and the name of the current thread.
112      */

113     public static void debug(String JavaDoc message) {
114         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
115         buffer.append(new Date JavaDoc(System.currentTimeMillis()));
116         buffer.append(" - ["); //$NON-NLS-1$
117
buffer.append(Thread.currentThread().getName());
118         buffer.append("] "); //$NON-NLS-1$
119
buffer.append(message);
120         System.out.println(buffer.toString());
121     }
122
123     public static void log(int severity, String JavaDoc message, Throwable JavaDoc t) {
124         if (message == null)
125             message = ""; //$NON-NLS-1$
126
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     /**
137      * Logs a throwable, assuming severity of error
138      * @param t
139      */

140     public static void log(Throwable JavaDoc t) {
141         log(IStatus.ERROR, "Internal Error", t); //$NON-NLS-1$
142
}
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