geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject cvs commit: incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment WARConfigBuilder.java
Date Sat, 21 Feb 2004 19:51:29 GMT
jboynes     2004/02/21 11:51:29

  Modified:    modules/connector/src/java/org/apache/geronimo/connector/deployment
                        AbstractRARConfigBuilder.java
               modules/deployment/src/java/org/apache/geronimo/deployment
                        ConfigurationBuilder.java
               modules/deployment/src/java/org/apache/geronimo/deployment/service
                        ServiceConfigBuilder.java
               modules/jetty/src/java/org/apache/geronimo/jetty/deployment
                        WARConfigBuilder.java
  Log:
  Update ConfigBuilder API to allow for unpacked modules
  
  Revision  Changes    Path
  1.2       +19 -1     incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/AbstractRARConfigBuilder.java
  
  Index: AbstractRARConfigBuilder.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/AbstractRARConfigBuilder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractRARConfigBuilder.java	21 Feb 2004 01:10:49 -0000	1.1
  +++ AbstractRARConfigBuilder.java	21 Feb 2004 19:51:29 -0000	1.2
  @@ -60,6 +60,8 @@
   import java.io.File;
   import java.io.FileOutputStream;
   import java.io.IOException;
  +import java.io.BufferedInputStream;
  +import java.io.FileInputStream;
   import java.net.URI;
   import java.net.URISyntaxException;
   import java.net.URL;
  @@ -156,6 +158,22 @@
       public XmlObject getDeploymentPlan(URL module) {
           //for starters we require an external geronimo dd.
           return null;
  +    }
  +
  +    public void buildConfiguration(File outfile, File module, XmlObject plan) throws IOException,
DeploymentException {
  +        if (module.isDirectory()) {
  +            throw new DeploymentException("Cannot deploy an unpacked RAR");
  +        }
  +        FileInputStream is = new FileInputStream(module);
  +        try {
  +            buildConfiguration(outfile, new JarInputStream(new BufferedInputStream(is)),
plan);
  +        } finally {
  +            try {
  +                is.close();
  +            } catch (IOException e) {
  +                // ignore
  +            }
  +        }
       }
   
       public void buildConfiguration(File outfile, JarInputStream module, XmlObject plan)
throws IOException, DeploymentException {
  
  
  
  1.4       +19 -1     incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/ConfigurationBuilder.java
  
  Index: ConfigurationBuilder.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/ConfigurationBuilder.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ConfigurationBuilder.java	20 Feb 2004 07:19:13 -0000	1.3
  +++ ConfigurationBuilder.java	21 Feb 2004 19:51:29 -0000	1.4
  @@ -87,5 +87,23 @@
        */
       XmlObject getDeploymentPlan(URL module);
   
  +    /**
  +     * Build a configuration from a local file
  +     * @param outfile the file to write the configuration to
  +     * @param module the module to build
  +     * @param plan the deployment plan
  +     * @throws IOException if there was a problem reading or writing the files
  +     * @throws DeploymentException if there was a problem with the configuration
  +     */
  +    void buildConfiguration(File outfile, File module, XmlObject plan) throws IOException,
DeploymentException;
  +
  +    /**
  +     * Build a configuration from an arbitrary input stream
  +     * @param outfile the file to write the configuration to
  +     * @param module the module to build
  +     * @param plan the deployment plan
  +     * @throws IOException if there was a problem reading or writing the files
  +     * @throws DeploymentException if there was a problem with the configuration
  +     */
       void buildConfiguration(File outfile, JarInputStream module, XmlObject plan) throws
IOException, DeploymentException;
   }
  
  
  
  1.6       +5 -1      incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java
  
  Index: ServiceConfigBuilder.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ServiceConfigBuilder.java	20 Feb 2004 15:49:56 -0000	1.5
  +++ ServiceConfigBuilder.java	21 Feb 2004 19:51:29 -0000	1.6
  @@ -118,6 +118,10 @@
           return null;
       }
   
  +    public void buildConfiguration(File outfile, File module, XmlObject plan) throws IOException,
DeploymentException {
  +        buildConfiguration(outfile, (JarInputStream)null, plan);
  +    }
  +
       public void buildConfiguration(File outfile, JarInputStream module, XmlObject plan)
