tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r813181 - in /openejb/trunk/openejb3/container/openejb-core/src: main/java/org/apache/openejb/config/DeploymentLoader.java test/java/org/apache/openejb/config/DeploymentLoaderTest.java
Date Thu, 10 Sep 2009 00:18:22 GMT
Author: dblevins
Date: Thu Sep 10 00:18:22 2009
New Revision: 813181

URL: http://svn.apache.org/viewvc?rev=813181&view=rev
Log:
Fixed duplicate	altdd logging.	Seems most of it was caused by the @LocalClient	processing.
 Filed that as OPENEJB-1069.

Added:
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/DeploymentLoaderTest.java
  (with props)
Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.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=813181&r1=813180&r2=813181&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
Thu Sep 10 00:18:22 2009
@@ -47,7 +47,6 @@
 import org.apache.openejb.api.LocalClient;
 import org.apache.openejb.api.RemoteClient;
 import org.apache.openejb.loader.SystemInstance;
-import org.apache.openejb.loader.Options.Log;
 import org.apache.openejb.jee.Application;
 import org.apache.openejb.jee.ApplicationClient;
 import org.apache.openejb.jee.Connector;
@@ -410,6 +409,10 @@
     }
 
     protected static ClientModule createClientModule(URL clientUrl, String absolutePath,
ClassLoader appClassLoader, String moduleName) throws OpenEJBException {
+        return createClientModule(clientUrl, absolutePath, appClassLoader, moduleName, true);
+    }
+
+    protected static ClientModule createClientModule(URL clientUrl, String absolutePath,
ClassLoader appClassLoader, String moduleName, boolean log) throws OpenEJBException {
         ResourceFinder clientFinder = new ResourceFinder(clientUrl);
 
         URL manifestUrl = null;
@@ -431,7 +434,8 @@
         }
 
 //        if (mainClass == null) throw new IllegalStateException("No Main-Class defined in
META-INF/MANIFEST.MF file");
-        Map<String, URL> descriptors = getDescriptors(clientUrl);
+
+        Map<String, URL> descriptors = getDescriptors(clientFinder, log);
 
         ApplicationClient applicationClient = null;
         URL clientXmlUrl = descriptors.get("application-client.xml");
@@ -467,7 +471,7 @@
             ejbModule.getWatchedResources().add(URLs.toFilePath(ejbJarXmlUrl));
         }
 
-        ejbModule.setClientModule(createClientModule(baseUrl, jarPath, classLoader, null));
+        ejbModule.setClientModule(createClientModule(baseUrl, jarPath, classLoader, null,
false));
 
         // load webservices descriptor
         addWebservices(ejbModule);
@@ -958,11 +962,22 @@
             // OPENEJB-1059: looking for an altdd persistence.xml file in all urls
             // delegates to xbean finder for going throughout the list
             ResourceFinder finder = new ResourceFinder("", appModule.getClassLoader(), url);
-            Map<String, URL> descriptors = getDescriptors(finder);
+            Map<String, URL> descriptors = getDescriptors(finder, false);
 
             // if a persistence.xml has been found, just pull it to the list
             if (descriptors.containsKey("persistence.xml")) {
-                persistenceUrls.add(descriptors.get("persistence.xml"));
+                URL descriptor = descriptors.get("persistence.xml");
+
+                // don't add it if already present
+                if (persistenceUrls.contains(descriptor)) continue;
+
+                // log if it is an altdd
+                String urlString = descriptor.toExternalForm();
+                if (!urlString.contains("META-INF/persistence.xml")) {
+                    logger.info("AltDD persistence.xml -> " + urlString);
+                }
+                
+                persistenceUrls.add(descriptor);
             }
         }
     }
@@ -974,15 +989,26 @@
     }
 
     private static Map<String, URL> getDescriptors(ResourceFinder finder) throws OpenEJBException
{
+        return getDescriptors(finder, true);
+    }
+
+    private static Map<String, URL> getDescriptors(ResourceFinder finder, boolean log)
throws OpenEJBException {
         try {
 
-            return altDDSources(finder.getResourcesMap("META-INF/"), true);
+            return altDDSources(finder.getResourcesMap("META-INF/"), log);
 
         } catch (IOException e) {
             throw new OpenEJBException("Unable to determine descriptors in jar.", e);
         }
     }
 
