[jboss-cvs] jboss/src/main/org/jboss/deployment ...

Scott Stark scott.stark at jboss.com
Mon Jul 24 12:12:45 EDT 2006


  User: starksm 
  Date: 06/07/24 12:12:45

  Modified:    src/main/org/jboss/deployment   EARDeployer.java
                        J2eeApplicationMetaData.java
  Log:
  JBAS-3411, add support for ear deployments without application.xml and ear library-directory
  
  Revision  Changes    Path
  1.44      +199 -21   jboss/src/main/org/jboss/deployment/EARDeployer.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: EARDeployer.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/deployment/EARDeployer.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -b -r1.43 -r1.44
  --- EARDeployer.java	29 Dec 2005 19:42:20 -0000	1.43
  +++ EARDeployer.java	24 Jul 2006 16:12:45 -0000	1.44
  @@ -24,14 +24,19 @@
   import java.io.File;
   import java.io.IOException;
   import java.io.InputStream;
  +import java.io.FileInputStream;
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.security.Policy;
   import java.util.Enumeration;
   import java.util.HashMap;
   import java.util.Iterator;
  +import java.util.ArrayList;
   import java.util.jar.JarEntry;
   import java.util.jar.JarFile;
  +import java.util.jar.Manifest;
  +import java.util.jar.Attributes;
  +import java.util.jar.JarInputStream;
   
   import javax.management.ObjectName;
   import javax.security.jacc.PolicyConfiguration;
  @@ -49,12 +54,9 @@
   /**
    * Enterprise Archive Deployer.
    *
  - * @jmx:mbean name="jboss.j2ee:service=EARDeployer"
  - *            extends="org.jboss.deployment.SubDeployerMBean"
  - *
    * @author <a href="mailto:marc.fleury at jboss.org">Marc Fleury</a>
    * @author Scott.Stark at jboss.org
  - * @version $Revision: 1.43 $
  + * @version $Revision: 1.44 $
    */
   public class EARDeployer extends SubDeployerSupport
      implements EARDeployerMBean
  @@ -79,7 +81,6 @@
      }
      
      /**
  -    * @jmx:managed-attribute
       * @return whether ear deployments should be isolated
       */
      public boolean isIsolated()
  @@ -88,7 +89,6 @@
      }
      
      /**
  -    * @jmx:managed-attribute
       * @param isolated whether ear deployments should be isolated
       */
      public void setIsolated(boolean isolated)
  @@ -97,7 +97,6 @@
      }
      
      /**
  -    * @jmx:managed-attribute
       * @return whether ear deployments should be call by value
       */
      public boolean isCallByValue()
  @@ -106,7 +105,6 @@
      }
      
      /**
  -    * @jmx:managed-attribute
       * @param callByValue whether ear deployments should be call by value
       */
      public void setCallByValue(boolean callByValue)
  @@ -127,20 +125,31 @@
         try
         {
            log.info("Init J2EE application: " + di.url);
  -
            InputStream in = di.localCl.getResourceAsStream("META-INF/application.xml");
  -         if( in == null )
  -            throw new DeploymentException("No META-INF/application.xml found");
  -
  +         boolean hasAppXml = in != null;
  +         J2eeApplicationMetaData metaData = new J2eeApplicationMetaData();
  +         if( hasAppXml )
  +         {
            /* Don't require validation of application.xml since an ear may
            just contain a jboss sar specified in the jboss-app.xml descriptor.
            */
            XmlFileLoader xfl = new XmlFileLoader(false);
  -         J2eeApplicationMetaData metaData = new J2eeApplicationMetaData();
            Element application = xfl.getDocument(in, "META-INF/application.xml").getDocumentElement();
            metaData.importXml(application);
  -         di.metaData = metaData;
            in.close();
  +         }
  +         else
  +         {
  +            // Scan the ear for modules
  +            scanEar(metaData, di);
  +         }
  +         di.metaData = metaData;
  +
  +         // If there is a library-directory add its jars to the classpath
  +         if( metaData.getLibraryDirectory() != null )
  +         {
  +            addLibraryJars(di, metaData.getLibraryDirectory());
  +         }
   
            // Check for a jboss-app.xml descriptor
            Element loader = null;
  @@ -148,7 +157,7 @@
            if( in != null )
            {
               // Create a new parser with validation enabled for jboss-app.xml
  -            xfl = new XmlFileLoader(true);
  +            XmlFileLoader xfl = new XmlFileLoader(true);
               Element jbossApp = xfl.getDocument(in, "META-INF/jboss-app.xml").getDocumentElement();
               in.close();
               // Import module/service archives to metadata
  @@ -407,4 +416,173 @@
      protected void processNestedDeployments(DeploymentInfo di)
      {
      }
  +
  +   /**
  +   For an ear without an application.xml, determine modules via:
  +   a. All ear modules with an extension of .war are considered web modules. The
  +    context root of the web module is the name of the file relative to the root
  +    of the application package, with the .war extension removed.
  +   b. All ear modules with extension of .rar are considered resource adapters.
  +   c. A directory named lib is considered to be the library directory, as
  +    described in Section EE.8.2.1, “Bundled Libraries.”
  +   d. For all ear modules with a filename extension of .jar, but not in the lib
  +    directory, do the following:
  +   i. If the JAR file contains a META-INF/MANIFEST.MF file with a Main-Class
  +    attribute, or contains a META-INF/application-client.xml file, consider the
  +    jar file to be an application client module.
  +   ii. If the JAR file contains a META-INF/ejb-jar.xml file, or contains any
  +   class with an EJB component annotation (Stateless, etc.), consider the JAR
  +    file to be an EJB module.
  +   iii. All other JAR files are ignored unless referenced by a JAR file
  +    discovered above using one of the JAR file reference mechanisms such as the
  +    Class-Path header in a manifest file.
  +    * TODO: rewrite using vfs
  +    * @param metaData
  +    * @param di
  +    */
  +   private void scanEar(J2eeApplicationMetaData metaData, DeploymentInfo di)
  +      throws IOException
  +   {
  +      if (di.isDirectory) 
  +      {
  +         File earDir = new File(di.localUrl.getFile());
  +         String[] content = earDir.list();
  +         int length = content != null ? content.length : 0;
  +         for(int n = 0; n < length; n ++)
  +         {
  +            String module = content[n];
  +            if( module.endsWith(".war") )
  +            {
  +               J2eeModuleMetaData war = new J2eeModuleMetaData(J2eeModuleMetaData.WEB, module);
  +               metaData.addModule(war);
  +            }
  +            else if( module.endsWith(".rar") )
  +            {
  +               J2eeModuleMetaData war = new J2eeModuleMetaData(J2eeModuleMetaData.CONNECTOR, module);
  +               metaData.addModule(war);
  +            }
  +            else if( module.endsWith(".jar") )
  +            {
  +               File mfFile = new File(earDir, module+"/META-INF/MANIFEST.MF");
  +               File clientXml = new File(earDir, module+"/META-INF/application-client.xml");
  +               File ejbXml = new File(earDir, module+"/META-INF/ejb-jar.xml");
  +               if( clientXml.exists() )
  +               {
  +                  J2eeModuleMetaData car = new J2eeModuleMetaData(J2eeModuleMetaData.CONNECTOR, module);
  +                  metaData.addModule(car);
  +               }
  +               else if( mfFile.exists() )
  +               {
  +                  FileInputStream fis = new FileInputStream(mfFile);
  +                  Manifest mf = new Manifest(fis);
  +                  fis.close();
  +                  Attributes attrs = mf.getMainAttributes();
  +                  if( attrs.containsKey(Attributes.Name.MAIN_CLASS) )
  +                  {
  +                     J2eeModuleMetaData car = new J2eeModuleMetaData(J2eeModuleMetaData.CONNECTOR, module);
  +                     metaData.addModule(car);                     
  +                  }
  +               }
  +               else if( ejbXml.exists() )
  +               {
  +                  J2eeModuleMetaData ejb = new J2eeModuleMetaData(J2eeModuleMetaData.EJB, module);
  +                  metaData.addModule(ejb);
  +               }
  +               else
  +               {
  +                  // TODO: scan for annotations
  +               }
  +            }
  +         }
  +      }
  +      else
  +      {
  +         JarFile earFile = new JarFile(di.localUrl.getFile());
  +         for (Enumeration e = earFile.entries(); e.hasMoreElements();)
  +         {
  +            JarEntry entry = (JarEntry)e.nextElement();
  +            String module = entry.getName();
  +            if( module.endsWith(".war") )
  +            {
  +               J2eeModuleMetaData war = new J2eeModuleMetaData(J2eeModuleMetaData.WEB, module);
  +               metaData.addModule(war);
  +            }
  +            else if( module.endsWith(".rar") )
  +            {
  +               J2eeModuleMetaData war = new J2eeModuleMetaData(J2eeModuleMetaData.CONNECTOR, module);
  +               metaData.addModule(war);
  +            }
  +            else if( module.endsWith(".jar") )
  +            {
  +               InputStream is = earFile.getInputStream(entry);
  +               JarInputStream jis = new JarInputStream(is);
  +               Manifest mf = jis.getManifest();
  +               if( mf != null )
  +               {
  +                  Attributes attrs = mf.getMainAttributes();
  +                  if( attrs.containsKey(Attributes.Name.MAIN_CLASS) )
  +                  {
  +                     J2eeModuleMetaData car = new J2eeModuleMetaData(J2eeModuleMetaData.CONNECTOR, module);
  +                     metaData.addModule(car);                     
  +                     jis.close();
  +                     continue;
  +                  }
  +               }
  +               JarEntry jarEntry = jis.getNextJarEntry();
  +               while( jarEntry != null )
  +               {
  +                  String name = jarEntry.getName();
  +                  if( name.equals("META-INF/application-client.xml") )
  +                  {
  +                     J2eeModuleMetaData car = new J2eeModuleMetaData(J2eeModuleMetaData.CONNECTOR, module);
  +                     metaData.addModule(car);
  +                  }
  +                  else if( name.equals("META-INF/ejb-jar.xml") )
  +                  {
  +                     J2eeModuleMetaData ejb = new J2eeModuleMetaData(J2eeModuleMetaData.EJB, module);
  +                     metaData.addModule(ejb);
  +                  }
  +                  jarEntry = jis.getNextJarEntry();
  +               }
  +               jis.close();
  +               // TODO: scan for annotations
  +            }
  +         }
  +      }
  +   }
  +
  +   /**
  +    * Add any ear library-directory jars to the deployment classpath
  +    * @param di
  +    * @param lib
  +    * @throws IOException
  +    */
  +   private void addLibraryJars(DeploymentInfo di, String lib)
  +      throws IOException
  +   {
  +      if (di.isDirectory) 
  +      {
  +         File earDir = new File(di.localUrl.getFile(), lib);
  +         String[] content = earDir.list();
  +         int length = content != null ? content.length : 0;
  +         for(int n = 0; n < length; n ++)
  +         {
  +            String path = "lib/" + content[n];
  +            URL jarURL = new URL(di.localUrl, path);
  +            di.addLibraryJar(jarURL);
  +         }
  +      }
  +      else
  +      {
  +         JarFile earFile = new JarFile(di.localUrl.getFile());
  +         for (Enumeration e = earFile.entries(); e.hasMoreElements();)
  +         {
  +            JarEntry entry = (JarEntry)e.nextElement();
  +            String path = "lib/" + entry.getName();
  +            URL jarURL = new URL(di.localUrl, path);
  +            di.addLibraryJar(jarURL);
  +         }
  +      }
  +   }
  +
   }
  
  
  
  1.13      +34 -4     jboss/src/main/org/jboss/deployment/J2eeApplicationMetaData.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: J2eeApplicationMetaData.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/deployment/J2eeApplicationMetaData.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -b -r1.12 -r1.13
  --- J2eeApplicationMetaData.java	12 Jan 2006 11:59:17 -0000	1.12
  +++ J2eeApplicationMetaData.java	24 Jul 2006 16:12:45 -0000	1.13
  @@ -39,7 +39,8 @@
    * descriptors.
    *
    * @author Thomas.Diesler at jboss.org
  - * @version $Revision: 1.12 $
  + * @author Scott.Stark at jboss.org
  + * @version $Revision: 1.13 $
    * @see org.jboss.metadata.XmlLoadable
    */
   public class J2eeApplicationMetaData
  @@ -52,6 +53,10 @@
      private String description;
      private String smallIcon;
      private String largeIcon;
  +   /** The library-directory name, defaults to lib */
  +   private String libDirName = "lib";
  +   /** The application element version */
  +   private String version;  
   
      /**
       * The security-roles
  @@ -75,6 +80,11 @@
   
      // Public --------------------------------------------------------
   
  +   public String getVersion()
  +   {
  +      return version;
  +   }
  +
      public String getDisplayName()
      {
         return displayName;
  @@ -125,6 +135,20 @@
         return jmxName;
      }
      
  +   public String getLibraryDirectory()
  +   {
  +      return libDirName;
  +   }
  +
  +   /**
  +    * Add a module to the module map.
  +    * @param moduleMetaData
  +    */
  +   public void addModule(J2eeModuleMetaData moduleMetaData)
  +   {
  +      this.modules.put(moduleMetaData.getFileName(), moduleMetaData);
  +   }
  +
      /**
       * Imports either the application.xml or jboss-app.xml from the given element.
       *
  @@ -150,6 +174,7 @@
   
      protected void importApplicationXml(Element rootElement) throws DeploymentException
      {
  +      version = getElementAttribute(rootElement, "version");
         // j2ee_1_4.xsd describes display-name as minOccurs="0" to maxOccurs="unbounded"
         displayName = super.getOptionalChildContent(rootElement, "display-name", "");
   
  @@ -171,12 +196,17 @@
            largeIcon = "";
         }
   
  +      // Look for an ear library-directory
  +      libDirName = getOptionalChildContent(rootElement, "library-directory", "lib");
  +      if( libDirName != null && libDirName.length() == 0 )
  +         libDirName = null;
  +
         // extract modules...
         for (Iterator it = getChildrenByTagName(rootElement, "module"); it.hasNext();)
         {
            J2eeModuleMetaData moduleMetaData = new J2eeModuleMetaData();
            moduleMetaData.importXml((Element) it.next());
  -         modules.put(moduleMetaData.getFileName(), moduleMetaData);
  +         addModule(moduleMetaData);
         }
      }
   
  @@ -236,7 +266,7 @@
         {
            J2eeModuleMetaData moduleMetaData = new J2eeModuleMetaData();
            moduleMetaData.importXml((Element) it.next());
  -         modules.put(moduleMetaData.getFileName(), moduleMetaData);
  +         addModule(moduleMetaData);
         }
      }
   }
  
  
  



More information about the jboss-cvs-commits mailing list