Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/service/weaving/SupplementerRegistry.java103
-rw-r--r--bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/AspectJAdaptorFactory.java41
-rw-r--r--bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AspectJHook.java8
-rw-r--r--bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/SupplementBundleListener.java12
4 files changed, 99 insertions, 65 deletions
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/service/weaving/SupplementerRegistry.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/service/weaving/SupplementerRegistry.java
index 213da49ac..481b82a79 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/service/weaving/SupplementerRegistry.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/service/weaving/SupplementerRegistry.java
@@ -14,7 +14,6 @@
package org.eclipse.equinox.service.weaving;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
@@ -100,23 +99,17 @@ public class SupplementerRegistry {
.add("org.eclipse.equinox.simpleconfigurator");
}
- public void addSupplementedBundle(final Bundle supplementedBundle,
- final List supplementers) {
- for (final Iterator iterator = supplementers.iterator(); iterator
- .hasNext();) {
- final String supplementersName = (String) iterator.next();
- if (this.supplementers.containsKey(supplementersName)) {
- final Supplementer supplementer = (Supplementer) this.supplementers
- .get(supplementersName);
- supplementer.addSupplementedBundle(supplementedBundle);
- }
- }
+ public void addBundle(final Bundle bundle) {
+ // First analyze which supplementers already exists for this bundle
+ addSupplementedBundle(bundle);
+
+ // Second analyze if this bundle itself is a supplementer
+ addSupplementer(bundle, true);
}
- public void addSupplementer(final Bundle bundle) {
- final Dictionary manifest = bundle.getHeaders();
+ public void addSupplementedBundle(final Bundle bundle) {
try {
- // First analyze which supplementers already exists for this bundle
+ final Dictionary manifest = bundle.getHeaders();
final ManifestElement[] imports = ManifestElement.parseHeader(
Constants.IMPORT_PACKAGE, (String) manifest
.get(Constants.IMPORT_PACKAGE));
@@ -128,8 +121,13 @@ public class SupplementerRegistry {
if (supplementers.size() > 0) {
this.addSupplementedBundle(bundle, supplementers);
}
+ } catch (final BundleException e) {
+ }
+ }
- // Second analyze if this bundle itself is a supplementer
+ public void addSupplementer(final Bundle bundle, final boolean updateBundles) {
+ try {
+ final Dictionary manifest = bundle.getHeaders();
final ManifestElement[] supplementBundle = ManifestElement
.parseHeader(SUPPLEMENT_BUNDLE, (String) manifest
.get(SUPPLEMENT_BUNDLE));
@@ -148,23 +146,16 @@ public class SupplementerRegistry {
this.supplementers.put(bundle.getSymbolicName(),
newSupplementer);
- resupplementInstalledBundles(newSupplementer);
+ if (updateBundles) {
+ resupplementInstalledBundles(newSupplementer);
+ }
}
} catch (final BundleException e) {
}
}
- public Set getSupplementedBundles() {
- final Set supplementedBundles = new HashSet();
- final Iterator supplementersIterator = supplementers.values()
- .iterator();
- while (supplementersIterator.hasNext()) {
- final Supplementer supplementer = (Supplementer) supplementersIterator
- .next();
- supplementedBundles.addAll(Arrays.asList(supplementer
- .getSupplementedBundles()));
- }
- return supplementedBundles;
+ public PackageAdmin getPackageAdmin() {
+ return packageAdmin;
}
public Bundle[] getSupplementers(final Bundle bundle) {
@@ -204,15 +195,7 @@ public class SupplementerRegistry {
return result;
}
- public void removeSupplementedBundle(final Bundle bundle) {
- for (final Iterator iterator = this.supplementers.values().iterator(); iterator
- .hasNext();) {
- final Supplementer supplementer = (Supplementer) iterator.next();
- supplementer.removeSupplementedBundle(bundle);
- }
- }
-
- public void removeSupplementer(final Bundle bundle) {
+ public void removeBundle(final Bundle bundle) {
// if this bundle is itself supplemented by others, remove the bundle from those lists
removeSupplementedBundle(bundle);
@@ -252,12 +235,31 @@ public class SupplementerRegistry {
+ bundle.getSymbolicName());
try {
+ final int initialstate = (bundle.getState() & (Bundle.ACTIVE | Bundle.STARTING));
+ if (initialstate != 0
+ && packageAdmin != null
+ && packageAdmin.getBundleType(bundle) != PackageAdmin.BUNDLE_TYPE_FRAGMENT) {
+ bundle.stop(Bundle.STOP_TRANSIENT);
+ }
bundle.update();
} catch (final BundleException e) {
e.printStackTrace();
}
}
+ private void addSupplementedBundle(final Bundle supplementedBundle,
+ final List supplementers) {
+ for (final Iterator iterator = supplementers.iterator(); iterator
+ .hasNext();) {
+ final String supplementersName = (String) iterator.next();
+ if (this.supplementers.containsKey(supplementersName)) {
+ final Supplementer supplementer = (Supplementer) this.supplementers
+ .get(supplementersName);
+ supplementer.addSupplementedBundle(supplementedBundle);
+ }
+ }
+ }
+
private boolean isSupplementerMatching(final String symbolicName,
final ManifestElement[] imports, final ManifestElement[] exports,
final Supplementer supplementer) {
@@ -274,6 +276,14 @@ public class SupplementerRegistry {
return false;
}
+ private void removeSupplementedBundle(final Bundle bundle) {
+ for (final Iterator iterator = this.supplementers.values().iterator(); iterator
+ .hasNext();) {
+ final Supplementer supplementer = (Supplementer) iterator.next();
+ supplementer.removeSupplementedBundle(bundle);
+ }
+ }
+
private void resupplementInstalledBundles(final Supplementer supplementer) {
final Bundle[] installedBundles = context.getBundles();
@@ -300,23 +310,8 @@ public class SupplementerRegistry {
if (isSupplementerMatching(bundle.getSymbolicName(), imports,
exports, supplementer)) {
- boolean alreadyRequired = false;
- final ManifestElement[] requires = ManifestElement
- .parseHeader(Constants.REQUIRE_BUNDLE,
- (String) manifest
- .get(Constants.REQUIRE_BUNDLE));
- if (requires != null) {
- for (int j = 0; j < requires.length; j++) {
- if (requires[j].getValue().equals(
- supplementer.getSymbolicName())) {
- alreadyRequired = true;
- }
- }
- }
-
- if (!alreadyRequired) {
- updateInstalledBundle(bundle);
- }
+
+ updateInstalledBundle(bundle);
}
} catch (final BundleException e) {
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/AspectJAdaptorFactory.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/AspectJAdaptorFactory.java
index 8fdd6c3e3..1acd272fe 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/AspectJAdaptorFactory.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/adaptors/AspectJAdaptorFactory.java
@@ -36,6 +36,7 @@ import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.service.startlevel.StartLevel;
import org.osgi.util.tracker.ServiceTracker;
public class AspectJAdaptorFactory {
@@ -43,7 +44,9 @@ public class AspectJAdaptorFactory {
private static final Collection IGNORE_WEAVING_SERVICE_BUNDLES = Arrays
.asList(new String[] { "org.eclipse.equinox.weaving.aspectj",
"org.eclipse.equinox.caching",
- "org.eclipse.equinox.caching.j9" });
+ "org.eclipse.equinox.caching.j9",
+ "org.eclipse.update.configurator",
+ "org.eclipse.equinox.simpleconfigurator" });
private BundleContext bundleContext;
@@ -51,6 +54,8 @@ public class AspectJAdaptorFactory {
private PackageAdmin packageAdminService;
+ private StartLevel startLevelService;
+
private SupplementerRegistry supplementerRegistry;
private ServiceListener weavingServiceListener;
@@ -103,6 +108,9 @@ public class AspectJAdaptorFactory {
this.bundleContext = context;
this.supplementerRegistry = supplementerRegistry;
+ initializePackageAdminService(context);
+ initializeStartLevelService(context);
+
// Service tracker for weaving service
weavingServiceTracker = new ServiceTracker(context,
IWeavingService.class.getName(), null);
@@ -123,6 +131,9 @@ public class AspectJAdaptorFactory {
final Bundle bundle = (Bundle) entry.getKey();
if (entry.getValue() == null) {
bundleEntries.remove();
+ System.err
+ .println("bundle update because of weaving service start: "
+ + bundle.getSymbolicName());
supplementerRegistry
.updateInstalledBundle(bundle);
if (Debug.DEBUG_WEAVE)
@@ -132,7 +143,10 @@ public class AspectJAdaptorFactory {
}
}
}
- if (event.getType() == ServiceEvent.UNREGISTERING) {
+ if (event.getType() == ServiceEvent.UNREGISTERING
+ && startLevelService != null
+ && startLevelService.getStartLevel() > 0) {
+
final Iterator bundleEntries = weavingServices.entrySet()
.iterator();
synchronized (weavingServices) {
@@ -141,6 +155,9 @@ public class AspectJAdaptorFactory {
final Bundle bundle = (Bundle) entry.getKey();
if (entry.getValue() != null) {
bundleEntries.remove();
+ System.err
+ .println("bundle update because of weaving service stop: "
+ + bundle.getSymbolicName());
supplementerRegistry
.updateInstalledBundle(bundle);
if (Debug.DEBUG_WEAVE)
@@ -165,8 +182,6 @@ public class AspectJAdaptorFactory {
cachingServiceTracker.open();
if (Debug.DEBUG_CACHE)
Debug.println("> Opened service tracker for caching service.");
-
- initializePackageAdminService(context);
}
protected ICachingService getCachingService(final BaseClassLoader loader,
@@ -242,4 +257,22 @@ public class AspectJAdaptorFactory {
.println("< AspectJAdaptorFactory.initializePackageAdminService() "
+ packageAdminService);
}
+
+ private void initializeStartLevelService(final BundleContext context) {
+ if (Debug.DEBUG_GENERAL)
+ Debug
+ .println("> AspectJAdaptorFactory.initializeStartLevelService() context="
+ + context);
+
+ final ServiceReference ref = context
+ .getServiceReference(StartLevel.class.getName());
+ if (ref != null) {
+ startLevelService = (StartLevel) context.getService(ref);
+ }
+
+ if (Debug.DEBUG_GENERAL)
+ Debug
+ .println("< AspectJAdaptorFactory.initializeStartLevelService() "
+ + startLevelService);
+ }
}
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AspectJHook.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AspectJHook.java
index a4b1c0206..83114b901 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AspectJHook.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/AspectJHook.java
@@ -200,15 +200,17 @@ public class AspectJHook extends AbstractAspectJHook {
context.addBundleListener(new SupplementBundleListener(
supplementerRegistry));
- // re-build supplementer registry state for installed bundles
+ // final re-build supplementer final registry state for final installed bundles
final Bundle[] installedBundles = context.getBundles();
for (int i = 0; i < installedBundles.length; i++) {
- supplementerRegistry.addSupplementer(installedBundles[i]);
+ supplementerRegistry.addSupplementer(installedBundles[i], false);
+ }
+ for (int i = 0; i < installedBundles.length; i++) {
+ supplementerRegistry.addSupplementedBundle(installedBundles[i]);
}
if (Debug.DEBUG_GENERAL)
Debug.println("< AspectJHook.initialize() adaptorFactory="
+ adaptorFactory);
}
-
}
diff --git a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/SupplementBundleListener.java b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/SupplementBundleListener.java
index 006625352..f64c5106e 100644
--- a/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/SupplementBundleListener.java
+++ b/bundles/org.eclipse.equinox.weaving.hook/src/org/eclipse/equinox/weaving/hooks/SupplementBundleListener.java
@@ -28,12 +28,16 @@ public class SupplementBundleListener implements SynchronousBundleListener {
public void bundleChanged(final BundleEvent event) {
final Bundle bundle = event.getBundle();
if (event.getType() == BundleEvent.INSTALLED) {
- supplementerRegistry.addSupplementer(bundle);
+ supplementerRegistry.addBundle(bundle);
} else if (event.getType() == BundleEvent.UNINSTALLED) {
- supplementerRegistry.removeSupplementer(bundle);
+ supplementerRegistry.removeBundle(bundle);
} else if (event.getType() == BundleEvent.UPDATED) {
- supplementerRegistry.removeSupplementer(bundle);
- supplementerRegistry.addSupplementer(bundle);
+ System.err.println("bundle update: "
+ + event.getBundle().getBundleId());
+
+ supplementerRegistry.removeBundle(bundle);
+ supplementerRegistry.addBundle(bundle);
+ // supplementerRegistry.getPackageAdmin().refreshPackages(null);
}
}

Back to the top