Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Lippert2008-07-30 20:28:31 +0000
committerMartin Lippert2008-07-30 20:28:31 +0000
commitea9ee2cb6c1ca120145aa1deff3e3b82440fb302 (patch)
tree0a41347c73e12f85c75e1833d6b7214ed5ce0c36
parenta26d88054080cef5fba4a5c37c988cbf306820a0 (diff)
downloadrt.equinox.bundles-ea9ee2cb6c1ca120145aa1deff3e3b82440fb302.tar.gz
rt.equinox.bundles-ea9ee2cb6c1ca120145aa1deff3e3b82440fb302.tar.xz
rt.equinox.bundles-ea9ee2cb6c1ca120145aa1deff3e3b82440fb302.zip
Bug 216398 - [aspects] add handling of bundle and aspect versions to standard caching service, bugfixes for fragments and non-deterministic generation of namespace key
-rw-r--r--bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/OSGiWeavingAdaptor.java12
-rw-r--r--bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/OSGiWeavingContext.java242
2 files changed, 148 insertions, 106 deletions
diff --git a/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/OSGiWeavingAdaptor.java b/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/OSGiWeavingAdaptor.java
index 6b4a5914c..9534299f0 100644
--- a/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/OSGiWeavingAdaptor.java
+++ b/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/OSGiWeavingAdaptor.java
@@ -17,6 +17,8 @@ package org.eclipse.equinox.weaving.aspectj.loadtime;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
@@ -162,6 +164,16 @@ public class OSGiWeavingAdaptor extends ClassLoaderWeavingAdaptor {
private void parseDefinitionsFromRequiredBundles(List definitions,
Set seenBefore) {
Bundle[] bundles = weavingContext.getBundles();
+
+ Arrays.sort(bundles, new Comparator() {
+
+ public int compare(Object arg0, Object arg1) {
+ long bundleId1 = ((Bundle) arg0).getBundleId();
+ long bundleId2 = ((Bundle) arg1).getBundleId();
+ return (int) (bundleId1 - bundleId2);
+ }
+ });
+
for (int i = 0; i < bundles.length; i++) {
parseDefinitionFromRequiredBundle(bundles[i], definitions,
seenBefore);
diff --git a/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/OSGiWeavingContext.java b/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/OSGiWeavingContext.java
index 881cb3f7f..718a8d62c 100644
--- a/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/OSGiWeavingContext.java
+++ b/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/OSGiWeavingContext.java
@@ -31,114 +31,144 @@ import org.eclipse.osgi.service.resolver.State;
import org.osgi.framework.Bundle;
public class OSGiWeavingContext extends DefaultWeavingContext {
-
- private final State resolverState;
- private final Bundle bundle;
- private final BundleDescription bundleDescription;
- private final SupplementerRegistry supplementerRegistry;
-
- public OSGiWeavingContext(ClassLoader loader, Bundle bundle, State state, BundleDescription bundleDescription, SupplementerRegistry supplementerRegistry) {
- super(loader);
- this.bundle = bundle;
- this.bundleDescription = bundleDescription;
- this.resolverState = state;
- this.supplementerRegistry = supplementerRegistry;
- if (WeavingServicePlugin.DEBUG) System.out.println("- WeavingContext.WeavingContext() locader=" + loader + ", bundle=" + bundle.getSymbolicName());
- }
-
- public String getBundleIdFromURL(URL url) {
- return resolverState.getBundle(Integer.parseInt(url.getHost())).getSymbolicName();
- }
-
+
+ private final State resolverState;
+
+ private final Bundle bundle;
+
+ private final BundleDescription bundleDescription;
+
+ private final SupplementerRegistry supplementerRegistry;
+
+ public OSGiWeavingContext(ClassLoader loader, Bundle bundle, State state,
+ BundleDescription bundleDescription,
+ SupplementerRegistry supplementerRegistry) {
+ super(loader);
+ this.bundle = bundle;
+ this.bundleDescription = bundleDescription;
+ this.resolverState = state;
+ this.supplementerRegistry = supplementerRegistry;
+ if (WeavingServicePlugin.DEBUG)
+ System.out.println("- WeavingContext.WeavingContext() locader="
+ + loader + ", bundle=" + bundle.getSymbolicName());
+ }
+
+ public String getBundleIdFromURL(URL url) {
+ return resolverState.getBundle(Integer.parseInt(url.getHost()))
+ .getSymbolicName();
+ }
+
public String getBundleVersionFromURL(URL url) {
- return resolverState.getBundle(Integer.parseInt(url.getHost())).getVersion().toString();
+ return resolverState.getBundle(Integer.parseInt(url.getHost()))
+ .getVersion().toString();
+ }
+
+ public String toString() {
+ return getClass().getName() + "[" + bundleDescription.getSymbolicName()
+ + "]";
}
- public String toString(){
- return getClass().getName() + "[" + bundleDescription.getSymbolicName() + "]";
- }
-
- public String getClassLoaderName() {
- return bundleDescription.getSymbolicName();
- }
-
- public String getFile(URL url) {
- return getBundleIdFromURL(url) + url.getFile();
- }
-
- public String getId () {
- return bundleDescription.getSymbolicName();
- }
-
- public Enumeration getResources(String name) throws IOException {
- Enumeration result = super.getResources(name);
-
- if (name.endsWith("aop.xml")){
- Vector modified =new Vector();
- BundleSpecification[] requires = bundleDescription.getRequiredBundles();
- BundleDescription[] fragments = bundleDescription.getFragments();
-
- while(result.hasMoreElements()){
- URL xml = (URL) result.nextElement();
- String resourceBundleName = getBundleIdFromURL(xml);
-
- if (bundleDescription.getSymbolicName().equals(resourceBundleName)){
- modified.add(xml);
- continue;
- }
-
- for (int i=0; i<requires.length; i++){
- BundleSpecification r = requires[i];
- if (r.getName().equals(resourceBundleName)){
- modified.add(xml);
- continue;
- }
- }
-
- for (int i = 0; i < fragments.length; i++) {
- BundleSpecification[] fragmentRequires = fragments[i].getRequiredBundles();
- for (int j=0; j<fragmentRequires.length; j++){
- BundleSpecification r = fragmentRequires[j];
- if (r.getName().equals(resourceBundleName)){
- modified.add(xml);
- continue;
- }
- }
- }
- }
-
- result=modified.elements();
- }
- return result;
- }
-
- public List getDefinitions(ClassLoader loader, WeavingAdaptor adaptor) {
- List definitions = ((OSGiWeavingAdaptor)adaptor).parseDefinitionsForBundle();
- return definitions;
- }
-
- public Bundle[] getBundles() {
- Set bundles = new HashSet();
-
- // the bundle this context belongs to should be used
- bundles.add(this.bundle);
-
- // add required bundles
- if (this.bundle.getBundleContext() != null) {
- BundleDescription[] resolvedRequires = this.bundleDescription.getResolvedRequires();
- for (int i = 0; i < resolvedRequires.length; i++) {
- Bundle requiredBundle = this.bundle.getBundleContext().getBundle(resolvedRequires[i].getBundleId());
- if (requiredBundle != null) {
- bundles.add(requiredBundle);
- }
- }
- }
-
- // add supplementers
- Bundle[] supplementers = this.supplementerRegistry.getSupplementers(this.bundle);
- bundles.addAll(Arrays.asList(supplementers));
-
- return (Bundle[]) bundles.toArray(new Bundle[bundles.size()]);
- }
+ public String getClassLoaderName() {
+ return bundleDescription.getSymbolicName();
+ }
+
+ public String getFile(URL url) {
+ return getBundleIdFromURL(url) + url.getFile();
+ }
+
+ public String getId() {
+ return bundleDescription.getSymbolicName();
+ }
+
+ public Enumeration getResources(String name) throws IOException {
+ Enumeration result = super.getResources(name);
+
+ if (name.endsWith("aop.xml")) {
+ Vector modified = new Vector();
+ BundleSpecification[] requires = bundleDescription
+ .getRequiredBundles();
+ BundleDescription[] fragments = bundleDescription.getFragments();
+
+ while (result.hasMoreElements()) {
+ URL xml = (URL) result.nextElement();
+ String resourceBundleName = getBundleIdFromURL(xml);
+
+ if (bundleDescription.getSymbolicName().equals(
+ resourceBundleName)) {
+ modified.add(xml);
+ continue;
+ }
+
+ for (int i = 0; i < requires.length; i++) {
+ BundleSpecification r = requires[i];
+ if (r.getName().equals(resourceBundleName)) {
+ modified.add(xml);
+ continue;
+ }
+ }
+
+ for (int i = 0; i < fragments.length; i++) {
+ BundleSpecification[] fragmentRequires = fragments[i]
+ .getRequiredBundles();
+ for (int j = 0; j < fragmentRequires.length; j++) {
+ BundleSpecification r = fragmentRequires[j];
+ if (r.getName().equals(resourceBundleName)) {
+ modified.add(xml);
+ continue;
+ }
+ }
+ }
+ }
+
+ result = modified.elements();
+ }
+ return result;
+ }
+
+ public List getDefinitions(ClassLoader loader, WeavingAdaptor adaptor) {
+ List definitions = ((OSGiWeavingAdaptor) adaptor)
+ .parseDefinitionsForBundle();
+ return definitions;
+ }
+
+ public Bundle[] getBundles() {
+ Set bundles = new HashSet();
+
+ // the bundle this context belongs to should be used
+ bundles.add(this.bundle);
+
+ // add required bundles
+ if (this.bundle.getBundleContext() != null) {
+ BundleDescription[] resolvedRequires = this.bundleDescription
+ .getResolvedRequires();
+ for (int i = 0; i < resolvedRequires.length; i++) {
+ Bundle requiredBundle = this.bundle.getBundleContext()
+ .getBundle(resolvedRequires[i].getBundleId());
+ if (requiredBundle != null) {
+ bundles.add(requiredBundle);
+ }
+ }
+ }
+
+ // add fragment bundles
+ if (this.bundle.getBundleContext() != null) {
+ BundleDescription[] fragments = this.bundleDescription
+ .getFragments();
+ for (int i = 0; i < fragments.length; i++) {
+ Bundle fragmentBundle = this.bundle.getBundleContext()
+ .getBundle(fragments[i].getBundleId());
+ if (fragmentBundle != null) {
+ bundles.add(fragmentBundle);
+ }
+ }
+ }
+
+ // add supplementers
+ Bundle[] supplementers = this.supplementerRegistry
+ .getSupplementers(this.bundle);
+ bundles.addAll(Arrays.asList(supplementers));
+
+ return (Bundle[]) bundles.toArray(new Bundle[bundles.size()]);
+ }
}

Back to the top