tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r898947 - in /openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config: DeploymentLoader.java DeploymentsResolver.java RequireDescriptors.java
Date Wed, 13 Jan 2010 21:49:19 GMT
Author: dblevins
Date: Wed Jan 13 21:49:18 2010
New Revision: 898947

URL: http://svn.apache.org/viewvc?rev=898947&view=rev
Log:
OPENEJB-1130: Stricter ClientModule classpath discovery prevents NameAlreadyBoundException

Added:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/RequireDescriptors.java
  (with props)
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/DeploymentsResolver.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=898947&r1=898946&r2=898947&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
Wed Jan 13 21:49:18 2010
@@ -1137,6 +1137,17 @@
     }
 
     public static Class<? extends DeploymentModule> discoverModuleType(URL baseUrl,
ClassLoader classLoader, boolean searchForDescriptorlessApplications) throws IOException,
UnknownModuleTypeException {
+        Set<RequireDescriptors> search = new HashSet<RequireDescriptors>();
+
+        if (!searchForDescriptorlessApplications) search.addAll(Arrays.asList(RequireDescriptors.values()));
+
+        return discoverModuleType(baseUrl, classLoader, search);
+    }
+
+    public static Class<? extends DeploymentModule> discoverModuleType(URL baseUrl,
ClassLoader classLoader, Set<RequireDescriptors> requireDescriptor) throws IOException,
UnknownModuleTypeException {
+        final boolean scanPotentialEjbModules = !requireDescriptor.contains(RequireDescriptors.EJB);
+        final boolean scanPotentialClientModules = !requireDescriptor.contains(RequireDescriptors.CLIENT);
+
         ResourceFinder finder = new ResourceFinder("", classLoader, baseUrl);
         Map<String, URL> descriptors = altDDSources(finder.getResourcesMap("META-INF/"),
false);
 
@@ -1165,7 +1176,8 @@
         }
 
         URL manifestUrl = descriptors.get("MANIFEST.MF");
-        if (manifestUrl != null) {
+        if (scanPotentialClientModules && manifestUrl != null) {
+            // In this case scanPotentialClientModules really means "require application-client.xml"
             InputStream is = manifestUrl.openStream();
             Manifest manifest = new Manifest(is);
             String mainClass = manifest.getMainAttributes().getValue(Attributes.Name.MAIN_CLASS);
@@ -1174,7 +1186,7 @@
             }
         }
 
