aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mahrw...@apache.org
Subject svn commit: r1144092 - in /aries/trunk: jpa/jpa-container-itest/ jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/context/itest/ jpa/jpa-container-testbundle-eclipselink/ util/src/main/java/org/apache/aries/util/internal/ util/src/main/java/o...
Date Thu, 07 Jul 2011 23:13:13 GMT
Author: mahrwald
Date: Thu Jul  7 23:13:12 2011
New Revision: 1144092

URL: http://svn.apache.org/viewvc?rev=1144092&view=rev
Log:
ARIES-691: Fix NullPointer in getting classloader for resolved bundle on Felix

Added:
    aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/context/itest/EclipseLinkStartupTest.java
Modified:
    aries/trunk/jpa/jpa-container-itest/pom.xml
    aries/trunk/jpa/jpa-container-testbundle-eclipselink/pom.xml
    aries/trunk/util/src/main/java/org/apache/aries/util/internal/FelixWorker.java
    aries/trunk/util/src/main/java/org/apache/aries/util/io/packageinfo

Modified: aries/trunk/jpa/jpa-container-itest/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-itest/pom.xml?rev=1144092&r1=1144091&r2=1144092&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container-itest/pom.xml (original)
+++ aries/trunk/jpa/jpa-container-itest/pom.xml Thu Jul  7 23:13:12 2011
@@ -63,6 +63,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+          <groupId>org.ops4j.pax.runner</groupId>
+          <artifactId>pax-runner-no-jcl</artifactId>
+          <version>1.7.3</version>
+        </dependency>
+        <dependency>
             <groupId>org.ops4j.pax.exam</groupId>
             <artifactId>pax-exam-container-default</artifactId>
             <scope>test</scope>

