package org.eclipse.core.internal.utils;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.osgi.service.debug.*;
import org.osgi.framework.Bundle;
public class Policy {
static DebugTrace DEBUG_TRACE;
public static final DebugOptionsListener RESOURCES_DEBUG_OPTIONS_LISTENER = new DebugOptionsListener() {
@Override
public void optionsChanged(DebugOptions options) {
DEBUG_TRACE = options.newDebugTrace(ResourcesPlugin.PI_RESOURCES);
DEBUG = options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/debug", false);
DEBUG_AUTO_REFRESH = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/refresh", false);
DEBUG_BUILD_DELTA = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/build/delta", false);
DEBUG_BUILD_CYCLE = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/build/cycle", false);
DEBUG_BUILD_FAILURE = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/build/failure", false);
DEBUG_BUILD_INTERRUPT = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/build/interrupt", false);
DEBUG_BUILD_INVOKING = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/build/invoking", false);
DEBUG_BUILD_NEEDED = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/build/needbuild", false);
DEBUG_BUILD_NEEDED_STACK = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/build/needbuildstack", false);
DEBUG_BUILD_STACK = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/build/stacktrace", false);
DEBUG_CONTENT_TYPE = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/contenttype", false);
DEBUG_CONTENT_TYPE_CACHE = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/contenttype/cache", false);
DEBUG_HISTORY = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/history", false);
DEBUG_NATURES = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/natures", false);
DEBUG_NOTIFICATIONS = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/notifications", false);
DEBUG_PREFERENCES = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/preferences", false);
DEBUG_RESTORE = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/restore", false);
DEBUG_RESTORE_MARKERS = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/restore/markers", false);
DEBUG_RESTORE_MASTERTABLE = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/restore/mastertable", false);
DEBUG_RESTORE_METAINFO = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/restore/metainfo", false);
DEBUG_RESTORE_SNAPSHOTS = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/restore/snapshots", false);
DEBUG_RESTORE_SYNCINFO = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/restore/syncinfo", false);
DEBUG_RESTORE_TREE = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/restore/tree", false);
DEBUG_SAVE = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/save", false);
DEBUG_SAVE_MARKERS = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/save/markers", false);
DEBUG_SAVE_MASTERTABLE = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/save/mastertable", false);
DEBUG_SAVE_METAINFO = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/save/metainfo", false);
DEBUG_SAVE_SYNCINFO = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/save/syncinfo", false);
DEBUG_SAVE_TREE = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/save/tree", false);
DEBUG_STRINGS = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/strings", false);
}
};
public static final boolean buildOnCancel = false;
public static boolean DEBUG = false;
public static boolean DEBUG_AUTO_REFRESH = false;
public static boolean DEBUG_BUILD_DELTA = false;
public static boolean DEBUG_BUILD_CYCLE = false;
public static boolean DEBUG_BUILD_FAILURE = false;
public static boolean DEBUG_BUILD_INTERRUPT = false;
public static boolean DEBUG_BUILD_INVOKING = false;
public static boolean DEBUG_BUILD_NEEDED = false;
public static boolean DEBUG_BUILD_NEEDED_STACK = false;
public static boolean DEBUG_BUILD_STACK = false;
public static boolean DEBUG_CONTENT_TYPE = false;
public static boolean DEBUG_CONTENT_TYPE_CACHE = false;
public static boolean DEBUG_HISTORY = false;
public static boolean DEBUG_NATURES = false;
public static boolean DEBUG_NOTIFICATIONS = false;
public static boolean DEBUG_PREFERENCES = false;
public static boolean DEBUG_RESTORE = false;
public static boolean DEBUG_RESTORE_MARKERS = false;
public static boolean DEBUG_RESTORE_MASTERTABLE = false;
public static boolean DEBUG_RESTORE_METAINFO = false;
public static boolean DEBUG_RESTORE_SNAPSHOTS = false;
public static boolean DEBUG_RESTORE_SYNCINFO = false;
public static boolean DEBUG_RESTORE_TREE = false;
public static boolean DEBUG_SAVE = false;
public static boolean DEBUG_SAVE_MARKERS = false;
public static boolean DEBUG_SAVE_MASTERTABLE = false;
public static boolean DEBUG_SAVE_METAINFO = false;
public static boolean DEBUG_SAVE_SYNCINFO = false;
public static boolean DEBUG_SAVE_TREE = false;
public static boolean DEBUG_STRINGS = false;
public static final long MAX_BUILD_DELAY = 1000;
public static final long MIN_BUILD_DELAY = 100;
public static int opWork = 100;
public static final int totalWork = 100;
public static void checkCanceled(IProgressMonitor monitor) {
if (monitor.isCanceled())
throw new OperationCanceledException();
}
public static void debug(String message) {
StringBuilder output = new StringBuilder();
Job currentJob = Job.getJobManager().currentJob();
if (currentJob != null) {
output.append(currentJob.getClass().getName());
output.append("(");
output.append(currentJob.getName());
output.append("): ");
}
output.append(message);
DEBUG_TRACE.trace(null, output.toString());
}
public static void debug(Throwable t) {
StringWriter writer = new StringWriter();
t.printStackTrace(new PrintWriter(writer));
String str = writer.toString();
if (str.endsWith("\n"))
str = str.substring(0, str.length() - 2);
debug(str);
}
public static void log(int severity, String message, Throwable t) {
if (message == null)
message = "";
log(new Status(severity, ResourcesPlugin.PI_RESOURCES, 1, message, t));
}
public static void log(IStatus status) {
final Bundle bundle = Platform.getBundle(ResourcesPlugin.PI_RESOURCES);
if (bundle == null)
return;
Platform.getLog(bundle).log(status);
}
public static void log(Throwable t) {
log(IStatus.ERROR, "Internal Error", t);
}
public static IProgressMonitor monitorFor(IProgressMonitor monitor) {
return monitor == null ? new NullProgressMonitor() : monitor;
}
public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks) {
if (monitor == null)
return new NullProgressMonitor();
if (monitor instanceof NullProgressMonitor)
return monitor;
return new SubProgressMonitor(monitor, ticks);
}
}