Felix-478: Fix classloading problems when trying to initialize a compiled class by adding slf4j to the classpath and provide a better error handling if classes can't be loaded.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@618199 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/pom.xml b/scrplugin/pom.xml
index 8d50bb5..d0c79ec 100644
--- a/scrplugin/pom.xml
+++ b/scrplugin/pom.xml
@@ -73,6 +73,7 @@
<artifactId>maven-plugin-api</artifactId>
<version>2.0.7</version>
</dependency>
+
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-archiver</artifactId>
@@ -84,5 +85,17 @@
<artifactId>qdox</artifactId>
<version>1.6.3</version>
</dependency>
+
+ <!-- Logging support -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.4.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.4.3</version>
+ </dependency>
</dependencies>
</project>
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescriptorManager.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescriptorManager.java
index 71895e0..d5748fd 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescriptorManager.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescriptorManager.java
@@ -37,6 +37,8 @@
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.IOUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.thoughtworks.qdox.JavaDocBuilder;
import com.thoughtworks.qdox.model.JavaSource;
@@ -49,6 +51,8 @@
protected static final String SERVICE_COMPONENT = "Service-Component";
+ protected final Logger logger = LoggerFactory.getLogger(this.getClass());
+
/** The sources read by qdox. */
protected final JavaSource[] sources;
@@ -220,7 +224,7 @@
} catch (IOException ioe) {
throw new MojoFailureException("Unable to add target directory to classloader.");
}
- return new URLClassLoader(path);
+ return new URLClassLoader(path, this.getClass().getClassLoader());
}
protected Manifest getManifest(Artifact artifact) throws IOException {
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaField.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaField.java
index 3a08804..17b9a59 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaField.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaField.java
@@ -53,10 +53,25 @@
return value.toString();
}
return null;
+ } catch (NoClassDefFoundError e) {
+ // ignore and try qdox
} catch (Exception e) {
- // ignore and return null
- return null;
+ // ignore and try qdox
}
+ String value = this.field.getInitializationExpression();
+ if ( value != null ) {
+ int pos = value.indexOf("\"");
+ if ( pos != -1 ) {
+ try {
+ value = value.substring(pos + 1);
+ value = value.substring(0, value.lastIndexOf("\""));
+ } catch (ArrayIndexOutOfBoundsException aioobe) {
+ // ignore this as this is a qdox problem
+ value = this.field.getInitializationExpression();
+ }
+ }
+ }
+ return value;
}
/**