geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: incubator-geronimo/modules/j2ee maven.xml
Date Wed, 23 Jun 2004 21:58:22 GMT
dain        2004/06/23 14:58:22

  Modified:    modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment
                        EARConfigBuilder.java
               modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment
                        EARConfigBuilderTest.java
               modules/j2ee maven.xml
  Log:
  Added support for deployment of ear files without a geronimo-application.xml file
  
  Revision  Changes    Path
  1.11      +67 -24    incubator-geronimo/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java
  
  Index: EARConfigBuilder.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- EARConfigBuilder.java	23 Jun 2004 20:24:45 -0000	1.10
  +++ EARConfigBuilder.java	23 Jun 2004 21:58:22 -0000	1.11
  @@ -35,7 +35,6 @@
   import java.util.jar.JarOutputStream;
   import java.util.jar.Manifest;
   import java.util.zip.ZipEntry;
  -
   import javax.management.MalformedObjectNameException;
   import javax.management.ObjectName;
   
  @@ -66,6 +65,8 @@
    * @version $Revision$ $Date$
    */
   public class EARConfigBuilder implements ConfigurationBuilder {
  +    private static final String PARENT_ID = "org/apache/geronimo/Server";
  +
       private final Kernel kernel;
       private final Repository repository;
       private final ModuleBuilder ejbConfigBuilder;
  @@ -102,35 +103,44 @@
       }
   
       public XmlObject getDeploymentPlan(URL module) throws XmlException {
  -        XmlObject plan;
   
           try {
  -            URL gerAppURL = new URL("jar:" + module.toString() + "!/META-INF/geronimo-application.xml");
  -            plan = XmlBeansUtil.getXmlObject(gerAppURL, GerApplicationDocument.type);
  -            if (plan != null) {
  -                return plan;
  +            URL moduleBase;
  +            if (module.toString().endsWith("/")) {
  +                moduleBase = module;
  +            } else {
  +                moduleBase = new URL("jar:" + module.toString() + "!/");
  +            }
  +            GerApplicationDocument gerAppDoc = (GerApplicationDocument) XmlBeansUtil.getXmlObject(new
URL(moduleBase, "META-INF/geronimo-application.xml"), GerApplicationDocument.type);
  +            if (gerAppDoc != null) {
  +                return gerAppDoc.getApplication();
  +            }
  +
  +            // try to create a default plan (will return null if this is not an ear file)
  +            GerApplicationType defaultPlan = createDefaultPlan(moduleBase);
  +            if (defaultPlan != null) {
  +                return defaultPlan;
               }
           } catch (MalformedURLException e) {
           }
   
           // support a naked modules
  -
           if (webConfigBuilder != null) {
  -            plan = webConfigBuilder.getDeploymentPlan(module);
  +            XmlObject plan = webConfigBuilder.getDeploymentPlan(module);
               if (plan != null) {
                   return plan;
               }
           }
   
           if (ejbConfigBuilder != null) {
  -            plan = ejbConfigBuilder.getDeploymentPlan(module);
  +            XmlObject plan = ejbConfigBuilder.getDeploymentPlan(module);
               if (plan != null) {
                   return plan;
               }
           }
   
           if (connectorConfigBuilder != null) {
  -            plan = connectorConfigBuilder.getDeploymentPlan(module);
  +            XmlObject plan = connectorConfigBuilder.getDeploymentPlan(module);
               if (plan != null) {
                   return plan;
               }
  @@ -139,6 +149,41 @@
           return null;
       }
   
  +    private GerApplicationType createDefaultPlan(URL moduleBase) throws XmlException {
  +        // load the web.xml
  +        URL applicationXmlUrl = null;
  +        try {
  +            applicationXmlUrl = new URL(moduleBase, "META-INF/application.xml");
  +        } catch (MalformedURLException e) {
  +            return null;
  +        }
  +        ApplicationDocument applicationDoc = (ApplicationDocument) XmlBeansUtil.getXmlObject(applicationXmlUrl,
ApplicationDocument.type);
  +        if (applicationDoc == null) {
  +            return null;
  +        }
  +
  +        // construct the empty geronimo-application.xml
  +        GerApplicationType gerApplication = GerApplicationType.Factory.newInstance();
  +
  +        // set the parentId and configId
  +        gerApplication.setParentId(PARENT_ID);
  +        String id = applicationDoc.getApplication().getId();
  +        if (id == null) {
  +            id = moduleBase.getFile();
  +            if (id.endsWith("!/")) {
  +                id = id.substring(0, id.length()-2);
  +            }
  +            if (id.endsWith(".ear")) {
  +                id = id.substring(0, id.length()-4);
  +            }
  +            id = id.substring(id.lastIndexOf('/') + 1);
  +        }
  +
  +        gerApplication.setConfigId(id);
  +        return gerApplication;
  +    }
  +
  +
       public void buildConfiguration(File outfile, Manifest manifest, InputStream is, XmlObject
plan) throws IOException, DeploymentException {
           File tmp = FileUtil.toTempFile(is);
           buildConfiguration(outfile, manifest, new JarFile(tmp), plan);
  @@ -199,9 +244,9 @@
               }
   
               // add dependencies declared in the geronimo-application.xml
  -            if (plan instanceof GerApplicationDocument) {
  -                GerApplicationDocument geronimoDoc = (GerApplicationDocument) plan;
  -                GerDependencyType[] dependencies = geronimoDoc.getApplication().getDependencyArray();
  +            if (plan instanceof GerApplicationType) {
  +                GerApplicationType geronimoApplication = (GerApplicationType) plan;
  +                GerDependencyType[] dependencies = geronimoApplication.getDependencyArray();
                   for (int i = 0; i < dependencies.length; i++) {
                       earContext.addDependency(getDependencyURI(dependencies[i]));
                   }
  @@ -221,9 +266,9 @@
               }
   
               // add gbeans declared in the geronimo-application.xml
  -            if (plan instanceof GerApplicationDocument) {
  -                GerApplicationDocument geronimoDoc = (GerApplicationDocument) plan;
  -                GerGbeanType[] gbeans = geronimoDoc.getApplication().getGbeanArray();
  +            if (plan instanceof GerApplicationType) {
  +                GerApplicationType geronimoApplication = (GerApplicationType) plan;
  +                GerGbeanType[] gbeans = geronimoApplication.getGbeanArray();
                   for (int i = 0; i < gbeans.length; i++) {
                       GBeanHelper.addGbean(new GerGBeanAdapter(gbeans[i]), cl, earContext);
                   }
  @@ -262,7 +307,7 @@
   
       private ApplicationType addModules(URI configId, XmlObject plan, JarFile earFile, Set
moduleLocations, Set modules) throws DeploymentException, IOException {
           ApplicationType application;
  -        if (plan instanceof GerApplicationDocument) {
  +        if (plan instanceof GerApplicationType) {
               try {
                   JarEntry appXMLEntry = earFile.getJarEntry("META-INF/application.xml");
                   if (appXMLEntry == null) {
  @@ -333,9 +378,8 @@
       }
   
       private URI getParentId(XmlObject plan) throws DeploymentException {
  -        if (plan instanceof GerApplicationDocument) {
  -            GerApplicationType application = ((GerApplicationDocument) plan).getApplication();
  -
  +        if (plan instanceof GerApplicationType) {
  +            GerApplicationType application = (GerApplicationType) plan;
               if (application.isSetParentId()) {
                   try {
                       return new URI(application.getParentId());
  @@ -369,9 +413,8 @@
       }
   
       private URI getConfigId(XmlObject plan) throws DeploymentException {
  -        if (plan instanceof GerApplicationDocument) {
  -            GerApplicationType application = ((GerApplicationDocument) plan).getApplication();
  -
  +        if (plan instanceof GerApplicationType) {
  +            GerApplicationType application = (GerApplicationType) plan;
               try {
                   return new URI(application.getConfigId());
               } catch (URISyntaxException e) {
  
  
  
  1.3       +22 -1     incubator-geronimo/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/EARConfigBuilderTest.java
  
  Index: EARConfigBuilderTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/EARConfigBuilderTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- EARConfigBuilderTest.java	11 Jun 2004 19:18:21 -0000	1.2
  +++ EARConfigBuilderTest.java	23 Jun 2004 21:58:22 -0000	1.3
  @@ -85,6 +85,27 @@
           }
       }
   
  +    public void testNakedEarBuildConfiguration() throws Exception {
  +        MockEJBConfigBuilder ejbConfigBuilder = new MockEJBConfigBuilder();
  +        MockWARConfigBuilder webConfigBuilder = new MockWARConfigBuilder();
  +        MockConnectorConfigBuilder connectorConfigBuilder = new MockConnectorConfigBuilder();
  +        EARConfigBuilder configBuilder = new EARConfigBuilder(null, null, j2eeServer, ejbConfigBuilder,
webConfigBuilder, connectorConfigBuilder, transactionManagerObjectName, connectionTrackerObjectName);
  +        File earFile = new File("target/test-naked-ear.ear");
  +
  +        File carFile = File.createTempFile("EARTest", ".car");
  +        try {
  +            ejbConfigBuilder.ejbModule = new EJBModule("test-ejb-jar.jar", URI.create("test-ejb-jar.jar"));
  +            webConfigBuilder.contextRoot = "test";
  +            webConfigBuilder.webModule = new WebModule("test-war.war", URI.create("test-war.war"),
"test");
  +            connectorConfigBuilder.connectorModule = new ConnectorModule("test-rar.rar",
URI.create("test-rar.rar"));
  +
  +            XmlObject plan = configBuilder.getDeploymentPlan(earFile.toURL());
  +            configBuilder.buildConfiguration(carFile, null, earFile, plan);
  +        } finally {
  +            carFile.delete();
  +        }
  +    }
  +
       public void testNoEJBDeployer() throws Exception {
           MockWARConfigBuilder warConfigBuilder = new MockWARConfigBuilder();
           MockConnectorConfigBuilder connectorConfigBuilder = new MockConnectorConfigBuilder();
  
  
  
  1.3       +12 -1     incubator-geronimo/modules/j2ee/maven.xml
  
  Index: maven.xml
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/j2ee/maven.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- maven.xml	21 Jun 2004 20:33:32 -0000	1.2
  +++ maven.xml	23 Jun 2004 21:58:22 -0000	1.3
  @@ -72,5 +72,16 @@
               </fileset>
           </ant:jar>
           
  +        <!-- Build test-naked-ear -->
  +        <ant:jar destfile="${basedir}/target/test-naked-ear.ear" >
  +            <fileset dir="${basedir}/target">
  +                <include name="test-ejb-jar.jar"/>
  +                <include name="test-war.war"/>
  +            </fileset>
  +            <fileset dir="${basedir}/src/test-ear">
  +                <include name="META-INF/*"/>
  +                <exclude name="META-INF/geronimo-application.xml"/>
  +            </fileset>
  +        </ant:jar>
       </preGoal>
   </project>
  
  
  

Mime
View raw message