[seam-commits] Seam SVN: r9499 - in branches/enterprise/JBPAPP_4_3_FP01/src/main: org/jboss/seam/deployment and 1 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Nov 4 10:48:04 EST 2008


Author: manaRH
Date: 2008-11-04 10:48:04 -0500 (Tue, 04 Nov 2008)
New Revision: 9499

Added:
   branches/enterprise/JBPAPP_4_3_FP01/src/main/META-INF/seam-deployment.properties
   branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/deployment/SeamDeploymentProperties.java
Modified:
   branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/init/Initialization.java
Log:
JBPAPP-1257

Added: branches/enterprise/JBPAPP_4_3_FP01/src/main/META-INF/seam-deployment.properties
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/main/META-INF/seam-deployment.properties	                        (rev 0)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/main/META-INF/seam-deployment.properties	2008-11-04 15:48:04 UTC (rev 9499)
@@ -0,0 +1 @@
+org.jboss.seam.init.duplicateJarsPatterns=^tmp\\d+(\\S*.jar)
\ No newline at end of file


Property changes on: branches/enterprise/JBPAPP_4_3_FP01/src/main/META-INF/seam-deployment.properties
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/deployment/SeamDeploymentProperties.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/deployment/SeamDeploymentProperties.java	                        (rev 0)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/deployment/SeamDeploymentProperties.java	2008-11-04 15:48:04 UTC (rev 9499)
@@ -0,0 +1,116 @@
+package org.jboss.seam.deployment;
+
+import static org.jboss.seam.util.Strings.split;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Properties;
+
+import org.jboss.seam.util.EnumerationEnumeration;
+
+public class SeamDeploymentProperties
+{
+   
+   private ClassLoader classLoader;
+   private Enumeration<URL> urlEnum;
+   
+   public SeamDeploymentProperties(ClassLoader classLoader)
+   {
+      this.classLoader = classLoader;
+   }
+
+   /**
+    * The resource bundle used to control Seam deployment
+    */
+   public static final String RESOURCE_BUNDLE = "META-INF/seam-deployment.properties";
+   
+   // All resource bundles to use, including legacy names
+   private static final String[] RESOURCE_BUNDLES = { RESOURCE_BUNDLE, "META-INF/seam-scanner.properties" };
+   
+   /**
+    * Get a list of possible values for a given key.
+    * 
+    * First, System properties are tried, followed by the specified resource
+    * bundle (first in classpath only).
+    * 
+    * Colon (:) deliminated lists are split out.
+    * 
+    */
+   public List<String> getPropertyValues(String key)
+   {
+      List<String>values = new ArrayList<String>();
+      addPropertiesFromSystem(key, values);
+      addPropertiesFromResourceBundle(key, values);
+      return values;
+   }
+   
+   private void addPropertiesFromSystem(String key, List<String> values)
+   {
+      addProperty(key, System.getProperty(key), values);
+   }
+   
+   private void addPropertiesFromResourceBundle(String key, List<String> values)
+   {
+      try
+      {  
+         while ( getResources().hasMoreElements() )
+         {
+            URL url = getResources().nextElement();
+            Properties properties = new Properties();
+            InputStream propertyStream = url.openStream();
+            try
+            {
+               properties.load(propertyStream);
+               addProperty(key, properties.getProperty(key), values);
+            }
+            finally
+            {
+               if (propertyStream != null)
+               {
+                  propertyStream.close();
+               }
+            }
+         }
+      }
+      catch (IOException e) 
+      {
+         // No - op, file is optional
+      }
+   }
+   
+   /*
+    * Add the property to the set of properties only if it hasn't already been added
+    */
+   private void addProperty(String key, String value, List<String> values)
+   {
+      if (value != null)
+      {
+         String[] properties = split(value, ":");
+         for (String property : properties)
+         {
+            values.add(property);
+         }
+         
+      }
+   }
+   
+   private Enumeration<URL> getResources() throws IOException
+   {
+      
+      if (urlEnum == null)
+      {
+         Enumeration<URL>[] enumerations = new Enumeration[RESOURCE_BUNDLES.length]; 
+         for (int i = 0; i < RESOURCE_BUNDLES.length; i ++)
+         {   
+            enumerations[i] = classLoader.getResources(RESOURCE_BUNDLES[i]);
+         }
+         urlEnum = new EnumerationEnumeration<URL>(enumerations);
+      }
+      return urlEnum;
+   }
+   
+}


