code clean up. Bug 267448 Trace file issues
diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/Debug.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/Debug.java
index 92f7b7f..237d374 100644
--- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/Debug.java
+++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/Debug.java
@@ -347,7 +347,9 @@
printStackTrace(nested);
}
} catch (IllegalAccessException e) {
+ // nothing
} catch (InvocationTargetException e) {
+ // nothing
}
}
}
diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/EclipseDebugTrace.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/EclipseDebugTrace.java
index f8adb40..8a93649 100644
--- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/EclipseDebugTrace.java
+++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/EclipseDebugTrace.java
@@ -31,6 +31,71 @@
public static final String PROP_TRACE_SIZE_MAX = "eclipse.trace.size.max"; //$NON-NLS-1$
/** The system property used to specify the maximum number of backup trace files to use */
public static final String PROP_TRACE_FILE_MAX = "eclipse.trace.backup.max"; //$NON-NLS-1$
+ /** The trace message for a thread stack dump */
+ protected final static String MESSAGE_THREAD_DUMP = "Thread Stack dump: "; //$NON-NLS-1$
+ /** The trace message for a method completing with a return value */
+ protected final static String MESSAGE_EXIT_METHOD_WITH_RESULTS = "Exiting method with result: "; //$NON-NLS-1$
+ /** The trace message for a method completing with no return value */
+ protected final static String MESSAGE_EXIT_METHOD_NO_RESULTS = "Exiting method with a void return"; //$NON-NLS-1$
+ /** The trace message for a method starting with a set of arguments */
+ protected final static String MESSAGE_ENTER_METHOD_WITH_PARAMS = "Entering method with parameters: ("; //$NON-NLS-1$
+ /** The trace message for a method starting with no arguments */
+ protected final static String MESSAGE_ENTER_METHOD_NO_PARAMS = "Entering method with no parameters"; //$NON-NLS-1$
+ /** The version attribute written to the header of the trace file */
+ protected final static String TRACE_FILE_VERSION_COMMENT = "version: "; //$NON-NLS-1$
+ /** The version value written to the header of the trace file */
+ protected final static String TRACE_FILE_VERSION = "1.0"; //$NON-NLS-1$
+ /** The new session identifier to be written whenever a new session starts */
+ protected final static String TRACE_NEW_SESSION = "!SESSION "; //$NON-NLS-1$
+ /** The date attribute written to the header of the trace file to show when this file was created */
+ protected final static String TRACE_FILE_DATE = "Time of creation: "; //$NON-NLS-1$
+ /** Trace date formatter using the pattern: yyyy-MM-dd HH:mm:ss.SSS */
+ protected final static SimpleDateFormat TRACE_FILE_DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); //$NON-NLS-1$
+ /** The comment character used by the trace file */
+ protected final static String TRACE_COMMENT = "#"; //$NON-NLS-1$
+ /** The delimiter used to separate trace elements such as the time stamp, message, etc */
+ protected final static String TRACE_ELEMENT_DELIMITER = "|"; //$NON-NLS-1$
+ /** OS-specific line separator */
+ protected static final String LINE_SEPARATOR;
+ static {
+ String s = System.getProperty("line.separator"); //$NON-NLS-1$
+ LINE_SEPARATOR = s == null ? "\n" : s; //$NON-NLS-1$
+ }
+ /** The value written to the trace file if a null object is being traced */
+ public final static String NULL_VALUE = "<null>"; //$NON-NLS-1$
+ /** */
+ private final static SecureAction secureAction = (SecureAction) AccessController.doPrivileged(SecureAction.createSecureAction());
+ /** A lock object used to synchronize access to the trace file */
+ protected final static Object writeLock = new Object();
+
+ /******************* Tracing file attributes **************************/
+ /** The default size a trace file can grow before it is rotated */
+ public static final int DEFAULT_TRACE_FILE_SIZE = 1000; // The value is in KB.
+ /** The default number of backup trace files */
+ public static final int DEFAULT_TRACE_FILES = 10;
+ /** The minimum size limit for trace file rotation */
+ public static final int DEFAULT_TRACE_FILE_MIN_SIZE = 10;
+ /** The extension used for log files */
+ public static final String TRACE_FILE_EXTENSION = ".trace"; //$NON-NLS-1$
+ /** The extension markup to use for backup log files*/
+ public static final String BACKUP_MARK = ".bak_"; //$NON-NLS-1$
+ /** The maximum size that a trace file should grow (0 = unlimited) */
+ protected int maxTraceFileSize = DEFAULT_TRACE_FILE_SIZE; // The value is in KB.
+ /** The maximum number of trace files that should be saved */
+ protected int maxTraceFiles = DEFAULT_TRACE_FILES;
+ /** The index of the currently backed-up trace file */
+ protected int backupTraceFileIndex = 0;
+
+ /** An optional argument to specify the name of the class used by clients to trace messages. If no trace class is specified
+ * then the class calling this API is assumed to be the class being traced.
+ */
+ protected Class traceClass = null;
+ /** The symbolic name of the bundle being traced */
+ protected String bundleSymbolicName = null;
+ /** A flag to determine if the message being written is done to a new file (i.e. should the header information be written) */
+ protected static boolean newSession = true;
+ /** DebugOptions are used to determine if the specified bundle symbolic name + option-path has debugging enabled */
+ protected DebugOptions debugOptions = null;
/**
* Construct a new EclipseDebugTrace for the specified bundle symbolic name and write messages to the specified
@@ -57,7 +122,7 @@
this.traceClass = traceClass;
this.debugOptions = debugOptions;
this.bundleSymbolicName = bundleSymbolicName;
- this.readLogProperties();
+ readLogProperties();
}
/**
@@ -70,9 +135,9 @@
if (optionPath == null)
return true;
boolean debugEnabled = false;
- if (this.debugOptions.isDebugEnabled()) {
- final String option = this.bundleSymbolicName + optionPath;
- debugEnabled = this.debugOptions.getBooleanOption(option, false);
+ if (debugOptions.isDebugEnabled()) {
+ final String option = bundleSymbolicName + optionPath;
+ debugEnabled = debugOptions.getBooleanOption(option, false);
}
return debugEnabled;
}
@@ -83,9 +148,9 @@
*/
public void trace(final String optionPath, final String message) {
- if (this.isDebuggingEnabled(optionPath)) {
- final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(this.bundleSymbolicName, optionPath, message, this.traceClass);
- this.writeRecord(record);
+ if (isDebuggingEnabled(optionPath)) {
+ final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, message, traceClass);
+ writeRecord(record);
}
}
@@ -95,9 +160,9 @@
*/
public void trace(final String optionPath, final String message, final Throwable error) {
- if (this.isDebuggingEnabled(optionPath)) {
- final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(this.bundleSymbolicName, optionPath, message, error, this.traceClass);
- this.writeRecord(record);
+ if (isDebuggingEnabled(optionPath)) {
+ final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, message, error, traceClass);
+ writeRecord(record);
}
}
@@ -107,9 +172,9 @@
*/
public void traceEntry(final String optionPath) {
- if (this.isDebuggingEnabled(optionPath)) {
- final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(this.bundleSymbolicName, optionPath, EclipseDebugTrace.MESSAGE_ENTER_METHOD_NO_PARAMS, this.traceClass);
- this.writeRecord(record);
+ if (isDebuggingEnabled(optionPath)) {
+ final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, EclipseDebugTrace.MESSAGE_ENTER_METHOD_NO_PARAMS, traceClass);
+ writeRecord(record);
}
}
@@ -119,8 +184,8 @@
*/
public void traceEntry(final String optionPath, final Object methodArgument) {
- if (this.isDebuggingEnabled(optionPath)) {
- this.traceEntry(optionPath, new Object[] {methodArgument});
+ if (isDebuggingEnabled(optionPath)) {
+ traceEntry(optionPath, new Object[] {methodArgument});
}
}
@@ -130,7 +195,7 @@
*/
public void traceEntry(final String optionPath, final Object[] methodArguments) {
- if (this.isDebuggingEnabled(optionPath)) {
+ if (isDebuggingEnabled(optionPath)) {
final StringBuffer messageBuffer = new StringBuffer(EclipseDebugTrace.MESSAGE_ENTER_METHOD_WITH_PARAMS);
if (methodArguments != null) {
int i = 0;
@@ -145,8 +210,8 @@
}
messageBuffer.append(")"); //$NON-NLS-1$
}
- final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(this.bundleSymbolicName, optionPath, messageBuffer.toString(), this.traceClass);
- this.writeRecord(record);
+ final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, messageBuffer.toString(), traceClass);
+ writeRecord(record);
}
}
@@ -156,9 +221,9 @@
*/
public void traceExit(final String optionPath) {
- if (this.isDebuggingEnabled(optionPath)) {
- final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(this.bundleSymbolicName, optionPath, EclipseDebugTrace.MESSAGE_EXIT_METHOD_NO_RESULTS, this.traceClass);
- this.writeRecord(record);
+ if (isDebuggingEnabled(optionPath)) {
+ final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, EclipseDebugTrace.MESSAGE_EXIT_METHOD_NO_RESULTS, traceClass);
+ writeRecord(record);
}
}
@@ -168,15 +233,15 @@
*/
public void traceExit(final String optionPath, final Object result) {
- if (this.isDebuggingEnabled(optionPath)) {
+ if (isDebuggingEnabled(optionPath)) {
final StringBuffer messageBuffer = new StringBuffer(EclipseDebugTrace.MESSAGE_EXIT_METHOD_WITH_RESULTS);
if (result == null) {
messageBuffer.append(EclipseDebugTrace.NULL_VALUE);
} else {
messageBuffer.append(result.toString());
}
- final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(this.bundleSymbolicName, optionPath, messageBuffer.toString(), this.traceClass);
- this.writeRecord(record);
+ final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, messageBuffer.toString(), traceClass);
+ writeRecord(record);
}
}
@@ -186,13 +251,13 @@
*/
public void traceDumpStack(final String optionPath) {
- if (this.isDebuggingEnabled(optionPath)) {
+ if (isDebuggingEnabled(optionPath)) {
final StringBuffer messageBuffer = new StringBuffer(EclipseDebugTrace.MESSAGE_THREAD_DUMP);
StackTraceElement[] elements = new Exception().getStackTrace();
// the first element in this stack trace is going to be this class, so ignore it
// the second element in this stack trace is going to either be the caller or the trace class. Ignore it only if a traceClass is defined
// the rest of the elements should be included in the file array
- int firstIndex = (this.traceClass == null) ? 1 : 2;
+ int firstIndex = (traceClass == null) ? 1 : 2;
int endIndex = elements.length - firstIndex;
final StackTraceElement[] newElements = new StackTraceElement[endIndex];
int i = 0;
@@ -201,9 +266,9 @@
i++;
firstIndex++;
}
- messageBuffer.append(this.convertStackTraceElementsToString(newElements));
- final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(this.bundleSymbolicName, optionPath, messageBuffer.toString(), this.traceClass);
- this.writeRecord(record);
+ messageBuffer.append(convertStackTraceElementsToString(newElements));
+ final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, messageBuffer.toString(), traceClass);
+ writeRecord(record);
}
}
@@ -242,18 +307,18 @@
if (entry != null) {
synchronized (EclipseDebugTrace.writeLock) {
- final File tracingFile = this.debugOptions.getFile(); // the tracing file may be null if it has not been set
+ final File tracingFile = debugOptions.getFile(); // the tracing file may be null if it has not been set
Writer traceWriter = null;
try {
// check to see if the file should be rotated
- this.checkTraceFileSize(tracingFile);
+ checkTraceFileSize(tracingFile);
// open the trace file
- traceWriter = this.openWriter(tracingFile);
+ traceWriter = openWriter(tracingFile);
if (EclipseDebugTrace.newSession) {
- this.writeSession(traceWriter);
+ writeSession(traceWriter);
EclipseDebugTrace.newSession = false;
}
- this.writeMessage(traceWriter, entry);
+ writeMessage(traceWriter, entry);
// flush the writer
traceWriter.flush();
} catch (Exception ex) {
@@ -263,7 +328,7 @@
} finally {
// close the trace writer
if (tracingFile != null) {
- this.closeWriter(traceWriter);
+ closeWriter(traceWriter);
}
}
}
@@ -277,20 +342,20 @@
String newMaxTraceFileSize = secureAction.getProperty(PROP_TRACE_SIZE_MAX);
if (newMaxTraceFileSize != null) {
- this.maxTraceFileSize = Integer.parseInt(newMaxTraceFileSize);
- if (this.maxTraceFileSize != 0 && this.maxTraceFileSize < DEFAULT_TRACE_FILE_MIN_SIZE) {
+ maxTraceFileSize = Integer.parseInt(newMaxTraceFileSize);
+ if (maxTraceFileSize != 0 && maxTraceFileSize < DEFAULT_TRACE_FILE_MIN_SIZE) {
// If the value is '0', then it means no size limitation.
// Also, make sure no inappropriate(too small) assigned value.
- this.maxTraceFileSize = DEFAULT_TRACE_FILE_MIN_SIZE;
+ maxTraceFileSize = DEFAULT_TRACE_FILE_MIN_SIZE;
}
}
String newMaxLogFiles = secureAction.getProperty(PROP_TRACE_FILE_MAX);
if (newMaxLogFiles != null) {
- this.maxTraceFiles = Integer.parseInt(newMaxLogFiles);
- if (this.maxTraceFiles < 1) {
+ maxTraceFiles = Integer.parseInt(newMaxLogFiles);
+ if (maxTraceFiles < 1) {
// Make sure no invalid assigned value. (at least >= 1)
- this.maxTraceFiles = DEFAULT_TRACE_FILES;
+ maxTraceFiles = DEFAULT_TRACE_FILES;
}
}
}
@@ -305,17 +370,17 @@
// 0 file size means there is no size limit
boolean isBackupOK = true;
- if (this.maxTraceFileSize > 0) {
+ if (maxTraceFileSize > 0) {
if ((traceFile != null) && traceFile.exists()) {
- if ((traceFile.length() >> 10) > this.maxTraceFileSize) { // Use KB as file size unit.
+ if ((traceFile.length() >> 10) > maxTraceFileSize) { // Use KB as file size unit.
final String traceFileName = traceFile.getAbsolutePath();
// Delete old backup file that will be replaced.
String backupFilename = ""; //$NON-NLS-1$
if (traceFileName.toLowerCase().endsWith(TRACE_FILE_EXTENSION)) {
- backupFilename = traceFileName.substring(0, traceFileName.length() - TRACE_FILE_EXTENSION.length()) + BACKUP_MARK + this.backupTraceFileIndex + TRACE_FILE_EXTENSION;
+ backupFilename = traceFileName.substring(0, traceFileName.length() - TRACE_FILE_EXTENSION.length()) + BACKUP_MARK + backupTraceFileIndex + TRACE_FILE_EXTENSION;
} else {
- backupFilename = traceFileName + BACKUP_MARK + this.backupTraceFileIndex;
+ backupFilename = traceFileName + BACKUP_MARK + backupTraceFileIndex;
}
final File backupFile = new File(backupFilename);
if (backupFile.exists()) {
@@ -343,18 +408,18 @@
*/
Writer traceWriter = null;
try {
- traceWriter = this.openWriter(traceFile);
- this.writeComment(traceWriter, "This is a continuation of trace file " + backupFile.getAbsolutePath()); //$NON-NLS-1$
- this.writeComment(traceWriter, EclipseDebugTrace.TRACE_FILE_DATE + EclipseDebugTrace.TRACE_FILE_DATE_FORMATTER.format(new Date(System.currentTimeMillis())));
+ traceWriter = openWriter(traceFile);
+ writeComment(traceWriter, "This is a continuation of trace file " + backupFile.getAbsolutePath()); //$NON-NLS-1$
+ writeComment(traceWriter, EclipseDebugTrace.TRACE_FILE_DATE + EclipseDebugTrace.TRACE_FILE_DATE_FORMATTER.format(new Date(System.currentTimeMillis())));
traceWriter.flush();
} catch (IOException ioEx) {
ioEx.printStackTrace();
} finally {
if (traceFile != null) {
- this.closeWriter(traceWriter);
+ closeWriter(traceWriter);
}
}
- this.backupTraceFileIndex = (++this.backupTraceFileIndex) % this.maxTraceFiles;
+ backupTraceFileIndex = (++backupTraceFileIndex) % maxTraceFiles;
}
}
}
@@ -405,12 +470,12 @@
*/
protected void writeSession(final Writer traceWriter) throws IOException {
- this.writeComment(traceWriter, EclipseDebugTrace.TRACE_NEW_SESSION + this.getFormattedDate());
- this.writeComment(traceWriter, EclipseDebugTrace.TRACE_FILE_VERSION_COMMENT + EclipseDebugTrace.TRACE_FILE_VERSION);
- this.writeComment(traceWriter, "The following option strings are specified for this debug session:"); //$NON-NLS-1$
+ writeComment(traceWriter, EclipseDebugTrace.TRACE_NEW_SESSION + this.getFormattedDate());
+ writeComment(traceWriter, EclipseDebugTrace.TRACE_FILE_VERSION_COMMENT + EclipseDebugTrace.TRACE_FILE_VERSION);
+ writeComment(traceWriter, "The following option strings are specified for this debug session:"); //$NON-NLS-1$
final String[] allOptions = FrameworkDebugOptions.getDefault().getAllOptions();
for (int i = 0; i < allOptions.length; i++) {
- this.writeComment(traceWriter, "\t" + allOptions[i]); //$NON-NLS-1$
+ writeComment(traceWriter, "\t" + allOptions[i]); //$NON-NLS-1$
}
}
@@ -493,12 +558,12 @@
Writer traceWriter = null;
if (traceFile != null) {
try {
- traceWriter = this.logForStream(secureAction.getFileOutputStream(traceFile, true));
+ traceWriter = logForStream(secureAction.getFileOutputStream(traceFile, true));
} catch (IOException ioEx) {
- traceWriter = this.logForStream(System.out);
+ traceWriter = logForStream(System.out);
}
} else {
- traceWriter = this.logForStream(System.out);
+ traceWriter = logForStream(System.out);
}
return traceWriter;
}
@@ -520,70 +585,4 @@
traceWriter = null;
}
}
-
- /** The trace message for a thread stack dump */
- protected final static String MESSAGE_THREAD_DUMP = "Thread Stack dump: "; //$NON-NLS-1$
- /** The trace message for a method completing with a return value */
- protected final static String MESSAGE_EXIT_METHOD_WITH_RESULTS = "Exiting method with result: "; //$NON-NLS-1$
- /** The trace message for a method completing with no return value */
- protected final static String MESSAGE_EXIT_METHOD_NO_RESULTS = "Exiting method with a void return"; //$NON-NLS-1$
- /** The trace message for a method starting with a set of arguments */
- protected final static String MESSAGE_ENTER_METHOD_WITH_PARAMS = "Entering method with parameters: ("; //$NON-NLS-1$
- /** The trace message for a method starting with no arguments */
- protected final static String MESSAGE_ENTER_METHOD_NO_PARAMS = "Entering method with no parameters"; //$NON-NLS-1$
- /** The version attribute written to the header of the trace file */
- protected final static String TRACE_FILE_VERSION_COMMENT = "version: "; //$NON-NLS-1$
- /** The version value written to the header of the trace file */
- protected final static String TRACE_FILE_VERSION = "1.0"; //$NON-NLS-1$
- /** The new session identifier to be written whenever a new session starts */
- protected final static String TRACE_NEW_SESSION = "!SESSION "; //$NON-NLS-1$
- /** The date attribute written to the header of the trace file to show when this file was created */
- protected final static String TRACE_FILE_DATE = "Time of creation: "; //$NON-NLS-1$
- /** Trace date formatter using the pattern: yyyy-MM-dd HH:mm:ss.SSS */
- protected final static SimpleDateFormat TRACE_FILE_DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); //$NON-NLS-1$
- /** The comment character used by the trace file */
- protected final static String TRACE_COMMENT = "#"; //$NON-NLS-1$
- /** The delimiter used to separate trace elements such as the time stamp, message, etc */
- protected final static String TRACE_ELEMENT_DELIMITER = "|"; //$NON-NLS-1$
- /** OS-specific line separator */
- protected static final String LINE_SEPARATOR;
- static {
- String s = System.getProperty("line.separator"); //$NON-NLS-1$
- LINE_SEPARATOR = s == null ? "\n" : s; //$NON-NLS-1$
- }
- /** The value written to the trace file if a null object is being traced */
- public final static String NULL_VALUE = "<null>"; //$NON-NLS-1$
- /** */
- private final static SecureAction secureAction = (SecureAction) AccessController.doPrivileged(SecureAction.createSecureAction());
- /** A lock object used to synchronize access to the trace file */
- protected final static Object writeLock = new Object();
-
- /** An optional argument to specify the name of the class used by clients to trace messages. If no trace class is specified
- * then the class calling this API is assumed to be the class being traced.
- */
- protected Class traceClass = null;
- /** The symbolic name of the bundle being traced */
- protected String bundleSymbolicName = null;
- /** A flag to determine if the message being written is done to a new file (i.e. should the header information be written) */
- protected static boolean newSession = true;
- /** DebugOptions are used to determine if the specified bundle symbolic name + option-path has debugging enabled */
- protected DebugOptions debugOptions = null;
-
- /******************* Tracing file attributes **************************/
- /** The default size a trace file can grow before it is rotated */
- public static final int DEFAULT_TRACE_FILE_SIZE = 1000; // The value is in KB.
- /** The default number of backup trace files */
- public static final int DEFAULT_TRACE_FILES = 10;
- /** The minimum size limit for trace file rotation */
- public static final int DEFAULT_TRACE_FILE_MIN_SIZE = 10;
- /** The extension used for log files */
- public static final String TRACE_FILE_EXTENSION = ".trace"; //$NON-NLS-1$
- /** The extension markup to use for backup log files*/
- public static final String BACKUP_MARK = ".bak_"; //$NON-NLS-1$
- /** The maximum size that a trace file should grow (0 = unlimited) */
- protected int maxTraceFileSize = DEFAULT_TRACE_FILE_SIZE; // The value is in KB.
- /** The maximum number of trace files that should be saved */
- protected int maxTraceFiles = DEFAULT_TRACE_FILES;
- /** The index of the currently backed-up trace file */
- protected int backupTraceFileIndex = 0;
}
\ No newline at end of file
diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugTraceEntry.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugTraceEntry.java
index 94669bf..a057932 100644
--- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugTraceEntry.java
+++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugTraceEntry.java
@@ -14,208 +14,8 @@
* A framework trace entry is a bean containing all of the attributes for a single trace message.
*/
public class FrameworkDebugTraceEntry {
-
- /**
- * Construct a new FrameworkTraceRecord object
- *
- * @param bundleSymbolicName
- * The symbolic name of the bundle being traced
- * @param optionPath
- * The trace optionPath
- * @param message
- * The trace message
- * @param traceClass
- * The class that calls the trace API
- */
- public FrameworkDebugTraceEntry(final String bundleSymbolicName, final String optionPath, final String message, final Class traceClass) {
- this(bundleSymbolicName, optionPath, message, null, traceClass);
- }
-
- /**
- * Construct a new FrameworkTraceRecord object
- *
- * @param bundleSymbolicName
- * The symbolic name of the bundle being traced
- * @param optionPath
- * The trace optionPath
- * @param message
- * The trace message
- * @param error
- * An exception to be traced
- * @param traceClass
- * The class that calls the trace API
- */
- public FrameworkDebugTraceEntry(String bundleSymbolicName, final String optionPath, final String message, final Throwable error, final Class traceClass) {
- this.threadName = Thread.currentThread().getName();
- if (optionPath == null) {
- this.optionPath = FrameworkDebugTraceEntry.DEFAULT_OPTION_PATH;
- } else {
- this.optionPath = optionPath;
- }
- this.timestamp = System.currentTimeMillis();
- this.bundleSymbolicName = bundleSymbolicName;
- this.message = message;
- this.throwable = error;
-
- String determineClassName = null;
- String determineMethodName = null;
- int determineLineNumber = 0;
- // dynamically determine the class name, method name, and line number of the method calling the trace framework
- StackTraceElement[] stackElements = new Exception().getStackTrace();
- int i = 0;
- while (i < stackElements.length) {
- String fullClassName = stackElements[i].getClassName();
- if (!fullClassName.equals(Thread.class.getName()) && !fullClassName.equals(FrameworkDebugTraceEntry.class.getName()) && !fullClassName.equals(EclipseDebugTrace.class.getName())) {
- /*
- * The first class which is non-JDK or framework related has been hit.
- * If a traceClass has been specified then this current stack element
- * is likely that class so we should find out who called it. If a
- * trace class has not been specified, or has been specified and this
- * stack element is not that class, then we assume this stack element
- * is the caller of the trace API.
- */
- if ((traceClass == null) || !fullClassName.equals(traceClass.getName())) {
- determineClassName = stackElements[i].getClassName();
- determineMethodName = stackElements[i].getMethodName();
- determineLineNumber = stackElements[i].getLineNumber();
- }
- break;
- }
- i++;
- }
-
- this.className = determineClassName;
- this.methodName = determineMethodName;
- this.lineNumber = determineLineNumber;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- public String toString() {
-
- final StringBuffer buffer = new StringBuffer(this.threadName);
- buffer.append(" "); //$NON-NLS-1$
- buffer.append(this.timestamp);
- buffer.append(" "); //$NON-NLS-1$
- buffer.append(this.bundleSymbolicName);
- buffer.append(" "); //$NON-NLS-1$
- buffer.append(this.optionPath);
- buffer.append(" "); //$NON-NLS-1$
- buffer.append(this.className);
- buffer.append(" "); //$NON-NLS-1$
- buffer.append(this.methodName);
- buffer.append(" "); //$NON-NLS-1$
- buffer.append(this.lineNumber);
- if (this.message != null) {
- buffer.append(": "); //$NON-NLS-1$
- buffer.append(this.message);
- }
- if (this.throwable != null) {
- buffer.append(this.throwable);
- }
- return buffer.toString();
- }
-
- /**
- * Accessor to the threads name
- *
- * @return the name of the thread
- */
- public final String getThreadName() {
-
- return this.threadName;
- }
-
- /**
- * Accessor to the timestamp for this trace record
- *
- * @return the date
- */
- public final long getTimestamp() {
-
- return this.timestamp;
- }
-
- /**
- * Accessor for the symbolic name of the bundle being traced
- *
- * @return The symbolic name of the bundle being traced
- */
- public final String getBundleSymbolicName() {
-
- return this.bundleSymbolicName;
- }
-
- /**
- * Accessor for the trace message
- *
- * @return the trace message
- */
- public final String getMessage() {
-
- return this.message;
- }
-
- /**
- * Accessor for the trace exception. This may be null if there is no exception.
- *
- * @return the trace exception or null if none was defined.
- */
- public final Throwable getThrowable() {
-
- return this.throwable;
- }
-
- /**
- * Accessor for the name of the class being traced.
- *
- * @return The name of the class being traced.
- */
- public final String getClassName() {
-
- return this.className;
- }
-
- /**
- * Accessor for the method being traced.
- *
- * @return The name of the method being traced.
- */
- public final String getMethodName() {
-
- return this.methodName;
- }
-
- /**
- * Accessor for the option-path being traced. The <i><option-path></i> part of the debug option string
- * required for the Eclipse debugging framework.
- *
- * <pre>
- * Examples:
- * 1) If a trace string com.ibm.myplugin.core/debug=true is specified then 'debug' is the option-path value.
- * 2) If a trace string com.ibm.myplugin.core/debug/perf=true is specified then 'debug/perf' is the option-path value.
- * </pre>
- *
- *
- * @return The option-path being traced.
- */
- public final String getOptionPath() {
-
- return this.optionPath;
- }
-
- /**
- * Return the line number in the class/method where the trace originator
- *
- * @return The line number from the class and method where the trace request originated
- */
- public final int getLineNumber() {
-
- return this.lineNumber;
- }
+ /** If a bundles symbolic name is not specified then the default value of /debug can be used */
+ public final static String DEFAULT_OPTION_PATH = "/debug"; //$NON-NLS-1$
/**
* The name of the thread executing the code
@@ -263,6 +63,205 @@
*/
private final Throwable throwable;
- /** If a bundles symbolic name is not specified then the default value of /debug can be used */
- public final static String DEFAULT_OPTION_PATH = "/debug"; //$NON-NLS-1$
+ /**
+ * Construct a new FrameworkTraceRecord object
+ *
+ * @param bundleSymbolicName
+ * The symbolic name of the bundle being traced
+ * @param optionPath
+ * The trace optionPath
+ * @param message
+ * The trace message
+ * @param traceClass
+ * The class that calls the trace API
+ */
+ public FrameworkDebugTraceEntry(final String bundleSymbolicName, final String optionPath, final String message, final Class traceClass) {
+ this(bundleSymbolicName, optionPath, message, null, traceClass);
+ }
+
+ /**
+ * Construct a new FrameworkTraceRecord object
+ *
+ * @param bundleSymbolicName
+ * The symbolic name of the bundle being traced
+ * @param optionPath
+ * The trace optionPath
+ * @param message
+ * The trace message
+ * @param error
+ * An exception to be traced
+ * @param traceClass
+ * The class that calls the trace API
+ */
+ public FrameworkDebugTraceEntry(String bundleSymbolicName, final String optionPath, final String message, final Throwable error, final Class traceClass) {
+ threadName = Thread.currentThread().getName();
+ if (optionPath == null) {
+ this.optionPath = FrameworkDebugTraceEntry.DEFAULT_OPTION_PATH;
+ } else {
+ this.optionPath = optionPath;
+ }
+ timestamp = System.currentTimeMillis();
+ this.bundleSymbolicName = bundleSymbolicName;
+ this.message = message;
+ throwable = error;
+
+ String determineClassName = null;
+ String determineMethodName = null;
+ int determineLineNumber = 0;
+ // dynamically determine the class name, method name, and line number of the method calling the trace framework
+ StackTraceElement[] stackElements = new Exception().getStackTrace();
+ int i = 0;
+ while (i < stackElements.length) {
+ String fullClassName = stackElements[i].getClassName();
+ if (!fullClassName.equals(Thread.class.getName()) && !fullClassName.equals(FrameworkDebugTraceEntry.class.getName()) && !fullClassName.equals(EclipseDebugTrace.class.getName())) {
+ /*
+ * The first class which is non-JDK or framework related has been hit.
+ * If a traceClass has been specified then this current stack element
+ * is likely that class so we should find out who called it. If a
+ * trace class has not been specified, or has been specified and this
+ * stack element is not that class, then we assume this stack element
+ * is the caller of the trace API.
+ */
+ if ((traceClass == null) || !fullClassName.equals(traceClass.getName())) {
+ determineClassName = stackElements[i].getClassName();
+ determineMethodName = stackElements[i].getMethodName();
+ determineLineNumber = stackElements[i].getLineNumber();
+ }
+ break;
+ }
+ i++;
+ }
+
+ className = determineClassName;
+ methodName = determineMethodName;
+ lineNumber = determineLineNumber;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+
+ final StringBuffer buffer = new StringBuffer(threadName);
+ buffer.append(" "); //$NON-NLS-1$
+ buffer.append(timestamp);
+ buffer.append(" "); //$NON-NLS-1$
+ buffer.append(bundleSymbolicName);
+ buffer.append(" "); //$NON-NLS-1$
+ buffer.append(optionPath);
+ buffer.append(" "); //$NON-NLS-1$
+ buffer.append(className);
+ buffer.append(" "); //$NON-NLS-1$
+ buffer.append(methodName);
+ buffer.append(" "); //$NON-NLS-1$
+ buffer.append(lineNumber);
+ if (message != null) {
+ buffer.append(": "); //$NON-NLS-1$
+ buffer.append(message);
+ }
+ if (throwable != null) {
+ buffer.append(throwable);
+ }
+ return buffer.toString();
+ }
+
+ /**
+ * Accessor to the threads name
+ *
+ * @return the name of the thread
+ */
+ public final String getThreadName() {
+
+ return threadName;
+ }
+
+ /**
+ * Accessor to the timestamp for this trace record
+ *
+ * @return the date
+ */
+ public final long getTimestamp() {
+
+ return timestamp;
+ }
+
+ /**
+ * Accessor for the symbolic name of the bundle being traced
+ *
+ * @return The symbolic name of the bundle being traced
+ */
+ public final String getBundleSymbolicName() {
+
+ return bundleSymbolicName;
+ }
+
+ /**
+ * Accessor for the trace message
+ *
+ * @return the trace message
+ */
+ public final String getMessage() {
+
+ return message;
+ }
+
+ /**
+ * Accessor for the trace exception. This may be null if there is no exception.
+ *
+ * @return the trace exception or null if none was defined.
+ */
+ public final Throwable getThrowable() {
+
+ return throwable;
+ }
+
+ /**
+ * Accessor for the name of the class being traced.
+ *
+ * @return The name of the class being traced.
+ */
+ public final String getClassName() {
+
+ return className;
+ }
+
+ /**
+ * Accessor for the method being traced.
+ *
+ * @return The name of the method being traced.
+ */
+ public final String getMethodName() {
+
+ return methodName;
+ }
+
+ /**
+ * Accessor for the option-path being traced. The <i><option-path></i> part of the debug option string
+ * required for the Eclipse debugging framework.
+ *
+ * <pre>
+ * Examples:
+ * 1) If a trace string com.ibm.myplugin.core/debug=true is specified then 'debug' is the option-path value.
+ * 2) If a trace string com.ibm.myplugin.core/debug/perf=true is specified then 'debug/perf' is the option-path value.
+ * </pre>
+ *
+ *
+ * @return The option-path being traced.
+ */
+ public final String getOptionPath() {
+
+ return optionPath;
+ }
+
+ /**
+ * Return the line number in the class/method where the trace originator
+ *
+ * @return The line number from the class and method where the trace request originated
+ */
+ public final int getLineNumber() {
+
+ return lineNumber;
+ }
}
\ No newline at end of file