-        if (searchForDescriptorlessApplications) {
+        if (scanPotentialEjbModules || scanPotentialClientModules) {
             AnnotationFinder classFinder = new AnnotationFinder(classLoader, baseUrl);
 
             final Set<Class<? extends DeploymentModule>> otherTypes = new LinkedHashSet();
@@ -1182,12 +1194,12 @@
             AnnotationFinder.Filter filter = new AnnotationFinder.Filter() {
                 final String packageName = LocalClient.class.getName().replace("LocalClient",
"");
                 public boolean accept(String annotationName) {
-                    if (annotationName.startsWith("javax.ejb.")) {
+                    if (scanPotentialEjbModules && annotationName.startsWith("javax.ejb."))
{
                         if ("javax.ejb.Stateful".equals(annotationName)) return true;
                         if ("javax.ejb.Stateless".equals(annotationName)) return true;
                         if ("javax.ejb.Singleton".equals(annotationName)) return true;
                         if ("javax.ejb.MessageDriven".equals(annotationName)) return true;
-                    } else if (annotationName.startsWith(packageName)){
+                    } else if (scanPotentialClientModules && annotationName.startsWith(packageName)){
                         if (LocalClient.class.getName().equals(annotationName)) otherTypes.add(ClientModule.class);
                         if (RemoteClient.class.getName().equals(annotationName)) otherTypes.add(ClientModule.class);
                     }

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java?rev=898947&r1=898946&r2=898947&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
Wed Jan 13 21:49:18 2010
@@ -33,6 +33,7 @@
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Set;
 
 /**
  * @version $Rev$ $Date$
@@ -43,7 +44,7 @@
     static final String SEARCH_CLASSPATH_FOR_DEPLOYMENTS_PROPERTY = DEPLOYMENTS_CLASSPATH_PROPERTY;
     private static final String CLASSPATH_INCLUDE = "openejb.deployments.classpath.include";
     private static final String CLASSPATH_EXCLUDE = "openejb.deployments.classpath.exclude";
-    private static final String CLASSPATH_REQUIRE_DESCRIPTOR = "openejb.deployments.classpath.require.descriptor";
+    private static final String CLASSPATH_REQUIRE_DESCRIPTOR = RequireDescriptors.PROPERTY;
     private static final String CLASSPATH_FILTER_DESCRIPTORS = "openejb.deployments.classpath.filter.descriptors";
     private static final String CLASSPATH_FILTER_SYSTEMAPPS = "openejb.deployments.classpath.filter.systemapps";
     private static final Logger logger = DeploymentLoader.logger;
@@ -155,7 +156,7 @@
         Options options = SystemInstance.get().getOptions();
         String include = options.get(CLASSPATH_INCLUDE, "");
         String exclude = options.get(CLASSPATH_EXCLUDE, ".*");
-        boolean requireDescriptors = options.get(CLASSPATH_REQUIRE_DESCRIPTOR, false);
+        Set<RequireDescriptors> requireDescriptors = options.getAll(CLASSPATH_REQUIRE_DESCRIPTOR,
RequireDescriptors.CLIENT);
         boolean filterDescriptors = options.get(CLASSPATH_FILTER_DESCRIPTORS, false);
         boolean filterSystemApps = options.get(CLASSPATH_FILTER_SYSTEMAPPS, true);
 
@@ -246,15 +247,20 @@
                 return;
             } else if (size < 20) {
                 logger.debug("Inspecting classpath for applications: " + urls.size() + "
urls.");
-            } else if (size < 50 && !requireDescriptors) {
-                logger.info("Inspecting classpath for applications: " + urls.size() + " urls.
Consider adjusting your exclude/include.  Current settings: " + CLASSPATH_EXCLUDE + "='" +
exclude + "', " + CLASSPATH_INCLUDE + "='" + include + "'");
-            } else if (!requireDescriptors) {
-                logger.warning("Inspecting classpath for applications: " + urls.size() +
" urls.");
-                logger.warning("ADJUST THE EXCLUDE/INCLUDE!!!.  Current settings: " + CLASSPATH_EXCLUDE
+ "='" + exclude + "', " + CLASSPATH_INCLUDE + "='" + include + "'");
+            } else {
+                // Has the user allowed some module types to be discoverable via scraping?
                                                                 
+                boolean willScrape = requireDescriptors.size() < RequireDescriptors.values().length;
+
+                if (size < 50 && willScrape) {
+                    logger.info("Inspecting classpath for applications: " + urls.size() +
" urls. Consider adjusting your exclude/include.  Current settings: " + CLASSPATH_EXCLUDE
+ "='" + exclude + "', " + CLASSPATH_INCLUDE + "='" + include + "'");
+                } else if (willScrape) {
+                    logger.warning("Inspecting classpath for applications: " + urls.size()
+ " urls.");
+                    logger.warning("ADJUST THE EXCLUDE/INCLUDE!!!.  Current settings: " +
CLASSPATH_EXCLUDE + "='" + exclude + "', " + CLASSPATH_INCLUDE + "='" + include + "'");
+                }
             }
 
             long begin = System.currentTimeMillis();
-            processUrls(urls, classLoader, !requireDescriptors, base, jarList);
+            processUrls(urls, classLoader, requireDescriptors, base, jarList);
             long end = System.currentTimeMillis();
             long time = end - begin;
 
@@ -264,7 +270,7 @@
                 if (filterSystemApps){
                     unchecked = unchecked.exclude(".*/openejb-[^/]+(.(jar|ear|war)(./)?|/target/classes/?)");
                 }
-                processUrls(unchecked.getUrls(), classLoader, false, base, jarList);
+                processUrls(unchecked.getUrls(), classLoader, requireDescriptors, base, jarList);
             }
 
             if (logger.isDebugEnabled()) {
@@ -305,12 +311,12 @@
 
     }
 
-    private static void processUrls(List<URL> urls, ClassLoader classLoader, boolean
searchForDescriptorlessApplications, FileUtils base, List<String> jarList) {
+    private static void processUrls(List<URL> urls, ClassLoader classLoader, Set<RequireDescriptors>
requireDescriptors, FileUtils base, List<String> jarList) {
         for (URL url : urls) {
             Deployments deployment;
             String path;
             try {
-                Class<? extends DeploymentModule> moduleType = DeploymentLoader.discoverModuleType(url,
classLoader, searchForDescriptorlessApplications);
+                Class<? extends DeploymentModule> moduleType = DeploymentLoader.discoverModuleType(url,
classLoader, requireDescriptors);
                 if (AppModule.class.isAssignableFrom(moduleType) || EjbModule.class.isAssignableFrom(moduleType)
|| PersistenceModule.class.isAssignableFrom(moduleType) || ConnectorModule.class.isAssignableFrom(moduleType)
|| ClientModule.class.isAssignableFrom(moduleType)) {
                     deployment = JaxbOpenejb.createDeployments();
                     if (url.getProtocol().equals("jar")) {

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/RequireDescriptors.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/RequireDescriptors.java?rev=898947&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/RequireDescriptors.java
(added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/RequireDescriptors.java
Wed Jan 13 21:49:18 2010
@@ -0,0 +1,26 @@
+/**
+ * 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;
+
+/**
+ * @version $Rev$ $Date$
+*/
+public enum RequireDescriptors {
+    EJB, CLIENT;
+
+    public static final String PROPERTY = "openejb.deployments.classpath.require.descriptor";
+}

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



Mime
View raw message