You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2009/01/19 07:08:38 UTC

svn commit: r735615 - in /openejb/trunk/openejb3/container/openejb-core/src: main/java/org/apache/openejb/config/ main/java/org/apache/openejb/util/ test/java/org/apache/openejb/config/ test/java/org/superbiz/ test/java/org/superbiz/altdd/ test/resourc...

Author: dblevins
Date: Sun Jan 18 22:08:37 2009
New Revision: 735615

URL: http://svn.apache.org/viewvc?rev=735615&view=rev
Log:
OPENEJB-987: Support for alternate deployment descriptors for testing and other environments

Added:
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/AltDDPrefixTest.java
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/superbiz/
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/superbiz/altdd/
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/superbiz/altdd/Orange.java
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/superbiz/altdd/OrangeLocal.java
    openejb/trunk/openejb3/container/openejb-core/src/test/resources/altddapp/
    openejb/trunk/openejb3/container/openejb-core/src/test/resources/altddapp/META-INF/
    openejb/trunk/openejb3/container/openejb-core/src/test/resources/altddapp/META-INF/test.ejb-jar.xml
Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Classes.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java?rev=735615&r1=735614&r2=735615&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java Sun Jan 18 22:08:37 2009
@@ -38,9 +38,6 @@
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
-import javax.ejb.MessageDriven;
-import javax.ejb.Stateful;
-import javax.ejb.Stateless;
 import javax.xml.bind.JAXBException;
 
 import org.apache.openejb.ClassLoaderUtil;
@@ -78,6 +75,7 @@
  */
 public class DeploymentLoader {
     public static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP_CONFIG, "org.apache.openejb.util.resources");
+    private static final String OPENEJB_ALTDD_PREFIX = "openejb.altdd.prefix";
 
     public AppModule load(File jarFile) throws OpenEJBException {
         // verify we have a valid file
@@ -115,7 +113,7 @@
                         throw new OpenEJBException(e);
                     }
                 }
