Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Lippert2008-11-13 20:12:16 +0000
committerMartin Lippert2008-11-13 20:12:16 +0000
commit47089d25caeea036b060c5b06ddc38572c713e02 (patch)
tree9f3d9c938807db1af50834d47039c091807f25bb
parentaafd562f5048bc1048c3ef2c0af9d2ce9d71e8a5 (diff)
downloadrt.equinox.bundles-47089d25caeea036b060c5b06ddc38572c713e02.tar.gz
rt.equinox.bundles-47089d25caeea036b060c5b06ddc38572c713e02.tar.xz
rt.equinox.bundles-47089d25caeea036b060c5b06ddc38572c713e02.zip
Bug 249613 - [aspects] Deadlock when using equinox aspects and spring dm extender, parsing of aspect definition files done when bundles are resolvedparsing-on-resolve
-rw-r--r--bundles/org.eclipse.equinox.weaving.aspectj/.settings/org.eclipse.jdt.core.prefs12
-rw-r--r--bundles/org.eclipse.equinox.weaving.aspectj/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/WeavingServicePlugin.java11
-rw-r--r--bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/AspectDefinitionRegistry.java91
-rw-r--r--bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/OSGiWeavingAdaptor.java80
-rw-r--r--bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/OSGiWeavingContext.java24
6 files changed, 137 insertions, 83 deletions
diff --git a/bundles/org.eclipse.equinox.weaving.aspectj/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.weaving.aspectj/.settings/org.eclipse.jdt.core.prefs
index 7af86d307..9d6dac1e7 100644
--- a/bundles/org.eclipse.equinox.weaving.aspectj/.settings/org.eclipse.jdt.core.prefs
+++ b/bundles/org.eclipse.equinox.weaving.aspectj/.settings/org.eclipse.jdt.core.prefs
@@ -1,22 +1,22 @@
-#Mon Aug 04 14:34:18 CEST 2008
+#Tue Nov 11 23:48:19 CET 2008
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.3
+org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=ignore
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=ignore
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
@@ -80,7 +80,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
-org.eclipse.jdt.core.compiler.source=1.3
+org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
diff --git a/bundles/org.eclipse.equinox.weaving.aspectj/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.weaving.aspectj/META-INF/MANIFEST.MF
index e59655dc0..27aa9a2fe 100644
--- a/bundles/org.eclipse.equinox.weaving.aspectj/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.weaving.aspectj/META-INF/MANIFEST.MF
@@ -12,4 +12,4 @@ Import-Package: org.aspectj.weaver,
org.eclipse.osgi.service.debug,
org.eclipse.osgi.service.resolver,
org.osgi.framework
-Bundle-RequiredExecutionEnvironment: J2SE-1.3
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/WeavingServicePlugin.java b/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/WeavingServicePlugin.java
index d03e8debf..b1580b745 100644
--- a/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/WeavingServicePlugin.java
+++ b/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/WeavingServicePlugin.java
@@ -15,6 +15,7 @@ package org.eclipse.equinox.weaving.aspectj;
import java.util.Properties;
import org.eclipse.equinox.service.weaving.IWeavingService;
+import org.eclipse.equinox.weaving.aspectj.loadtime.AspectDefinitionRegistry;
import org.eclipse.osgi.service.debug.DebugOptions;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -33,6 +34,8 @@ public class WeavingServicePlugin implements BundleActivator {
//The shared instance.
private static WeavingServicePlugin plugin;
+ private AspectDefinitionRegistry aspectDefinitionRegistry;
+
private BundleContext context;
/**
@@ -50,6 +53,10 @@ public class WeavingServicePlugin implements BundleActivator {
return plugin;
}
+ public AspectDefinitionRegistry getAspectDefinitionRegistry() {
+ return aspectDefinitionRegistry;
+ }
+
/**
* @return The bundle context of the weaving service bundle or null, of
* bundle is not started
@@ -64,6 +71,10 @@ public class WeavingServicePlugin implements BundleActivator {
public void start(final BundleContext context) throws Exception {
this.context = context;
+ this.aspectDefinitionRegistry = new AspectDefinitionRegistry();
+ context.addBundleListener(this.aspectDefinitionRegistry);
+ this.aspectDefinitionRegistry.initialize(context.getBundles());
+
loadOptions(context);
if (verbose)
System.err
diff --git a/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/AspectDefinitionRegistry.java b/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/AspectDefinitionRegistry.java
new file mode 100644
index 000000000..42cc6eb2c
--- /dev/null
+++ b/bundles/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/AspectDefinitionRegistry.java
@@ -0,0 +1,91 @@
+
+package org.eclipse.equinox.weaving.aspectj.loadtime;
+
+import java.net.URL;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.aspectj.weaver.loadtime.definition.Definition;
+import org.aspectj.weaver.loadtime.definition.DocumentParser;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.SynchronousBundleListener;
+
+public class AspectDefinitionRegistry implements SynchronousBundleListener {
+
+ private static final String AOP_CONTEXT_LOCATION_HEADER = "Eclipse-AspectContext"; //$NON-NLS-1$
+
+ private static final String DEFAULT_AOP_CONTEXT_LOCATION = "META-INF/aop.xml"; //$NON-NLS-1$
+
+ private final Map<Bundle, Definition> aspectDefinitions;
+
+ /**
+ * Create a registry to manage aspect definition files
+ */
+ public AspectDefinitionRegistry() {
+ this.aspectDefinitions = new ConcurrentHashMap<Bundle, Definition>();
+ }
+
+ /**
+ * @see org.osgi.framework.BundleListener#bundleChanged(org.osgi.framework.BundleEvent)
+ */
+ public void bundleChanged(final BundleEvent event) {
+ if (event.getType() == BundleEvent.RESOLVED) {
+ bundleResolved(event.getBundle());
+ } else if (event.getType() == BundleEvent.UNRESOLVED) {
+ bundleUnresolved(event.getBundle());
+ }
+ }
+
+ public void bundleResolved(final Bundle bundle) {
+ if (!this.aspectDefinitions.containsKey(bundle)) {
+ this.aspectDefinitions.put(bundle,
+ parseDefinitionFromRequiredBundle(bundle));
+ }
+ }
+
+ public void bundleUnresolved(final Bundle bundle) {
+ this.aspectDefinitions.remove(bundle);
+ }
+
+ public Definition getAspectDefinition(final Bundle bundle) {
+ return this.aspectDefinitions.get(bundle);
+ }
+
+ public String getDefinitionLocation(final Bundle bundle) {
+ String aopContextHeader = (String) bundle.getHeaders().get(
+ AOP_CONTEXT_LOCATION_HEADER);
+ if (aopContextHeader != null) {
+ aopContextHeader = aopContextHeader.trim();
+ return aopContextHeader;
+ }
+
+ return DEFAULT_AOP_CONTEXT_LOCATION;
+ }
+
+ public void initialize(final Bundle[] bundles) {
+ for (final Bundle bundle : bundles) {
+ final int state = bundle.getState();
+ if (state != Bundle.INSTALLED && state != Bundle.UNINSTALLED) {
+ final Definition aspectDefinitions = parseDefinitionFromRequiredBundle(bundle);
+ if (aspectDefinitions != null) {
+ this.aspectDefinitions.put(bundle, aspectDefinitions);
+ }
+ }
+ }
+ }
+
+ public Definition parseDefinitionFromRequiredBundle(final Bundle bundle) {
+ try {
+ final URL aopXmlDef = bundle
+ .getEntry(getDefinitionLocation(bundle));
+ if (aopXmlDef != null) {
+ return DocumentParser.parse(aopXmlDef);
+ }
+ } catch (final Exception e) {
+ // warn("parse definitions failed", e);
+ }
+ return null;
+ }
+
+}
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 6feba2281..c15d4b4f7 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
@@ -15,18 +15,15 @@
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;
import java.util.Set;
-import java.util.StringTokenizer;
import org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor;
-import org.aspectj.weaver.loadtime.definition.DocumentParser;
+import org.aspectj.weaver.loadtime.definition.Definition;
import org.eclipse.equinox.weaving.aspectj.WeavingServicePlugin;
import org.osgi.framework.Bundle;
@@ -36,10 +33,6 @@ import org.osgi.framework.Bundle;
*/
public class OSGiWeavingAdaptor extends ClassLoaderWeavingAdaptor {
- private static final String AOP_CONTEXT_LOCATION_HEADER = "Eclipse-AspectContext";
-
- private static final String DEFAULT_AOP_CONTEXT_LOCATION = "META-INF/aop.xml";
-
private final List aspectDefinitions;
private final ClassLoader classLoader;
@@ -71,6 +64,7 @@ public class OSGiWeavingAdaptor extends ClassLoaderWeavingAdaptor {
/**
* @see org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor#getNamespace()
*/
+ @Override
public String getNamespace() {
// final String namespace = super.getNamespace();
return namespaceAddon.toString();
@@ -112,6 +106,7 @@ public class OSGiWeavingAdaptor extends ClassLoaderWeavingAdaptor {
* @see org.aspectj.weaver.tools.WeavingAdaptor#weaveClass(java.lang.String,
* byte[], boolean)
*/
+ @Override
public byte[] weaveClass(final String name, byte[] bytes,
final boolean mustWeave) throws IOException {
@@ -129,42 +124,22 @@ public class OSGiWeavingAdaptor extends ClassLoaderWeavingAdaptor {
return bytes;
}
- private void addToNamespaceAddon(final URL xml) {
- final String bundleName = weavingContext.getBundleIdFromURL(xml);
- final String bundleVersion = weavingContext
- .getBundleVersionFromURL(xml);
-
- namespaceAddon.append(bundleName);
+ private void addToNamespaceAddon(final Bundle bundle) {
+ namespaceAddon.append(bundle.getSymbolicName());
namespaceAddon.append(":");
- namespaceAddon.append(bundleVersion);
+ namespaceAddon.append(weavingContext.getBundleVersion(bundle));
namespaceAddon.append(";");
}
- private String getDefinitionLocation(final Bundle bundle) {
- String aopContextHeader = (String) bundle.getHeaders().get(
- AOP_CONTEXT_LOCATION_HEADER);
- if (aopContextHeader != null) {
- aopContextHeader = aopContextHeader.trim();
- return aopContextHeader;
- }
-
- return DEFAULT_AOP_CONTEXT_LOCATION;
- }
-
private void parseDefinitionFromRequiredBundle(final Bundle bundle,
final List definitions, final Set seenBefore) {
try {
- final URL aopXmlDef = bundle
- .getEntry(getDefinitionLocation(bundle));
- if (aopXmlDef != null) {
- if (!seenBefore.contains(aopXmlDef)) {
- definitions.add(DocumentParser.parse(aopXmlDef));
- seenBefore.add(aopXmlDef);
-
- addToNamespaceAddon(aopXmlDef);
- } else {
- warn("ignoring duplicate definition: " + aopXmlDef);
- }
+ final Definition aspectDefinition = WeavingServicePlugin
+ .getDefault().getAspectDefinitionRegistry()
+ .getAspectDefinition(bundle);
+ if (aspectDefinition != null) {
+ definitions.add(aspectDefinition);
+ addToNamespaceAddon(bundle);
}
} catch (final Exception e) {
warn("parse definitions failed", e);
@@ -183,7 +158,6 @@ public class OSGiWeavingAdaptor extends ClassLoaderWeavingAdaptor {
final Set seenBefore = new HashSet();
try {
- parseDefinitionsFromVisibility(definitions, seenBefore);
parseDefinitionsFromRequiredBundles(definitions, seenBefore);
if (definitions.isEmpty()) {
info("no configuration found. Disabling weaver for bundler "
@@ -216,34 +190,4 @@ public class OSGiWeavingAdaptor extends ClassLoaderWeavingAdaptor {
}
}
- private void parseDefinitionsFromVisibility(final List definitions,
- final Set seenBefore) {
- final String resourcePath = System.getProperty(
- "org.aspectj.weaver.loadtime.configuration", "");
- final StringTokenizer st = new StringTokenizer(resourcePath, ";");
-
- while (st.hasMoreTokens()) {
- try {
- final Enumeration xmls = weavingContext.getResources(st
- .nextToken());
-
- while (xmls.hasMoreElements()) {
- final URL xml = (URL) xmls.nextElement();
- if (!seenBefore.contains(xml)) {
- info("using configuration "
- + weavingContext.getFile(xml));
- definitions.add(DocumentParser.parse(xml));
- seenBefore.add(xml);
-
- addToNamespaceAddon(xml);
- } else {
- warn("ignoring duplicate definition: " + xml);
- }
- }
- } catch (final Exception e) {
- warn("parse definitions failed", e);
- }
- }
- }
-
}
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 32ed1ce9b..625003d3b 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
@@ -58,11 +58,6 @@ public class OSGiWeavingContext extends DefaultWeavingContext {
+ loader + ", bundle=" + bundle.getSymbolicName());
}
- public String getBundleIdFromURL(final URL url) {
- return resolverState.getBundle(Integer.parseInt(url.getHost()))
- .getSymbolicName();
- }
-
public Bundle[] getBundles() {
final Set bundles = new HashSet();
@@ -105,14 +100,22 @@ public class OSGiWeavingContext extends DefaultWeavingContext {
return (Bundle[]) bundles.toArray(new Bundle[bundles.size()]);
}
- public String getBundleVersionFromURL(final URL url) {
- return resolverState.getBundle(Integer.parseInt(url.getHost()))
- .getVersion().toString();
+ /**
+ * Extracts the version of the bundle to which the given url belongs to
+ *
+ * @param url An URL of a bundles resource
+ * @return The version of the bundle of the resource to which the URL points
+ * to
+ */
+ public String getBundleVersion(final Bundle bundle) {
+ return resolverState.getBundle(bundle.getBundleId()).getVersion()
+ .toString();
}
/**
* @see org.aspectj.weaver.loadtime.DefaultWeavingContext#getClassLoaderName()
*/
+ @Override
public String getClassLoaderName() {
return bundleDescription.getSymbolicName();
}
@@ -121,6 +124,7 @@ public class OSGiWeavingContext extends DefaultWeavingContext {
* @see org.aspectj.weaver.loadtime.DefaultWeavingContext#getDefinitions(java.lang.ClassLoader,
* org.aspectj.weaver.tools.WeavingAdaptor)
*/
+ @Override
public List getDefinitions(final ClassLoader loader,
final WeavingAdaptor adaptor) {
final List definitions = ((OSGiWeavingAdaptor) adaptor)
@@ -131,6 +135,7 @@ public class OSGiWeavingContext extends DefaultWeavingContext {
/**
* @see org.aspectj.weaver.loadtime.DefaultWeavingContext#getFile(java.net.URL)
*/
+ @Override
public String getFile(final URL url) {
return getBundleIdFromURL(url) + url.getFile();
}
@@ -138,6 +143,7 @@ public class OSGiWeavingContext extends DefaultWeavingContext {
/**
* @see org.aspectj.weaver.loadtime.DefaultWeavingContext#getId()
*/
+ @Override
public String getId() {
return bundleDescription.getSymbolicName();
}
@@ -145,6 +151,7 @@ public class OSGiWeavingContext extends DefaultWeavingContext {
/**
* @see org.aspectj.weaver.loadtime.DefaultWeavingContext#getResources(java.lang.String)
*/
+ @Override
public Enumeration getResources(final String name) throws IOException {
Enumeration result = super.getResources(name);
@@ -191,6 +198,7 @@ public class OSGiWeavingContext extends DefaultWeavingContext {
return result;
}
+ @Override
public String toString() {
return getClass().getName() + "[" + bundleDescription.getSymbolicName()
+ "]";

Back to the top