FELIX-2939 : Maven SCR Plugin is not (marked as) thread-safe for parallel builds
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1098587 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
index 47efce5..9264364 100644
--- a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
+++ b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
@@ -24,8 +24,7 @@
import org.apache.felix.scrplugin.Constants;
import org.apache.felix.scrplugin.tags.JavaClassDescription;
import org.apache.felix.scrplugin.tags.JavaField;
-import org.apache.felix.scrplugin.tags.annotation.AbstractTag;
-import org.apache.felix.scrplugin.tags.annotation.Util;
+import org.apache.felix.scrplugin.tags.annotation.*;
import com.thoughtworks.qdox.model.Annotation;
@@ -40,7 +39,7 @@
* @param annotation Annotation
* @param desc Description
*/
- public PropertyTag(final Annotation annotation, final JavaClassDescription desc, JavaField field) {
+ public PropertyTag(final Annotation annotation, final AnnotationJavaClassDescription desc, JavaField field) {
super(annotation, desc, field);
this.annotation = new Property() {
@@ -94,7 +93,7 @@
}
public Class<?>[] classValue() {
- return Util.getClassArrayValue(annotation, "classValue", Property.class);
+ return Util.getClassArrayValue(annotation, "classValue", Property.class, desc.getClassLoader());
}
public boolean[] boolValue() {
diff --git a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ReferenceTag.java b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ReferenceTag.java
index 0c27191..8319692 100644
--- a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ReferenceTag.java
+++ b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ReferenceTag.java
@@ -23,10 +23,8 @@
import org.apache.felix.scr.annotations.*;
import org.apache.felix.scrplugin.Constants;
-import org.apache.felix.scrplugin.tags.JavaClassDescription;
import org.apache.felix.scrplugin.tags.JavaField;
-import org.apache.felix.scrplugin.tags.annotation.AbstractTag;
-import org.apache.felix.scrplugin.tags.annotation.Util;
+import org.apache.felix.scrplugin.tags.annotation.*;
import com.thoughtworks.qdox.model.Annotation;
@@ -41,7 +39,7 @@
* @param annotation Annotation
* @param desc Description
*/
- public ReferenceTag(final Annotation annotation, final JavaClassDescription desc, JavaField field) {
+ public ReferenceTag(final Annotation annotation, final AnnotationJavaClassDescription desc, JavaField field) {
super(annotation, desc, field);
this.annotation = new Reference() {
@@ -63,7 +61,7 @@
}
public Class<?> referenceInterface() {
- return Util.getClassValue(annotation, "referenceInterface", Reference.class);
+ return Util.getClassValue(annotation, "referenceInterface", Reference.class, desc.getClassLoader());
}
public ReferenceStrategy strategy() {
diff --git a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ServiceTag.java b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ServiceTag.java
index 0cbf0e5..f9429b4 100644
--- a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ServiceTag.java
+++ b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ServiceTag.java
@@ -23,9 +23,7 @@
import org.apache.felix.scr.annotations.AutoDetect;
import org.apache.felix.scr.annotations.Service;
import org.apache.felix.scrplugin.Constants;
-import org.apache.felix.scrplugin.tags.JavaClassDescription;
-import org.apache.felix.scrplugin.tags.annotation.AbstractTag;
-import org.apache.felix.scrplugin.tags.annotation.Util;
+import org.apache.felix.scrplugin.tags.annotation.*;
import com.thoughtworks.qdox.model.Annotation;
@@ -43,7 +41,7 @@
* @param desc Description
*/
public ServiceTag(final Annotation annotation,
- final JavaClassDescription desc,
+ final AnnotationJavaClassDescription desc,
final Service tag,
final String serviceInterface) {
super(annotation, desc, null);
@@ -71,7 +69,7 @@
return map;
}
- public static List<ServiceTag> createServiceTags(final Annotation annotation, JavaClassDescription desc) {
+ public static List<ServiceTag> createServiceTags(final Annotation annotation, final AnnotationJavaClassDescription desc) {
final Service tag = new Service() {
public boolean serviceFactory() {
@@ -79,7 +77,7 @@
}
public Class<?>[] value() {
- return Util.getClassArrayValue(annotation, "value", Service.class);
+ return Util.getClassArrayValue(annotation, "value", Service.class, desc.getClassLoader());
}
public Class<? extends java.lang.annotation.Annotation> annotationType() {
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/JavaClassDescriptorManager.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/JavaClassDescriptorManager.java
index fe53da7..b1aa824 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/JavaClassDescriptorManager.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/JavaClassDescriptorManager.java
@@ -20,7 +20,8 @@
import org.apache.felix.scrplugin.om.Component;
import org.apache.felix.scrplugin.om.Components;
-import org.apache.felix.scrplugin.tags.*;
+import org.apache.felix.scrplugin.tags.JavaClassDescription;
+import org.apache.felix.scrplugin.tags.JavaTag;
import org.apache.felix.scrplugin.tags.annotation.AnnotationJavaClassDescription;
import org.apache.felix.scrplugin.tags.annotation.AnnotationTagProviderManager;
import org.apache.felix.scrplugin.tags.cl.ClassLoaderJavaClassDescription;
@@ -84,8 +85,6 @@
this.log = log;
this.annotationTagProviderManager = new AnnotationTagProviderManager( annotationTagProviders, classLoader );
this.classloader = classLoader;
-
- ClassUtil.classLoader = this.classloader;
}
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/ClassUtil.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/ClassUtil.java
index d84f4cb..76160d2 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/ClassUtil.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/ClassUtil.java
@@ -26,8 +26,6 @@
*/
public class ClassUtil {
- public static ClassLoader classLoader;
-
/**
* Try to get the initial value of a static field
* @param clazz The class.
@@ -59,7 +57,7 @@
/**
* Get the compiled class.
*/
- public static Class<?> getClass(String name) {
+ public static Class<?> getClass(final ClassLoader classLoader, String name) {
if ( classLoader == null ) {
return null;
}
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationJavaClassDescription.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationJavaClassDescription.java
index 15f3379..85563e9 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationJavaClassDescription.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationJavaClassDescription.java
@@ -43,6 +43,10 @@
super(clazz, javaClass, manager);
}
+ public ClassLoader getClassLoader() {
+ return this.manager.getClassLoader();
+ }
+
/**
* @see org.apache.felix.scrplugin.tags.JavaClassDescription#getTagByName(String)
*/
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/Util.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/Util.java
index ea44c02..671c616 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/Util.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/Util.java
@@ -293,13 +293,13 @@
}
}
- public static Class<?> getClassValue(Annotation annotation, String name, final Class<?> clazz) {
+ public static Class<?> getClassValue(Annotation annotation, String name, final Class<?> clazz, final ClassLoader classLoader) {
final Object obj = annotation.getNamedParameter(name);
if ( obj != null ) {
if ( obj instanceof Class<?> ) {
return (Class<?>)obj;
}
- return ClassUtil.getClass(obj.toString());
+ return ClassUtil.getClass(classLoader, obj.toString());
}
try {
return (Class<?>) clazz.getMethod(name).getDefaultValue();
@@ -309,7 +309,7 @@
}
}
- public static Class<?>[] getClassArrayValue(Annotation annotation, String name, final Class<?> clazz) {
+ public static Class<?>[] getClassArrayValue(Annotation annotation, String name, final Class<?> clazz, final ClassLoader classLoader) {
Object obj = annotation.getNamedParameter(name);
if ( obj != null ) {
if ( obj instanceof Class<?> ) {
@@ -325,12 +325,12 @@
if ( objArray[i] instanceof Class<?>) {
result[i] = (Class<?>)objArray[i];
} else {
- result[i] = ClassUtil.getClass(objArray[i].toString());
+ result[i] = ClassUtil.getClass(classLoader, objArray[i].toString());
}
}
return result;
}
- return new Class<?>[] {ClassUtil.getClass(obj.toString())};
+ return new Class<?>[] {ClassUtil.getClass(classLoader, obj.toString())};
}
try {
final Object val = clazz.getMethod(name).getDefaultValue();
diff --git a/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java b/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
index 17de868..557fcb8 100644
--- a/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
+++ b/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
@@ -39,6 +39,7 @@
*
* @goal scr
* @phase process-classes
+ * @threadSafe
* @description Build Service Descriptors from Java Source
* @requiresDependencyResolution compile
*/