Added: aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/context/itest/EclipseLinkStartupTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/context/itest/EclipseLinkStartupTest.java?rev=1144092&view=auto
==============================================================================
--- aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/context/itest/EclipseLinkStartupTest.java
(added)
+++ aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/context/itest/EclipseLinkStartupTest.java
Thu Jul  7 23:13:12 2011
@@ -0,0 +1,162 @@
+package org.apache.aries.jpa.context.itest;
+
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
+import static org.ops4j.pax.exam.OptionUtils.combine;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.spi.PersistenceProvider;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Inject;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.util.tracker.ServiceTracker;
+
+@RunWith(JUnit4TestRunner.class)
+public class EclipseLinkStartupTest {
+    public static final long DEFAULT_TIMEOUT = 10000;
+
+    @Inject
+    protected BundleContext bundleContext;
+    
+    @Test
+    public void testContextCreationWithStartingBundle() throws Exception {
+        // wait for the Eclipselink provider to come up
+        getOsgiService(PersistenceProvider.class);
+        
+        for (Bundle b : bundleContext.getBundles()) {
+            if (b.getSymbolicName().equals("org.apache.aries.jpa.container.itest.bundle.eclipselink"))
{
+                b.start();
+            }
+        }
+        
+        getOsgiService(EntityManagerFactory.class);
+    }
+
+    @org.ops4j.pax.exam.junit.Configuration
+    public static Option[] configuration() {
+        Option[] options = options(
+                felix().version("3.2.1"),
+                // Log
+                mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
+                mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
+                // Felix Config Admin
+                mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
+                // Felix mvn url handler
+                mavenBundle("org.ops4j.pax.url", "pax-url-mvn"),
+
+                // this is how you set the default log level when using pax
+                // logging (logProfile)
+//                systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level")
+//                        .value("DEBUG"),
+
+                // Bundles
+                mavenBundle("org.osgi", "org.osgi.compendium"),
+                mavenBundle("org.apache.aries", "org.apache.aries.util"),
+                // Adding blueprint to the runtime is a hack to placate the
+                // maven bundle plugin.
+                mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint"),
+                mavenBundle("asm", "asm-all"),
+                mavenBundle("org.apache.aries.proxy", "org.apache.aries.proxy"),
+                mavenBundle("org.apache.geronimo.specs", "geronimo-jpa_2.0_spec"),
+                mavenBundle("org.apache.aries.jndi", "org.apache.aries.jndi.api"),
+                mavenBundle("org.apache.aries.jndi", "org.apache.aries.jndi.core"),
+                mavenBundle("org.apache.aries.jndi", "org.apache.aries.jndi.url"),
+                mavenBundle("org.apache.aries.jpa", "org.apache.aries.jpa.api"),
+                mavenBundle("org.apache.aries.jpa", "org.apache.aries.jpa.container"),
+                mavenBundle("org.apache.aries.jpa", "org.apache.aries.jpa.container.context"),
+                mavenBundle("org.apache.aries.transaction", "org.apache.aries.transaction.manager"),
+                mavenBundle("org.apache.aries.transaction", "org.apache.aries.transaction.wrappers"),
+                mavenBundle("org.apache.derby", "derby"),
+                mavenBundle("org.apache.geronimo.specs", "geronimo-jta_1.1_spec"),
+                mavenBundle("commons-lang", "commons-lang"),
+                mavenBundle("commons-collections", "commons-collections"),
+                mavenBundle("commons-pool", "commons-pool"),
+
+                mavenBundle("org.eclipse.persistence", "org.eclipse.persistence.jpa"),
+                mavenBundle("org.eclipse.persistence", "org.eclipse.persistence.core"),
+                mavenBundle("org.eclipse.persistence", "org.eclipse.persistence.asm"),
+                mavenBundle("org.eclipse.persistence", "org.eclipse.persistence.antlr"),
+                
+                mavenBundle("org.apache.aries.jpa", "org.apache.aries.jpa.eclipselink.adapter"),
+                mavenBundle("org.apache.aries.jpa", "org.apache.aries.jpa.container.itest.bundle.eclipselink").noStart()
+            );
+        options = updateOptions(options);
+        return options;
+    }
+
+    protected static Option[] updateOptions(Option[] options) {
+        // We need to add pax-exam-junit here when running with the ibm
+        // jdk to avoid the following exception during the test run:
+        // ClassNotFoundException: org.ops4j.pax.exam.junit.Configuration
+        if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
+            Option[] ibmOptions = options(wrappedBundle(mavenBundle(
+                    "org.ops4j.pax.exam", "pax-exam-junit")));
+            options = combine(ibmOptions, options);
+        }
+
+        return options;
+    }
+
+    public static MavenArtifactProvisionOption mavenBundle(String groupId,
+            String artifactId) {
+        return CoreOptions.mavenBundle().groupId(groupId)
+                .artifactId(artifactId).versionAsInProject();
+    }
+
+    protected <T> T getOsgiService(Class<T> type, long timeout) {
+        return getOsgiService(type, null, timeout);
+    }
+
+    protected <T> T getOsgiService(Class<T> type) {
+        return getOsgiService(type, null, DEFAULT_TIMEOUT);
+    }
+
+    protected <T> T getOsgiService(Class<T> type, String filter, long timeout)
{
+        return getOsgiService(null, type, filter, timeout);
+    }
+
+    protected <T> T getOsgiService(BundleContext bc, Class<T> type,
+            String filter, long timeout) {
+        ServiceTracker tracker = null;
+        try {
+            String flt;
+            if (filter != null) {
+                if (filter.startsWith("(")) {
+                    flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName()
+                            + ")" + filter + ")";
+                } else {
+                    flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName()
+                            + ")(" + filter + "))";
+                }
+            } else {
+                flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")";
+            }
+            Filter osgiFilter = FrameworkUtil.createFilter(flt);
+            tracker = new ServiceTracker(bc == null ? bundleContext : bc,
+                    osgiFilter, null);
+            tracker.open();
+            // Note that the tracker is not closed to keep the reference
+            // This is buggy, has the service reference may change i think
+            Object svc = type.cast(tracker.waitForService(timeout));
+            if (svc == null) {
+                throw new RuntimeException("Gave up waiting for service " + flt);
+            }
+            return type.cast(svc);
+        } catch (InvalidSyntaxException e) {
+            throw new IllegalArgumentException("Invalid filter", e);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+    }
+}