throws IOException, DeploymentException {
           ConfigurationType configType = ((ConfigurationDocument) plan).getConfiguration();
           URI configID;
  
  
  
  1.8       +120 -27   incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/WARConfigBuilder.java
  
  Index: WARConfigBuilder.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/WARConfigBuilder.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- WARConfigBuilder.java	21 Feb 2004 17:41:55 -0000	1.7
  +++ WARConfigBuilder.java	21 Feb 2004 19:51:29 -0000	1.8
  @@ -62,12 +62,15 @@
   import java.io.FileOutputStream;
   import java.io.IOException;
   import java.io.InputStream;
  +import java.io.FileInputStream;
  +import java.io.BufferedInputStream;
   import java.net.MalformedURLException;
   import java.net.URI;
   import java.net.URISyntaxException;
   import java.net.URL;
   import java.util.Collections;
   import java.util.Properties;
  +import java.util.ArrayList;
   import java.util.jar.JarInputStream;
   import java.util.jar.JarOutputStream;
   import java.util.zip.ZipEntry;
  @@ -103,6 +106,7 @@
   import org.apache.xmlbeans.XmlBeans;
   import org.apache.xmlbeans.XmlException;
   import org.apache.xmlbeans.XmlObject;
  +import org.apache.xmlbeans.XmlOptions;
   
   /**
    *
  @@ -154,7 +158,7 @@
           try {
               is = planURL.openStream();
               try {
  -                return XmlBeans.getContextTypeLoader().parse(is, type, null);
  +                return parse(is, type);
               } finally {
                   is.close();
               }
  @@ -165,25 +169,82 @@
           }
       }
   
  -    public void buildConfiguration(File outfile, JarInputStream module, XmlObject plan)
throws IOException, DeploymentException {
  -        WebAppType webApp = null;
  +    public void buildConfiguration(File outfile, File module, XmlObject plan) throws IOException,
DeploymentException {
  +        if (!module.isDirectory()) {
  +            FileInputStream is = new FileInputStream(module);
  +            try {
  +                buildConfiguration(outfile, new JarInputStream(new BufferedInputStream(is)),
plan);
  +                return;
  +            } finally {
  +                try {
  +                    is.close();
  +                } catch (IOException e) {
  +                    // ignore
  +                }
  +            }
  +        }
  +        WebAppType webApp = getDD(module);
           JettyWebAppType jettyWebApp = ((JettyWebAppDocument) plan).getWebApp();
  -        URI configID;
  +        URI configID = getConfigID(jettyWebApp);
  +        URI parentID = getParentID(jettyWebApp);
  +
  +        FileOutputStream fos = new FileOutputStream(outfile);
           try {
  -            configID = new URI(jettyWebApp.getConfigId());
  -        } catch (URISyntaxException e) {
  -            throw new DeploymentException("Invalid configId " + jettyWebApp.getConfigId(),
e);
  +            JarOutputStream os = new JarOutputStream(new BufferedOutputStream(fos));
  +            DeploymentContext context = null;
  +            try {
  +                context = new DeploymentContext(os, configID, parentID, kernel);
  +            } catch (MalformedObjectNameException e) {
  +                throw new DeploymentException(e);
  +            }
  +
  +            // todo do we need to support include and dependency or can we rely on the
parent?
  +            // add low-level GBean definitions to the config
  +//            addIncludes(context, configType);
  +//            addDependencies(context, configType.getDependencyArray());
  +            ClassLoader cl = context.getClassLoader(repository);
  +            addGBeans(context, jettyWebApp.getGbeanArray(), cl);
  +
  +
  +            // add the GBean for the web application
  +            addWebAppGBean(context, webApp, jettyWebApp, module.getAbsoluteFile().toURI());
  +
  +            // todo do we need to add GBeans to make the servlets JSR77 ManagedObjects?
  +
  +            context.close();
  +            os.flush();
  +        } finally {
  +            fos.close();
           }
  -        URI parentID;
  -        if (jettyWebApp.isSetParentId()) {
  +    }
  +
  +    private WebAppType getDD(File module) throws IOException, DeploymentException {
  +        File dd = new File(module, "WEB-INF/web.xml");
  +        if (!(dd.exists() && dd.canRead())) {
  +            throw new DeploymentException("Cannot read WEB-INF/web.xml from module directory");
  +        }
  +        FileInputStream is = new FileInputStream(dd);
  +        try {
               try {
  -                parentID = new URI(jettyWebApp.getParentId());
  -            } catch (URISyntaxException e) {
  -                throw new DeploymentException("Invalid parentId " + jettyWebApp.getParentId(),
e);
  +                WebAppDocument doc = (WebAppDocument) parse(new BufferedInputStream(is),
WebAppDocument.type);
  +                return doc.getWebApp();
  +            } catch (XmlException e) {
  +                throw new DeploymentException("Unable to parse web.xml", e);
  +            }
  +        } finally {
  +            try {
  +                is.close();
  +            } catch (IOException e) {
  +                // ignore
               }
  -        } else {
  -            parentID = null;
           }
  +    }
  +
  +    public void buildConfiguration(File outfile, JarInputStream module, XmlObject plan)
throws IOException, DeploymentException {
  +        WebAppType webApp = null;
  +        JettyWebAppType jettyWebApp = ((JettyWebAppDocument) plan).getWebApp();
  +        URI configID = getConfigID(jettyWebApp);
  +        URI parentID = getParentID(jettyWebApp);
   
           FileOutputStream fos = new FileOutputStream(outfile);
           try {
  @@ -204,7 +265,7 @@
                       byte[] buffer = getBytes(module);
                       context.addFile(target, new ByteArrayInputStream(buffer));
                       try {
  -                        WebAppDocument doc = (WebAppDocument) XmlBeans.getContextTypeLoader().parse(new
ByteArrayInputStream(buffer), WebAppDocument.type, null);
  +                        WebAppDocument doc = (WebAppDocument) parse(new ByteArrayInputStream(buffer),
WebAppDocument.type);
                           webApp = doc.getWebApp();
                       } catch (XmlException e) {
                           throw new DeploymentException("Unable to parse web.xml");
  @@ -217,7 +278,6 @@
               if (webApp == null) {
                   throw new DeploymentException("Did not find WEB-INF/web.xml in module");
               }
  -            context.addToClassPath(warRoot);
   
               // todo do we need to support include and dependency or can we rely on the
parent?
               // add low-level GBean definitions to the config
  @@ -239,16 +299,6 @@
           }
       }
   
  -    private byte[] getBytes(InputStream is) throws IOException {
  -        byte[] buffer = new byte[4096];
  -        ByteArrayOutputStream baos = new ByteArrayOutputStream();
  -        int count;
  -        while ((count = is.read(buffer)) > 0) {
  -            baos.write(buffer, 0, count);
  -        }
  -        return baos.toByteArray();
  -    }
  -
       private void addWebAppGBean(DeploymentContext context, WebAppType webApp, JettyWebAppType
jettyWebApp, URI warRoot) throws DeploymentException {
           String contextRoot = jettyWebApp.getContextRoot().trim();
           if (contextRoot.length() == 0) {
  @@ -348,6 +398,49 @@
   
               context.addGBean(builder.getName(), builder.getGBean());
           }
  +    }
  +
  +    private XmlObject parse(InputStream is, SchemaType type) throws IOException, XmlException
{
  +        ArrayList errors = new ArrayList();
  +        SchemaTypeLoader loader = XmlBeans.getContextTypeLoader();
  +        XmlOptions options = new XmlOptions();
  +        options.setLoadLineNumbers();
  +        options.setErrorListener(errors);
  +        return loader.parse(is, type, options);
  +    }
  +
  +    private URI getParentID(JettyWebAppType jettyWebApp) throws DeploymentException {
  +        URI parentID;
  +        if (jettyWebApp.isSetParentId()) {
  +            try {
  +                parentID = new URI(jettyWebApp.getParentId());
  +            } catch (URISyntaxException e) {
  +                throw new DeploymentException("Invalid parentId " + jettyWebApp.getParentId(),
e);
  +            }
  +        } else {
  +            parentID = null;
  +        }
  +        return parentID;
  +    }
  +
  +    private URI getConfigID(JettyWebAppType jettyWebApp) throws DeploymentException {
  +        URI configID;
  +        try {
  +            configID = new URI(jettyWebApp.getConfigId());
  +        } catch (URISyntaxException e) {
  +            throw new DeploymentException("Invalid configId " + jettyWebApp.getConfigId(),
e);
  +        }
  +        return configID;
  +    }
  +
  +    private byte[] getBytes(InputStream is) throws IOException {
  +        byte[] buffer = new byte[4096];
  +        ByteArrayOutputStream baos = new ByteArrayOutputStream();
  +        int count;
  +        while ((count = is.read(buffer)) > 0) {
  +            baos.write(buffer, 0, count);
  +        }
  +        return baos.toByteArray();
       }
   
       public static final GBeanInfo GBEAN_INFO;
  
  
  

Mime
View raw message