tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1414199 - in /openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb: config/DeploymentLoader.java junit/ApplicationComposer.java
Date Tue, 27 Nov 2012 14:16:21 GMT
Author: rmannibucau
Date: Tue Nov 27 14:16:20 2012
New Revision: 1414199

URL: http://svn.apache.org/viewvc?rev=1414199&view=rev
Log:
OPENEJB-1956 root url for applicationcomposer

Modified:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java?rev=1414199&r1=1414198&r2=1414199&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
Tue Nov 27 14:16:20 2012
@@ -1245,7 +1245,7 @@ public class DeploymentLoader implements
         }
     }
 
-    private static Map<String, URL> mapDescriptors(final ResourceFinder finder)
+    public static Map<String, URL> mapDescriptors(final ResourceFinder finder)
             throws IOException {
         final Map<String, URL> map = finder.getResourcesMap(ddDir);
 

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java?rev=1414199&r1=1414198&r2=1414199&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
Tue Nov 27 14:16:20 2012
@@ -54,6 +54,7 @@ import org.apache.openejb.loader.SystemI
 import org.apache.openejb.spi.ContainerSystem;
 import org.apache.openejb.util.Join;
 import org.apache.openejb.util.ServiceManagerProxy;
+import org.apache.openejb.util.URLs;
 import org.apache.openejb.web.LightweightWebAppBuilder;
 import org.apache.webbeans.inject.AbstractInjectable;
 import org.apache.webbeans.inject.OWBInjector;
@@ -61,6 +62,7 @@ import org.apache.webbeans.web.lifecycle
 import org.apache.webbeans.web.lifecycle.test.MockServletContext;
 import org.apache.xbean.finder.AnnotationFinder;
 import org.apache.xbean.finder.IAnnotationFinder;
+import org.apache.xbean.finder.ResourceFinder;
 import org.apache.xbean.finder.archive.Archive;
 import org.apache.xbean.finder.archive.ClassesArchive;
 import org.junit.rules.MethodRule;
@@ -72,6 +74,8 @@ import org.junit.runners.model.Statement
 import org.junit.runners.model.TestClass;
 
 import javax.naming.Context;
+import java.io.File;
+import java.io.IOException;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.net.URL;
@@ -402,12 +406,12 @@ public class ApplicationComposer extends
                 } else if (obj instanceof Persistence) {
 
                     final Persistence persistence = (Persistence) obj;
-                    appModule.addPersistenceModule(new PersistenceModule("", persistence));
+                    appModule.addPersistenceModule(new PersistenceModule(implicitRootUrl(),
persistence));
 
                 } else if (obj instanceof PersistenceUnit) {
 
                     final PersistenceUnit unit = (PersistenceUnit) obj;
-                    appModule.addPersistenceModule(new PersistenceModule("", new Persistence(unit)));
+                    appModule.addPersistenceModule(new PersistenceModule(implicitRootUrl(),
new Persistence(unit)));
 
                 } else if (obj instanceof Beans) {
 
@@ -608,6 +612,28 @@ public class ApplicationComposer extends
         }
     }
 
+    private static String implicitRootUrl() {
+        final ResourceFinder finder = new ResourceFinder("", Thread.currentThread().getContextClassLoader());
+        try {
+            final URL url = DeploymentLoader.altDDSources(DeploymentLoader.mapDescriptors(finder),
false).get("persistence.xml");
+            if (url == null) {
+                return "";
+            }
+
+            final File file = URLs.toFile(url);
+            if (file.getName().endsWith("persistence.xml")) {
+                final String parent = file.getParentFile().getName();
+                if (parent.equalsIgnoreCase("META-INF")) {
+                    return file.getParentFile().getParentFile().getAbsolutePath();
+                }
+                return file.getParentFile().getAbsolutePath();
+            }
+            return url.toExternalForm();
+        } catch (IOException e) {
+            return "";
+        }
+    }
+
     private static Map<String, URL> descriptorsToMap(final Descriptors descriptors)
{
         if (descriptors != null) {
             final Map<String, URL> dds = new HashMap<String, URL>();



Mime
View raw message