Bug 405251 - [enterprise] Problems with deploying persistence applications - fix for supporting the persistence weaving
diff --git a/org.eclipse.virgo.web.enterprise.services.accessor/src/main/java/org/eclipse/virgo/web/enterprise/services/accessor/WebAppBundleClassLoaderDelegateHook.java b/org.eclipse.virgo.web.enterprise.services.accessor/src/main/java/org/eclipse/virgo/web/enterprise/services/accessor/WebAppBundleClassLoaderDelegateHook.java
index 07cc6a0..72be765 100755
--- a/org.eclipse.virgo.web.enterprise.services.accessor/src/main/java/org/eclipse/virgo/web/enterprise/services/accessor/WebAppBundleClassLoaderDelegateHook.java
+++ b/org.eclipse.virgo.web.enterprise.services.accessor/src/main/java/org/eclipse/virgo/web/enterprise/services/accessor/WebAppBundleClassLoaderDelegateHook.java
@@ -54,6 +54,8 @@
private final Map<Bundle, ClassLoader> implBundlesClassloaders = new ConcurrentHashMap<Bundle, ClassLoader>();
private final Map<Bundle, Set<String>> webAppBundles = new ConcurrentHashMap<Bundle, Set<String>>();
+
+ private final Set<Bundle> postFindApiBundles = new CopyOnWriteArraySet<Bundle>();
@Override
public Class<?> postFindClass(String name, BundleClassLoader bcl, BundleData bd) throws ClassNotFoundException {
@@ -62,8 +64,8 @@
enter();
Bundle bundle = bd.getBundle();
-
- if (this.implBundles.contains(bundle)) {
+
+ if (this.implBundles.contains(bundle)) {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
if (tccl != null) {
try {
@@ -80,11 +82,43 @@
}
}
}
- }
+ }
} finally {
exit();
}
}
+
+ if (shouldEnter(MAX_API_SEARCH_DEPTH)) {
+ try {
+ enter();
+ Bundle bundle = bd.getBundle();
+
+ if (this.webAppBundles.containsKey(bundle)) {
+ for (Bundle postFindApiProvider : postFindApiBundles) {
+ try {
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Post find api for class " + name
+ + " from bundle "
+ + bundle.getSymbolicName()
+ + ". Trying to load it with bundle "
+ + postFindApiProvider.getSymbolicName());
+ }
+ return postFindApiProvider.loadClass(name);
+ } catch (ClassNotFoundException e) {
+ // keep moving through the bundles
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Exception occurred while trying to find (post api) class ["
+ + name
+ + "]. Exception message: "
+ + e.getMessage());
+ }
+ }
+ }
+ }
+ } finally {
+ exit();
+ }
+ }
return null;
}
@@ -241,7 +275,14 @@
LOGGER.debug(bundle + "was added to API bundles.");
}
}
-
+
+ void addPostApiBundle(Bundle bundle) {
+ this.postFindApiBundles.add(bundle);
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug(bundle + "was added to post API bundles.");
+ }
+ }
+
void addImplBundle(Bundle bundle) {
this.implBundles.add(bundle);
if (LOGGER.isDebugEnabled()) {
@@ -268,7 +309,14 @@
LOGGER.debug(bundle + "was removed from Impl bundles.");
}
}
-
+
+ void removePostApiBundle(Bundle bundle) {
+ this.postFindApiBundles.remove(bundle);
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug(bundle + "was added to post API bundles.");
+ }
+ }
+
void addWebAppBundle(Bundle bundle) {
this.webAppBundles.put(bundle, cacheRequiredCapabilities(bundle));
}
@@ -375,5 +423,13 @@
Set<Bundle> getImplBundles() {
return this.implBundles;
}
+
+ private String getClassPackage(String className) {
+ int packageNameEndsIndex = className.lastIndexOf(".");
+ if(packageNameEndsIndex != -1 && packageNameEndsIndex != className.length() -1) {
+ return className.substring(0, packageNameEndsIndex);
+ }
+ return "";
+ }
}
diff --git a/org.eclipse.virgo.web.enterprise.services.accessor/src/main/java/org/eclipse/virgo/web/enterprise/services/accessor/WebAppBundleTrackerCustomizer.java b/org.eclipse.virgo.web.enterprise.services.accessor/src/main/java/org/eclipse/virgo/web/enterprise/services/accessor/WebAppBundleTrackerCustomizer.java
index 9985601..434bc4a 100755
--- a/org.eclipse.virgo.web.enterprise.services.accessor/src/main/java/org/eclipse/virgo/web/enterprise/services/accessor/WebAppBundleTrackerCustomizer.java
+++ b/org.eclipse.virgo.web.enterprise.services.accessor/src/main/java/org/eclipse/virgo/web/enterprise/services/accessor/WebAppBundleTrackerCustomizer.java
@@ -34,6 +34,10 @@
static final String API_BUNDLES = "api.bundles";
static final String IMPL_BUNDLES = "impl.bundles";
+
+ static final String POST_API_BUNDLES = "post.api.bundles";
+
+ static final String POST_API_PACKAGES = "post.api.packages";
private static final String COMMA_SEPARATOR = ",";
@@ -79,6 +83,12 @@
*/
@Deprecated
private final Map<String, VersionRange> implBundles;
+
+ /**
+ * @deprecated Not supported
+ */
+ @Deprecated
+ private final Map<String, VersionRange> postApiBundles;
public WebAppBundleTrackerCustomizer(WebAppBundleClassLoaderDelegateHook wabClassLoaderDelegateHook) {
String bundlesForJarScanner = System.getProperty("org.eclipse.virgo.jarscanner.bundles");
@@ -90,6 +100,8 @@
this.wabClassLoaderDelegateHook = wabClassLoaderDelegateHook;
this.apiBundles = Collections.unmodifiableMap(getBundles(System.getProperty(API_BUNDLES)));
this.implBundles = Collections.unmodifiableMap(getBundles(System.getProperty(IMPL_BUNDLES)));
+ this.postApiBundles = Collections.unmodifiableMap(getBundles(System.getProperty(POST_API_BUNDLES)));
+
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Predefined api bundles added to the tracker " + this.apiBundles);
LOGGER.debug("Predefined impl bundles added to the tracker " + this.implBundles);
@@ -109,6 +121,10 @@
if (isImplBundle(bundle)) {
this.wabClassLoaderDelegateHook.addImplBundle(bundle);
}
+
+ if(postApiBundles.containsKey(bundle.getSymbolicName())) {
+ this.wabClassLoaderDelegateHook.addPostApiBundle(bundle);
+ }
processExposeAdditionalAPIHeader(bundle);