Modified: aries/trunk/jpa/jpa-container-testbundle-eclipselink/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-testbundle-eclipselink/pom.xml?rev=1144092&r1=1144091&r2=1144092&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container-testbundle-eclipselink/pom.xml (original)
+++ aries/trunk/jpa/jpa-container-testbundle-eclipselink/pom.xml Thu Jul  7 23:13:12 2011
@@ -48,7 +48,7 @@
             *
         </aries.osgi.import>
         <aries.osgi.private.pkg />
-        <aries.osgi.symbolic.name>${project.groupId}.${project.artifactId}</aries.osgi.symbolic.name>
+        <aries.osgi.symbolic.name>${project.artifactId}</aries.osgi.symbolic.name>
     </properties>
     <dependencies>
         <dependency>

Modified: aries/trunk/util/src/main/java/org/apache/aries/util/internal/FelixWorker.java
URL: http://svn.apache.org/viewvc/aries/trunk/util/src/main/java/org/apache/aries/util/internal/FelixWorker.java?rev=1144092&r1=1144091&r2=1144092&view=diff
==============================================================================
--- aries/trunk/util/src/main/java/org/apache/aries/util/internal/FelixWorker.java (original)
+++ aries/trunk/util/src/main/java/org/apache/aries/util/internal/FelixWorker.java Thu Jul
 7 23:13:12 2011
@@ -28,21 +28,21 @@ public final class FelixWorker extends D
 {
   private static Method getCurrentModuleMethod;
   private static Method getClassLoader;
+  private static Class<?> moduleClass;
 
   static {
     Bundle b = FrameworkUtil.getBundle(FelixWorker.class);
     try {
       getCurrentModuleMethod = b.getClass().getDeclaredMethod("getCurrentModule");
-      Object result = getCurrentModuleMethod.invoke(b);
-      getClassLoader = result.getClass().getDeclaredMethod("getClassLoader");
+      moduleClass = b.getClass().getClassLoader().loadClass("org.apache.felix.framework.ModuleImpl");
+      getClassLoader = moduleClass.getDeclaredMethod("getClassLoader");
       
       getCurrentModuleMethod.setAccessible(true);
       getClassLoader.setAccessible(true);
     } catch (SecurityException e) {
     } catch (NoSuchMethodException e) {
     } catch (IllegalArgumentException e) {
-    } catch (IllegalAccessException e) {
-    } catch (InvocationTargetException e) {
+    } catch (ClassNotFoundException e) {
     }
   }
   
@@ -51,7 +51,7 @@ public final class FelixWorker extends D
     if (getCurrentModuleMethod != null) {
       try {
         Object result = getCurrentModuleMethod.invoke(b);
-        if (result != null) {
+        if (result != null && moduleClass.isInstance(result)) {
           Object cl = getClassLoader.invoke(result);
           
           if (cl instanceof ClassLoader) return (ClassLoader) cl;
@@ -66,6 +66,6 @@ public final class FelixWorker extends D
 
   public boolean isValid()
   {
-    return getCurrentModuleMethod != null && getClassLoader != null;
+    return getCurrentModuleMethod != null && moduleClass != null && getClassLoader
!= null;
   }
 }

Modified: aries/trunk/util/src/main/java/org/apache/aries/util/io/packageinfo
URL: http://svn.apache.org/viewvc/aries/trunk/util/src/main/java/org/apache/aries/util/io/packageinfo?rev=1144092&r1=1144091&r2=1144092&view=diff
==============================================================================
--- aries/trunk/util/src/main/java/org/apache/aries/util/io/packageinfo (original)
+++ aries/trunk/util/src/main/java/org/apache/aries/util/io/packageinfo Thu Jul  7 23:13:12
2011
@@ -16,4 +16,4 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-version 0.1
+version 0.1.0



Mime
View raw message