Property changes on: branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/deployment/SeamDeploymentProperties.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/init/Initialization.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/init/Initialization.java	2008-11-04 15:17:25 UTC (rev 9498)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/init/Initialization.java	2008-11-04 15:48:04 UTC (rev 9499)
@@ -20,6 +20,8 @@
 import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.TreeSet;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
@@ -43,6 +45,7 @@
 import org.jboss.seam.core.Init;
 import org.jboss.seam.core.PojoCache;
 import org.jboss.seam.deployment.HotDeploymentStrategy;
+import org.jboss.seam.deployment.SeamDeploymentProperties;
 import org.jboss.seam.deployment.StandardDeploymentStrategy;
 import org.jboss.seam.log.LogProvider;
 import org.jboss.seam.log.Logging;
@@ -63,6 +66,8 @@
 public class Initialization
 {
    public static final String COMPONENT_SUFFIX = ".component";
+   public static final String DUPLICATE_JARS_PATTERNS = "org.jboss.seam.init.duplicateJarsPatterns";
+   
    private static final LogProvider log = Logging.getLogProvider(Initialization.class);
 
    private ServletContext servletContext;
@@ -122,19 +127,68 @@
          throw new RuntimeException("error scanning META-INF/components.xml files", ioe);
       }
 
+      List<String> seenDocuments = new ArrayList<String>();
+      
       Properties replacements = getReplacements();
+      Set<Pattern> duplicateJarPatterns = new HashSet<Pattern>();
+      
+      for (String duplicateJarRegex : new HashSet<String>(new SeamDeploymentProperties(Thread.currentThread().getContextClassLoader()).getPropertyValues(DUPLICATE_JARS_PATTERNS)))
+      {
+         duplicateJarPatterns.add(Pattern.compile(duplicateJarRegex));
+      }
+      
       while (resources.hasMoreElements())
       {
          URL url = resources.nextElement();
-         try
+         
+         boolean skip = false;
+         String path = url.getPath();
+         String prefixPattern = "^(\\S*/)([\\S^/]*.jar)(\\S*)$";
+         Pattern pattern = Pattern.compile(prefixPattern);
+         Matcher matcher = pattern.matcher(path);
+         String jarName;
+         String fileName;
+         if (matcher.matches())
          {
-            log.info("reading " + url);
-            installComponentsFromXmlElements( XML.getRootElement( url.openStream() ), replacements );
+            jarName = matcher.group(2);
+            fileName = matcher.group(3);
+            Set<String> documentNames = new HashSet<String>();
+            for (Pattern duplicateJarPattern : duplicateJarPatterns)
+            {
+               Matcher duplicateMatcher = duplicateJarPattern.matcher(jarName);
+               
+               if (duplicateMatcher.matches())
+               {
+                  jarName = duplicateMatcher.group(1);
+               }
+               
+               documentNames.add(jarName + fileName);
+            }
+            for (String documentName : documentNames)
+            {
+               if (seenDocuments.contains(documentName))
+               {
+                  skip = true;
+               }
+            }
+            seenDocuments.addAll(documentNames);
          }
-         catch (Exception e)
+         if (!skip)
          {
-            throw new RuntimeException("error while reading " + url, e);
+            try
+            {
+               log.debug("reading " + url);
+               installComponentsFromXmlElements( XML.getRootElement( url.openStream() ), replacements );
+            }
+            catch (Exception e)
+            {
+               throw new RuntimeException("error while reading " + url, e);
+            }
          }
+         else
+         {
+            log.trace("skipping read of duplicate components.xml " + url);
+         }
       }
 
    }




More information about the seam-commits mailing list