[jboss-cvs] JBossAS SVN: r64357 - in trunk/server/src: main/org/jboss/deployment and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jul 30 20:10:51 EDT 2007
Author: scott.stark at jboss.org
Date: 2007-07-30 20:10:51 -0400 (Mon, 30 Jul 2007)
New Revision: 64357
Added:
trunk/server/src/main/org/jboss/deployment/EARContentsDeployer.java
Modified:
trunk/server/src/etc/deployers/ear-deployer-beans.xml
trunk/server/src/main/org/jboss/deployment/EARStructure.java
Log:
JBCTS-636, Add a J2eeApplicationMetaData producing deployer that runs if there is no application.xml.
Modified: trunk/server/src/etc/deployers/ear-deployer-beans.xml
===================================================================
--- trunk/server/src/etc/deployers/ear-deployer-beans.xml 2007-07-30 22:17:10 UTC (rev 64356)
+++ trunk/server/src/etc/deployers/ear-deployer-beans.xml 2007-07-31 00:10:51 UTC (rev 64357)
@@ -1,17 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- EAR Deployer
+ EAR Deployers
+ $Id$
-->
<deployment xmlns="urn:jboss:bean-deployer:2.0">
<bean name="EARStructureDeployer" class="org.jboss.deployment.EARStructure"/>
+ <!-- application.xml parsing deployer -->
<bean name="AppParsingDeployer" class="org.jboss.deployment.AppParsingDeployer">
<property name="type">ear</property>
<property name="useSchemaValidation">true</property>
<!-- What is this? property name="useValidation">false</property -->
</bean>
+ <!-- Implicit ear contents identifying deployer for ears without
+ an application.xml
+ -->
+ <bean name="EARContentsDeployer" class="org.jboss.deployment.EARContentsDeployer">
+ <constructor>
+ <parameter><inject bean="AppParsingDeployer" property="relativeOrder"/></parameter>
+ </constructor>
+
+ <property name="type">ear</property>
+ <!-- Does the deployment have to end in .ear to process it -->
+ <property name="requiresEarSuffix">true</property>
+ </bean>
+ <!-- jboss-app.xml parsing deployer -->
<bean name="JBossAppParsingDeployer" class="org.jboss.deployment.JBossAppParsingDeployer">
<property name="type">ear</property>
<!-- A flag indicating if ear deployments should have their own scoped
Added: trunk/server/src/main/org/jboss/deployment/EARContentsDeployer.java
===================================================================
--- trunk/server/src/main/org/jboss/deployment/EARContentsDeployer.java (rev 0)
+++ trunk/server/src/main/org/jboss/deployment/EARContentsDeployer.java 2007-07-31 00:10:51 UTC (rev 64357)
@@ -0,0 +1,246 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.deployment;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.metadata.XmlFileLoader;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
+import org.w3c.dom.Element;
+
+/**
+ * An implicit application.xml type of deployer. This deployer runs if
+ * there is no META-INF/application.xml to identify
+ * {@link #scanEar(VirtualFile, J2eeApplicationMetaData)}
+ *
+ * @author Bill Burke
+ * @author Scott.Stark at jboss.org
+ * @author adrian at jboss.org
+ * @version $Revision$
+ */
+public class EARContentsDeployer extends AbstractDeployer
+{
+ /** Does the deployment have to end in .ear to process it */
+ private boolean requiresEarSuffix = false;
+
+ /**
+ *
+ */
+ public EARContentsDeployer(int appParsingOrder)
+ {
+ setStage(DeploymentStages.PARSE);
+ setRelativeOrder(appParsingOrder+1);
+ setOutput(J2eeApplicationMetaData.class);
+ }
+
+ public boolean isRequiresEarSuffix()
+ {
+ return requiresEarSuffix;
+ }
+ public void setRequiresEarSuffix(boolean requiresEarSuffix)
+ {
+ this.requiresEarSuffix = requiresEarSuffix;
+ }
+
+ public void deploy(DeploymentUnit unit) throws DeploymentException
+ {
+ // Ignore non-parent deployments
+ if (unit.getParent() != null)
+ {
+ return;
+ }
+ // Ignore non-vfs deployments
+ if (unit instanceof VFSDeploymentUnit == false)
+ {
+ log.trace("Not a vfs deployment: " + unit.getName());
+ return;
+ }
+ //
+ if (requiresEarSuffix && unit.getSimpleName().endsWith(".ear") == false)
+ {
+ log.trace("Unit name does not end in .ear: " + unit.getSimpleName());
+ return;
+ }
+ VFSDeploymentUnit vfsunit = VFSDeploymentUnit.class.cast(unit);
+ // If there is a META-INF/application.xml
+ VirtualFile appXml = vfsunit.getMetaDataFile("application.xml");
+ if( appXml != null )
+ {
+ log.trace("Ignoring ear with META-INF/application.xml: " + unit.getSimpleName());
+ return;
+ }
+
+ deploy(vfsunit);
+ }
+
+ public void deploy(VFSDeploymentUnit unit) throws DeploymentException
+ {
+ VirtualFile root = unit.getRoot();
+ VirtualFile ear = unit.getFile(unit.getRelativePath());
+ deploy(unit, root, ear);
+ }
+
+ protected void deploy(VFSDeploymentUnit unit, VirtualFile root, VirtualFile file)
+ {
+ try
+ {
+ VirtualFile jbossAppXml = unit.getMetaDataFile("jboss-app.xml");
+ J2eeApplicationMetaData j2eeMetaData = new J2eeApplicationMetaData();
+
+ if (jbossAppXml != null)
+ {
+ InputStream in = jbossAppXml.openStream();
+ try
+ {
+ XmlFileLoader xfl = new XmlFileLoader(false);
+ Element jbossApp = xfl.getDocument(in, "META-INF/jboss-app.xml").getDocumentElement();
+ j2eeMetaData.importXml(jbossApp);
+ }
+ finally
+ {
+ in.close();
+ }
+ }
+
+ // TODO: need to scan for annotationss
+ scanEar(unit, file, j2eeMetaData);
+
+ unit.addAttachment(J2eeApplicationMetaData.class, j2eeMetaData);
+ }
+ catch(Exception e)
+ {
+ throw new RuntimeException("Error determining ear contents: " + file.getName(), e);
+ }
+ }
+
+ /**
+ 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.
+ */
+ private void scanEar(VFSDeploymentUnit unit, VirtualFile root, J2eeApplicationMetaData j2eeMetaData)
+ throws IOException
+ {
+ List<VirtualFile> archives = root.getChildren();
+ if (archives != null)
+ {
+ String earPath = root.getPathName();
+ for (VirtualFile vfArchive : archives)
+ {
+ String filename = earRelativePath(earPath, vfArchive.getPathName());
+ // Check if the module already exists, i.e. it is declared in jboss-app.xml
+ J2eeModuleMetaData moduleMetaData = j2eeMetaData.getModule(filename);
+ int type = typeFromSuffix(unit, filename, vfArchive);
+ if (type >= 0 && moduleMetaData == null)
+ {
+ moduleMetaData = new J2eeModuleMetaData(type, filename);
+ j2eeMetaData.addModule(moduleMetaData);
+ }
+ }
+ }
+ }
+
+ private int typeFromSuffix(VFSDeploymentUnit unit, String path, VirtualFile archive)
+ throws IOException
+ {
+ int type = -1;
+ if( path.endsWith(".war") )
+ type = J2eeModuleMetaData.WEB;
+ else if( path.endsWith(".rar") )
+ type = J2eeModuleMetaData.CONNECTOR;
+ else if( path.endsWith(".har") )
+ type = J2eeModuleMetaData.HAR;
+ else if( path.endsWith(".sar") )
+ type = J2eeModuleMetaData.SERVICE;
+ else if( path.endsWith(".jar") )
+ {
+ // Look for a META-INF/application-client.xml
+ VirtualFile mfFile = unit.getMetaDataFile("MANIFEST.MF");
+ VirtualFile clientXml = unit.getMetaDataFile("application-client.xml");
+ VirtualFile ejbXml = unit.getMetaDataFile("ejb-jar.xml");
+ VirtualFile jbossXml = unit.getMetaDataFile("jboss.xml");
+
+ if( clientXml != null )
+ {
+ type = J2eeModuleMetaData.CLIENT;
+ }
+ else if( mfFile != null )
+ {
+ Manifest mf = VFSUtils.readManifest(mfFile);
+ Attributes attrs = mf.getMainAttributes();
+ if( attrs.containsKey(Attributes.Name.MAIN_CLASS) )
+ {
+ type = J2eeModuleMetaData.CLIENT;
+ }
+ else
+ {
+ // TODO: scan for annotations. Assume EJB for now
+ type = J2eeModuleMetaData.EJB;
+ }
+ }
+ else if( ejbXml != null || jbossXml != null )
+ {
+ type = J2eeModuleMetaData.EJB;
+ }
+ else
+ {
+ // TODO: scan for annotations. Assume EJB for now
+ type = J2eeModuleMetaData.EJB;
+ }
+ }
+
+ return type;
+ }
+
+ private String earRelativePath(String earPath, String pathName)
+ {
+ StringBuilder tmp = new StringBuilder(pathName);
+ tmp.delete(0, earPath.length());
+ return tmp.toString();
+ }
+
+}
Property changes on: trunk/server/src/main/org/jboss/deployment/EARContentsDeployer.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Modified: trunk/server/src/main/org/jboss/deployment/EARStructure.java
===================================================================
--- trunk/server/src/main/org/jboss/deployment/EARStructure.java 2007-07-30 22:17:10 UTC (rev 64356)
+++ trunk/server/src/main/org/jboss/deployment/EARStructure.java 2007-07-31 00:10:51 UTC (rev 64357)
@@ -33,6 +33,7 @@
import org.jboss.deployers.vfs.spi.structure.VFSStructuralDeployers;
import org.jboss.deployers.vfs.spi.structure.helpers.AbstractStructureDeployer;
import org.jboss.metadata.XmlFileLoader;
+import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.VirtualFileFilter;
import org.jboss.virtual.plugins.vfs.helpers.SuffixMatchFilter;
@@ -105,6 +106,7 @@
VirtualFile jbossAppXml = getMetaDataFile(file, "META-INF/jboss-app.xml");
VirtualFile lib;
J2eeApplicationMetaData j2eeMetaData = new J2eeApplicationMetaData();
+
boolean scan = true;
if (applicationXml != null)
@@ -286,17 +288,7 @@
}
else if( mfFile != null )
{
- // TODO - use VFSUtils.readManifest
- InputStream is = mfFile.openStream();
- Manifest mf;
- try
- {
- mf = new Manifest(is);
- }
- finally
- {
- is.close();
- }
+ Manifest mf = VFSUtils.readManifest(mfFile);
Attributes attrs = mf.getMainAttributes();
if( attrs.containsKey(Attributes.Name.MAIN_CLASS) )
{
More information about the jboss-cvs-commits
mailing list