+    /**
+     * Modifies the map passed in with all the alt dd URLs found
+     *
+     * @param map
+     * @param log
+     * @return the same map instance updated with alt dds
+     */
     public static Map<String, URL> altDDSources(Map<String, URL> map, boolean
log) {
         String prefixes = SystemInstance.get().getProperty(OPENEJB_ALTDD_PREFIX);
 
@@ -1002,22 +1028,23 @@
                 URL value = entry.getValue();
                 if (key.startsWith(prefix)) {
                     key = key.substring(prefix.length());
-                    map.put(key, value);
 
-                    // for logging once all is resolved
                     alts.put(key, value);
                 }
             }
         }
 
-        if (log) {
-            for (Map.Entry<String, URL> alt : alts.entrySet()) {
-//        	module.getValidation().warn("DeploymentLoader", "altdd.overriden", alt.getKey(),
alt.getValue().toExternalForm());
-                logger.info("AltDD " + alt.getKey() + " -> " + alt.getValue().toExternalForm());
-            }
+        for (Map.Entry<String, URL> alt : alts.entrySet()) {
+            String key = alt.getKey();
+            URL value = alt.getValue();
+
+            // don't add and log if the same key/value is already in the map
+            if (value.equals(map.get(key))) continue;
+            
+            if (log) logger.info("AltDD " + key + " -> " + value.toExternalForm());
+            map.put(key, value);
         }
 
-
         return map;
     }
 
@@ -1213,5 +1240,5 @@
         }
         return baseUrl;
     }
-    
+
 }

Added: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/DeploymentLoaderTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/DeploymentLoaderTest.java?rev=813181&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/DeploymentLoaderTest.java
(added)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/DeploymentLoaderTest.java
Thu Sep 10 00:18:22 2009
@@ -0,0 +1,72 @@
+/**
+ * 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 java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.io.File;
+
+import org.apache.openejb.loader.SystemInstance;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DeploymentLoaderTest extends TestCase {
+
+    public void testProcessesAltDdsMethod() throws Exception {
+        /* We start with a directory structure like so:
+         *
+         * - META-INF/ejb-jar.xml
+         * - META-INF/test.ejb-jar.xml
+         * - META-INF/footest.ejb-jar.xml
+         * - META-INF/bartest.ejb-jar.xml
+         * - META-INF/persistence.xml
+         * - META-INF/test.env-entry.properties
+         */
+        Map<String, URL> original = new HashMap<String, URL>();
+        original.put("ejb-jar.xml", new File("META-INF/ejb-jar.xml").toURL());
+        original.put("test.ejb-jar.xml", new File("META-INF/test.ejb-jar.xml").toURL());
+        original.put("footest.ejb-jar.xml", new File("META-INF/footest.ejb-jar.xml").toURL());
+        original.put("bartest.ejb-jar.xml", new File("META-INF/bartest.ejb-jar.xml").toURL());
+        original.put("persistence.xml", new File("META-INF/persistence.xml").toURL());
+        original.put("test.env-entry.properties", new File("META-INF/test.env-entry.properties").toURL());
+
+        SystemInstance.get().setProperty("openejb.altdd.prefix", "footest, test");
+
+        Map<String, URL> processed = new HashMap<String, URL>(original);
+        DeploymentLoader.altDDSources(processed, false);
+
+        // an item that existed and should have been replaced
+        assertEquals(processed.get("ejb-jar.xml"), original.get("footest.ejb-jar.xml"));
+
+        // an item that didn't exist and should have been added
+        assertEquals(processed.get("env-entry.properties"), original.get("test.env-entry.properties"));
+
+        // items that shouldn't have been affected
+        assertEquals(processed.get("persistence.xml"), original.get("persistence.xml"));
+        assertEquals(processed.get("test.ejb-jar.xml"), original.get("test.ejb-jar.xml"));
+        assertEquals(processed.get("footest.ejb-jar.xml"), original.get("footest.ejb-jar.xml"));
+        assertEquals(processed.get("bartest.ejb-jar.xml"), original.get("bartest.ejb-jar.xml"));
+        assertEquals(processed.get("test.env-entry.properties"), original.get("test.env-entry.properties"));
+
+        // there should be no other additional entries
+        assertEquals(7, processed.size());
+    }
+}

Propchange: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/DeploymentLoaderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message