-
+                                                    
                 moduleClass = discoverModuleType(tempURL, ClassLoaderUtil.createTempClassLoader(doNotUseClassLoader), true);
             } catch (Exception e) {
                 throw new UnknownModuleTypeException("Unable to determine module type for jar: " + baseUrl.toExternalForm(), e);
@@ -191,12 +189,7 @@
 
         ResourceFinder finder = new ResourceFinder("", tmpClassLoader, appUrl);
 
-        Map<String, URL> appDescriptors;
-        try {
-            appDescriptors = finder.getResourcesMap("META-INF");
-        } catch (IOException e) {
-            throw new OpenEJBException("Unable to determine descriptors in jar: " + appUrl.toExternalForm(), e);
-        }
+        Map<String, URL> appDescriptors = getDescriptors(finder);
 
         try {
 
@@ -934,16 +927,49 @@
     }
 
     private static Map<String, URL> getDescriptors(URL moduleUrl) throws OpenEJBException {
+
+        ResourceFinder finder = new ResourceFinder(moduleUrl);
+
+        return getDescriptors(finder);
+    }
+
+    private static Map<String, URL> getDescriptors(ResourceFinder finder) throws OpenEJBException {
         try {
-            ResourceFinder finder = new ResourceFinder(moduleUrl);
 
-            return finder.getResourcesMap("META-INF/");
+            return altDDSources(finder.getResourcesMap("META-INF/"));
 
         } catch (IOException e) {
             throw new OpenEJBException("Unable to determine descriptors in jar.", e);
         }
     }
 
+    private static Map<String, URL> altDDSources(Map<String, URL> map) {
+
+        return altDDSources(map, true);
+    }
+
+    private static Map<String, URL> altDDSources(Map<String, URL> map, boolean log) {
+        String prefix = SystemInstance.get().getProperty(OPENEJB_ALTDD_PREFIX);
+
+        if (prefix == null || prefix.length() <= 0) return map;
+
+        if (!prefix.matches(".*[.-]$")) prefix += ".";
+
+        for (Map.Entry<String, URL> entry : map.entrySet()) {
+            String key = entry.getKey();
+            URL value = entry.getValue();
+            if (key.startsWith(prefix)) {
+                key = key.substring(prefix.length());
+                map.put(key, value);
+
+                if (log) logger.info("Found AltDD " + key + " -> " + value.toExternalForm());
+            }
+        }
+
+
+        return map;
+    }
+
     private static Map<String, URL> getWebDescriptors(File warFile) throws IOException {
         Map<String, URL> descriptors = new TreeMap<String,URL>();
 
@@ -1036,7 +1062,7 @@
     public static Class<? extends DeploymentModule> discoverModuleType(URL baseUrl, ClassLoader classLoader, boolean searchForDescriptorlessApplications) throws IOException, UnknownModuleTypeException {
         ResourceFinder finder = new ResourceFinder("", classLoader, baseUrl);
 
-        Map<String, URL> descriptors = finder.getResourcesMap("META-INF");
+        Map<String, URL> descriptors = altDDSources(finder.getResourcesMap("META-INF/"), false);
 
         String path = baseUrl.getPath();
         if (path.endsWith("/")) path = path.substring(0, path.length() - 1);

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java?rev=735615&r1=735614&r2=735615&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java Sun Jan 18 22:08:37 2009
@@ -94,8 +94,8 @@
         List<URL> persistenceUrls = (List<URL>) appModule.getAltDDs().get("persistence.xml");
         if (persistenceUrls != null) {
             for (URL persistenceUrl : persistenceUrls) {
-                String moduleName = persistenceUrl.toExternalForm().replaceFirst("!/?META-INF/persistence.xml$", "");
-                moduleName = moduleName.replaceFirst("/?META-INF/persistence.xml$", "/");
+                String moduleName = persistenceUrl.toExternalForm().replaceFirst("!/?META-INF/.*persistence.xml$", "");
+                moduleName = moduleName.replaceFirst("/?META-INF/.*persistence.xml$", "/");
                 if (moduleName.startsWith("jar:")) moduleName = moduleName.substring("jar:".length());
                 if (moduleName.startsWith("file:")) moduleName = moduleName.substring("file:".length());
 //                if (moduleName1.endsWith("/")) moduleName1 = moduleName1.substring(0, moduleName1.length() - 1);

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Classes.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Classes.java?rev=735615&r1=735614&r2=735615&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Classes.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Classes.java Sun Jan 18 22:08:37 2009
@@ -17,6 +17,8 @@
 package org.apache.openejb.util;
 
 import java.util.HashMap;
+import java.util.List;
+import java.util.ArrayList;
 import java.lang.reflect.Array;
 
 /**
@@ -65,4 +67,13 @@
             return "";
         }
     }
+
+    public static List<String> getSimpleNames(Class... classes){
+        List<String> list = new ArrayList<String>();
+        for (Class aClass : classes) {
+            list.add(aClass.getSimpleName());
+        }
+
+        return list;
+    }
 }

Added: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/AltDDPrefixTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/AltDDPrefixTest.java?rev=735615&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/AltDDPrefixTest.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/AltDDPrefixTest.java Sun Jan 18 22:08:37 2009
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.config;
+
+import junit.framework.TestCase;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.util.URLs;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.assembler.classic.Assembler;
+
+import java.net.URL;
+import java.io.File;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AltDDPrefixTest extends TestCase {
+
+    public void test() throws Exception {
+        Assembler assmbler = new Assembler();
+        SystemInstance.get().setProperty("openejb.altdd.prefix", "test");
+        ConfigurationFactory factory = new ConfigurationFactory();
+
+        URL resource = AltDDPrefixTest.class.getClassLoader().getResource("altddapp");
+        File file = URLs.toFile(resource);
+        AppInfo appInfo = factory.configureApplication(file);
+        assertNotNull(appInfo);
+        assertEquals(1, appInfo.ejbJars.size());
+    }
+}

Added: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/superbiz/altdd/Orange.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/superbiz/altdd/Orange.java?rev=735615&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/superbiz/altdd/Orange.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/superbiz/altdd/Orange.java Sun Jan 18 22:08:37 2009
@@ -0,0 +1,23 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.superbiz.altdd;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class Orange implements OrangeLocal {
+}

Added: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/superbiz/altdd/OrangeLocal.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/superbiz/altdd/OrangeLocal.java?rev=735615&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/superbiz/altdd/OrangeLocal.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/superbiz/altdd/OrangeLocal.java Sun Jan 18 22:08:37 2009
@@ -0,0 +1,23 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.superbiz.altdd;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public interface OrangeLocal {
+}

Added: openejb/trunk/openejb3/container/openejb-core/src/test/resources/altddapp/META-INF/test.ejb-jar.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/resources/altddapp/META-INF/test.ejb-jar.xml?rev=735615&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/resources/altddapp/META-INF/test.ejb-jar.xml (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/resources/altddapp/META-INF/test.ejb-jar.xml Sun Jan 18 22:08:37 2009
@@ -0,0 +1,8 @@
+<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.0" metadata-complete="false">
+  <enterprise-beans>
+    <session>
+      <ejb-name>OrangeBean</ejb-name>
+      <ejb-class>org.superbiz.altdd.Orange</ejb-class>
+    </session>
+  </enterprise-beans>
+</ejb-jar>