Bug 567964 - Add debug trace for open/close operations

Change-Id: Iaedc19d937a069e40cef242d40b4ac0b746848c0
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
diff --git a/bundles/org.eclipse.osgi/.options b/bundles/org.eclipse.osgi/.options
index 8e606f0..2ffeaa1 100644
--- a/bundles/org.eclipse.osgi/.options
+++ b/bundles/org.eclipse.osgi/.options
@@ -40,6 +40,10 @@
 org.eclipse.osgi/debug/storage=false
 # Debug the bundle file reading
 org.eclipse.osgi/debug/bundleFile=false
+# Debug the bundle file open calls
+org.eclipse.osgi/debug/bundleFile/open=false
+# Debug the bundle file close calls
+org.eclipse.osgi/debug/bundleFile/close=false
 
 # Eclipse adaptor options
 org.eclipse.osgi/eclipseadaptor/debug = false
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/connect/ConnectBundleFile.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/connect/ConnectBundleFile.java
index 2570312..f71245c 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/connect/ConnectBundleFile.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/connect/ConnectBundleFile.java
@@ -141,4 +141,9 @@
 	Optional<ClassLoader> getClassLoader() {
 		return content.getClassLoader();
 	}
+
+	@Override
+	public String toString() {
+		return content.toString();
+	}
 }
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/debug/Debug.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/debug/Debug.java
index 00bb826..daee0c1 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/debug/Debug.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/debug/Debug.java
@@ -109,6 +109,10 @@
 
 	public static final String OPTION_DEBUG_BUNDLE_FILE = ECLIPSE_OSGI + "/debug/bundleFile"; //$NON-NLS-1$
 
+	public static final String OPTION_DEBUG_BUNDLE_FILE_OPEN = ECLIPSE_OSGI + "/debug/bundleFile/open"; //$NON-NLS-1$
+
+	public static final String OPTION_DEBUG_BUNDLE_FILE_CLOSE = ECLIPSE_OSGI + "/debug/bundleFile/close"; //$NON-NLS-1$
+
 	/**
 	 * General debug flag.
 	 */
@@ -180,6 +184,10 @@
 
 	public boolean DEBUG_BUNDLE_FILE = false; // debug/bundleFile
 
+	public boolean DEBUG_BUNDLE_FILE_OPEN = false; // debug/bundleFile/open
+
+	public boolean DEBUG_BUNDLE_FILE_CLOSE = false; // debug/bundleFile/close
+
 	public Debug(DebugOptions dbgOptions) {
 		optionsChanged(dbgOptions);
 	}
@@ -207,6 +215,8 @@
 		DEBUG_CACHED_MANIFEST = dbgOptions.getBooleanOption(OPTION_CACHED_MANIFEST, false);
 		DEBUG_SYSTEM_BUNDLE = dbgOptions.getBooleanOption(OPTION_DEBUG_SYSTEM_BUNDLE, false);
 		DEBUG_BUNDLE_FILE = dbgOptions.getBooleanOption(OPTION_DEBUG_BUNDLE_FILE, false);
+		DEBUG_BUNDLE_FILE_OPEN = dbgOptions.getBooleanOption(OPTION_DEBUG_BUNDLE_FILE_OPEN, false);
+		DEBUG_BUNDLE_FILE_CLOSE = dbgOptions.getBooleanOption(OPTION_DEBUG_BUNDLE_FILE_CLOSE, false);
 	}
 
 	/**
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/CloseableBundleFile.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/CloseableBundleFile.java
index aeb4cc5..a425013 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/CloseableBundleFile.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/CloseableBundleFile.java
@@ -134,6 +134,9 @@
 					// This can throw an IO exception resulting in closed remaining true on exit
 					doOpen();
 					closed = false;
+					if (debug.DEBUG_BUNDLE_FILE_OPEN) {
+						Debug.println("OPENED bundle file - " + toString()); //$NON-NLS-1$
+					}
 				}
 			} else {
 				mruListUse();
@@ -356,6 +359,9 @@
 				doClose();
 				mruListRemove();
 				postClose();
+				if (debug.DEBUG_BUNDLE_FILE_CLOSE) {
+					Debug.println("CLOSED bundle file - " + toString()); //$NON-NLS-1$
+				}
 			}
 		} finally {
 			openLock.unlock();