Bug 432198 - Clean up trace options for class loading
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoader.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoader.java
index 4253633..d64241b 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoader.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoader.java
@@ -338,7 +338,7 @@
private Class<?> findClassInternal(String name, boolean checkParent) throws ClassNotFoundException {
if (debug.DEBUG_LOADER)
- Debug.println("BundleLoader[" + this + "].loadBundleClass(" + name + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Debug.println("BundleLoader[" + this + "].findClassInternal(" + name + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String pkgName = getPackageName(name);
boolean bootDelegation = false;
// follow the OSGi delegation model
@@ -363,6 +363,9 @@
// 3) search the imported packages
PackageSource source = findImportedSource(pkgName, null);
if (source != null) {
+ if (debug.DEBUG_LOADER) {
+ Debug.println("BundleLoader[" + this + "] loading from import package: " + source); //$NON-NLS-1$ //$NON-NLS-2$
+ }
// 3) found import source terminate search at the source
result = source.loadClass(name);
if (result != null)
@@ -371,9 +374,13 @@
}
// 4) search the required bundles
source = findRequiredSource(pkgName, null);
- if (source != null)
+ if (source != null) {
+ if (debug.DEBUG_LOADER) {
+ Debug.println("BundleLoader[" + this + "] loading from required bundle package: " + source); //$NON-NLS-1$ //$NON-NLS-2$
+ }
// 4) attempt to load from source but continue on failure
result = source.loadClass(name);
+ }
// 5) search the local bundle
if (result == null)
result = findLocalClass(name);
@@ -505,6 +512,8 @@
* Finds the resource for a bundle. This method is used for delegation by the bundle's classloader.
*/
public URL findResource(String name) {
+ if (debug.DEBUG_LOADER)
+ Debug.println("BundleLoader[" + this + "].findResource(" + name + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if ((name.length() > 1) && (name.charAt(0) == '/')) /* if name has a leading slash */
name = name.substring(1); /* remove leading slash before search */
String pkgName = getResourcePackageName(name);
@@ -537,14 +546,22 @@
return result;
// 3) search the imported packages
PackageSource source = findImportedSource(pkgName, null);
- if (source != null)
+ if (source != null) {
+ if (debug.DEBUG_LOADER) {
+ Debug.println("BundleLoader[" + this + "] loading from import package: " + source); //$NON-NLS-1$ //$NON-NLS-2$
+ }
// 3) found import source terminate search at the source
return source.getResource(name);
+ }
// 4) search the required bundles
source = findRequiredSource(pkgName, null);
- if (source != null)
+ if (source != null) {
+ if (debug.DEBUG_LOADER) {
+ Debug.println("BundleLoader[" + this + "] loading from required bundle package: " + source); //$NON-NLS-1$ //$NON-NLS-2$
+ }
// 4) attempt to load from source but continue on failure
result = source.getResource(name);
+ }
// 5) search the local bundle
if (result == null)
result = findLocalResource(name);
@@ -615,15 +632,22 @@
// 3) search the imported packages
PackageSource source = findImportedSource(pkgName, null);
- if (source != null)
+ if (source != null) {
+ if (debug.DEBUG_LOADER) {
+ Debug.println("BundleLoader[" + this + "] loading from import package: " + source); //$NON-NLS-1$ //$NON-NLS-2$
+ }
// 3) found import source terminate search at the source
return compoundEnumerations(result, source.getResources(name));
+ }
// 4) search the required bundles
source = findRequiredSource(pkgName, null);
- if (source != null)
+ if (source != null) {
+ if (debug.DEBUG_LOADER) {
+ Debug.println("BundleLoader[" + this + "] loading from required bundle package: " + source); //$NON-NLS-1$ //$NON-NLS-2$
+ }
// 4) attempt to load from source but continue on failure
result = compoundEnumerations(result, source.getResources(name));
-
+ }
// 5) search the local bundle
// compound the required source results with the local ones
Enumeration<URL> localResults = findLocalResources(name);
@@ -773,7 +797,11 @@
* @return String
*/
public final String toString() {
- return wiring.getRevision().toString();
+ ModuleRevision revision = wiring.getRevision();
+ String name = revision.getSymbolicName();
+ if (name == null)
+ name = "unknown"; //$NON-NLS-1$
+ return name + '_' + revision.getVersion();
}
/**
@@ -1032,10 +1060,16 @@
private PackageSource findDynamicSource(String pkgName) {
if (!isExportedPackage(pkgName) && isDynamicallyImported(pkgName)) {
+ if (debug.DEBUG_LOADER) {
+ Debug.println("BundleLoader[" + this + "] attempting to resolve dynamic package: " + pkgName); //$NON-NLS-1$ //$NON-NLS-2$
+ }
ModuleRevision revision = wiring.getRevision();
ModuleWire dynamicWire = revision.getRevisions().getModule().getContainer().resolveDynamic(pkgName, revision);
if (dynamicWire != null) {
PackageSource source = createExportPackageSource(dynamicWire, null);
+ if (debug.DEBUG_LOADER) {
+ Debug.println("BundleLoader[" + this + "] using dynamic import source: " + source); //$NON-NLS-1$ //$NON-NLS-2$
+ }
synchronized (importedSources) {
importedSources.add(source);
}
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/ModuleClassLoader.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/ModuleClassLoader.java
index 36dc95b..c517585 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/ModuleClassLoader.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/ModuleClassLoader.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 IBM Corporation and others.
+ * Copyright (c) 2005, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -154,7 +154,7 @@
*/
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
if (getDebug().DEBUG_LOADER)
- Debug.println("BundleClassLoader[" + getBundleLoader() + "].loadClass(" + name + ")"); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
+ Debug.println("ModuleClassLoader[" + getBundleLoader() + "].loadClass(" + name + ")"); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
try {
// Just ask the delegate. This could result in findLocalClass(name) being called.
Class<?> clazz = getBundleLoader().findClass(name);
@@ -164,7 +164,7 @@
return (clazz);
} catch (Error e) {
if (getDebug().DEBUG_LOADER) {
- Debug.println("BundleClassLoader[" + getBundleLoader() + "].loadClass(" + name + ") failed."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Debug.println("ModuleClassLoader[" + getBundleLoader() + "].loadClass(" + name + ") failed."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Debug.printStackTrace(e);
}
throw e;
@@ -172,7 +172,7 @@
// If the class is not found do not try to look for it locally.
// The delegate would have already done that for us.
if (getDebug().DEBUG_LOADER) {
- Debug.println("BundleClassLoader[" + getBundleLoader() + "].loadClass(" + name + ") failed."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Debug.println("ModuleClassLoader[" + getBundleLoader() + "].loadClass(" + name + ") failed."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Debug.printStackTrace(e);
}
throw e;
@@ -195,7 +195,7 @@
*/
public URL getResource(String name) {
if (getDebug().DEBUG_LOADER) {
- Debug.println("BundleClassLoader[" + getBundleLoader() + "].getResource(" + name + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Debug.println("ModuleClassLoader[" + getBundleLoader() + "].getResource(" + name + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
URL url = getBundleLoader().findResource(name);
@@ -203,7 +203,7 @@
return (url);
if (getDebug().DEBUG_LOADER) {
- Debug.println("BundleClassLoader[" + getBundleLoader() + "].getResource(" + name + ") failed."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Debug.println("ModuleClassLoader[" + getBundleLoader() + "].getResource(" + name + ") failed."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
return (null);
@@ -225,12 +225,12 @@
*/
public Enumeration<URL> getResources(String name) throws IOException {
if (getDebug().DEBUG_LOADER) {
- Debug.println("BundleClassLoader[" + getBundleLoader() + "].getResources(" + name + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Debug.println("ModuleClassLoader[" + getBundleLoader() + "].getResources(" + name + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
Enumeration<URL> result = getBundleLoader().findResources(name);
if (getDebug().DEBUG_LOADER) {
if (result == null || !result.hasMoreElements()) {
- Debug.println("BundleClassLoader[" + getBundleLoader() + "].getResources(" + name + ") failed."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Debug.println("ModuleClassLoader[" + getBundleLoader() + "].getResources(" + name + ") failed."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
}
return result;
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/classpath/ClasspathManager.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/classpath/ClasspathManager.java
index 822435c..8bb2acc 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/classpath/ClasspathManager.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/classpath/ClasspathManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 IBM Corporation and others.
+ * Copyright (c) 2005, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -557,7 +557,7 @@
private Class<?> findClassImpl(String name, ClasspathEntry classpathEntry, List<ClassLoaderHook> hooks) {
if (debug.DEBUG_LOADER)
- Debug.println("BundleClassLoader[" + classpathEntry.getBundleFile() + "].findClassImpl(" + name + ")"); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
+ Debug.println("ModuleClassLoader[" + classloader.getBundleLoader() + " - " + classpathEntry.getBundleFile() + "].findClassImpl(" + name + ")"); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
String filename = name.replace('.', '/').concat(".class"); //$NON-NLS-1$
BundleEntry entry = classpathEntry.getBundleFile().getEntry(filename);
if (entry == null)
@@ -572,7 +572,7 @@
throw (LinkageError) new LinkageError("Error reading class bytes: " + name).initCause(e); //$NON-NLS-1$
}
if (debug.DEBUG_LOADER) {
- Debug.println(" read " + classbytes.length + " bytes from " + classpathEntry.getBundleFile() + "/" + filename); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Debug.println(" read " + classbytes.length + " bytes from " + classpathEntry.getBundleFile() + "!/" + filename); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Debug.println(" defining class " + name); //$NON-NLS-1$
}
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/sources/NullPackageSource.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/sources/NullPackageSource.java
index 77307b5..ef0c887f2 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/sources/NullPackageSource.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/sources/NullPackageSource.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2013 IBM Corporation and others.
+ * Copyright (c) 2003, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -35,10 +35,6 @@
return true;
}
- public String toString() {
- return id + " -> null"; //$NON-NLS-1$
- }
-
public Class<?> loadClass(String name) {
return null;
}
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/sources/PackageSource.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/sources/PackageSource.java
index 0205839..b54a40b 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/sources/PackageSource.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/sources/PackageSource.java
@@ -82,6 +82,25 @@
return false;
}
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append(id).append(" -> "); //$NON-NLS-1$
+ SingleSourcePackage[] suppliers = getSuppliers();
+ if (suppliers == null) {
+ return builder.append(String.valueOf(null)).toString();
+ }
+ builder.append('[');
+ for (int i = 0; i < suppliers.length; i++) {
+ if (i > 0) {
+ builder.append(',');
+ }
+ builder.append(suppliers[i].getLoader());
+ }
+ builder.append(']');
+ return builder.toString();
+ }
+
public abstract Collection<String> listResources(String path, String filePattern);
/**
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/sources/SingleSourcePackage.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/sources/SingleSourcePackage.java
index b77c6ce..40781e0 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/sources/SingleSourcePackage.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/sources/SingleSourcePackage.java
@@ -28,8 +28,8 @@
return new SingleSourcePackage[] {this};
}
- public String toString() {
- return id + " -> " + supplier; //$NON-NLS-1$
+ public BundleLoader getLoader() {
+ return supplier;
}
public Class<?> loadClass(String name) throws ClassNotFoundException {