jvanzyl     2002/10/18 18:47:22

  Modified:    src/java/org/apache/maven MavenUtils.java
               src/java/org/apache/maven/app Maven.java PluginManager.java
               src/java/org/apache/maven/project Project.java
               src/plugins-build/j2ee plugin.jelly
  Added:       src/java/org/apache/maven/util JellyUtils.java
  Removed:     src/java/org/apache/maven/app JellyUtils.java
  Log:
  o Trying to localize the compilation of jelly scripts to the JellyUtils
    class.
  o Move JellyUtils class to the org.apache.maven.util package.
  o Added the ability to deal with different encodings and InputStreams
    w.r.t the compilation of Jelly scripts.
  
  Revision  Changes    Path
  1.48      +54 -49    jakarta-turbine-maven/src/java/org/apache/maven/MavenUtils.java
  
  Index: MavenUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/MavenUtils.java,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- MavenUtils.java   18 Oct 2002 15:21:28 -0000      1.47
  +++ MavenUtils.java   19 Oct 2002 01:47:22 -0000      1.48
  @@ -90,15 +90,11 @@
   
   import org.apache.tools.ant.DirectoryScanner;
   import org.apache.maven.util.StringInputStream;
  +import org.apache.maven.util.JellyUtils;
   
  -
  -// Jelly goodies.
  -
  -import org.apache.commons.jelly.Jelly;
   import org.apache.commons.jelly.JellyContext;
   import org.apache.commons.jelly.Script;
   import org.apache.commons.jelly.XMLOutput;
  -import org.apache.commons.jelly.parser.XMLParser;
   
   import org.apache.commons.digester.ExtendedBaseRules;
   
  @@ -113,6 +109,9 @@
    */
   public class MavenUtils
   {
  +    /** Internal encoding used for Jelly interpolation. */
  +    private final static String INTERNAL_ENCODING = "ISO-8859-1";
  +
       /**    
        * A thread pool to avoid the startup overhead of the XML parser each 
        * time we want to parse something
  @@ -145,6 +144,14 @@
           return getProject(projectDescriptor, new File("."), null);
       }
   
  +    /*
  +    
  +    project.xml [ISO-8859-1]
  +    |
  +    v
  +    
  +    */
  +
       /**
        * @return the POM from the given file in the current directory, using the
        * given context as the parent context
  @@ -180,8 +187,10 @@
        * @return the Maven project object for the given project descriptor
        * @throws Exception when any errors occur
        */
  -    public static Project getProject(File projectDescriptor, File dir,
  -        MavenJellyContext parentContext) throws Exception
  +    public static Project getProject(File projectDescriptor, 
  +                                     File dir,
  +                                     MavenJellyContext parentContext) 
  +        throws Exception
       {
           BeanReader projectBeanReader = getProjectBeanReader();
           Project project = (Project) projectBeanReader.parse(projectDescriptor);
  @@ -189,8 +198,9 @@
           String pomToExtend = project.getExtend();
           if (pomToExtend != null)
           {
  -            Project parent = (Project) projectBeanReader.parse(new File(dir,
  -                pomToExtend));
  +            Project parent = (Project) projectBeanReader.parse(
  +                new File(dir,pomToExtend));
  +            
               project = (Project) mergeBeans(project, parent);
           }
                   
  @@ -199,7 +209,25 @@
           
           return project;
       }
  -    
  +
  +    /**
  +     * Create a project bean reader. We use it more than once so we don't
  +     * want to create it more than once.
  +     * 
  +     * @return a {@link BeanReader} capable of reading {@link Project projects}
  +     * @throws Exception when anything goes wrong. FIXME this is bad
  +     */
  +    private static BeanReader getProjectBeanReader()
  +        throws Exception
  +    {
  +        if (projectBeanReader == null)
  +        {
  +            projectBeanReader = createBeanReader(Project.class);
  +        }            
  +        
  +        return projectBeanReader;
  +    }
  +
       /**
        * Process the project descriptor using Jelly itself.
        *
  @@ -209,7 +237,8 @@
        * @throws Exception when anything goes wrong. FIXME this is bad
        */
       private static Project getJellyProject(Project project, 
  -        MavenJellyContext parentContext) throws Exception
  +                                           MavenJellyContext parentContext) 
  +        throws Exception
       {
           JellyContext context = null;
           
  @@ -223,14 +252,10 @@
               context = new JellyContext();
           }
           context.setVariable("pom", project);
  -        XMLParser parser = new XMLParser();
  -        parser.setContext(context);
           
  -//        Jelly jelly = new Jelly();
  -        
  -        Script script = parser.parse(new InputStreamReader(
  -            getProjectInputStream(project)));
  -        script = script.compile();
  +        Script script = JellyUtils.compileScript(getProjectInputStream(project), 
  +                                                 context,
  +                                                 INTERNAL_ENCODING);
           
           ByteArrayOutputStream baos = new ByteArrayOutputStream();
           Writer writer = new BufferedWriter(new OutputStreamWriter(baos));
  @@ -245,23 +270,16 @@
       }
       
       /**
  -     * Create a project bean reader. We use it more than once so we don't
  -     * want to create it more than once.
  -     * 
  -     * @return a {@link BeanReader} capable of reading {@link Project projects}
  +     * @return an {@link InputStream} for the given project
  +     * @param project a {@link Project maven project}
        * @throws Exception when anything goes wrong. FIXME this is bad
        */
  -    private static BeanReader getProjectBeanReader()
  +    public static InputStream getProjectInputStream(Project project)
           throws Exception
       {
  -        if (projectBeanReader == null)
  -        {
  -            projectBeanReader = createBeanReader(Project.class);
  -        }            
  -        
  -        return projectBeanReader;
  +        return new StringInputStream(getProjectString(project));
       }
  -    
  +
       /**
        * Create an XML string from a project.
        *
  @@ -278,18 +296,11 @@
           beanWriter.setWriteIDs(true);
           beanWriter.write(project);
           
  -        return projectStream.toString();
  -    }
  -
  -    /**
  -     * @return an {@link InputStream} for the given project
  -     * @param project a {@link Project maven project}
  -     * @throws Exception when anything goes wrong. FIXME this is bad
  -     */
  -    public static InputStream getProjectInputStream(Project project)
  -        throws Exception
  -    {
  -        return new StringInputStream(getProjectString(project));
  +        // We do not care what the original encoding was originally. This
  +        // is all completely internal. Our StringInputStream requires
  +        // everything to be encoded in "ISO-8859-1".
  +        
  +        return projectStream.toString(INTERNAL_ENCODING);
       }
   
       /**
  @@ -602,14 +613,8 @@
       {
           XMLIntrospector introspector = new XMLIntrospector();
   
  -        // set elements for attributes to true
           introspector.setAttributesForPrimitives(false);
           introspector.setCachingEnabled(true);
  -
  -        // wrap collections in an XML element
  -        //introspector.setWrapCollectionsInElement(true);
  -
  -        // turn bean elements into lower case
           introspector.setNameMapper(new DecapitalizeNameMapper());
           
           return introspector;
  
  
  
  1.112     +2 -1      jakarta-turbine-maven/src/java/org/apache/maven/app/Maven.java
  
  Index: Maven.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/app/Maven.java,v
  retrieving revision 1.111
  retrieving revision 1.112
  diff -u -r1.111 -r1.112
  --- Maven.java        4 Oct 2002 05:50:08 -0000       1.111
  +++ Maven.java        19 Oct 2002 01:47:22 -0000      1.112
  @@ -92,6 +92,7 @@
   import org.apache.maven.MavenUtils;
   import org.apache.maven.jelly.tags.project.MavenTagLibrary;
   import org.apache.maven.project.Project;
  +import org.apache.maven.util.JellyUtils;
   
   import org.apache.tools.ant.DemuxOutputStream;
   
  
  
  
  1.38      +2 -1      
jakarta-turbine-maven/src/java/org/apache/maven/app/PluginManager.java
  
  Index: PluginManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/app/PluginManager.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- PluginManager.java        18 Oct 2002 04:56:48 -0000      1.37
  +++ PluginManager.java        19 Oct 2002 01:47:22 -0000      1.38
  @@ -83,6 +83,7 @@
   import org.apache.maven.CreateDependencyClasspath;
   import org.apache.maven.project.Dependency;
   import org.apache.maven.project.Project;
  +import org.apache.maven.util.JellyUtils;
   
   // Tmp
   import org.apache.maven.repository.DefaultArtifactFactory;
  
  
  
  1.40      +18 -33    
jakarta-turbine-maven/src/java/org/apache/maven/project/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/project/Project.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- Project.java      22 Aug 2002 19:40:44 -0000      1.39
  +++ Project.java      19 Oct 2002 01:47:22 -0000      1.40
  @@ -65,8 +65,6 @@
   import java.util.List;
   import java.util.Map;
   
  -import org.apache.commons.betwixt.io.SAXBeanWriter;
  -
   import org.apache.maven.MavenConstants;
   import org.apache.maven.MavenUtils;
   
  @@ -311,36 +309,6 @@
       }        
   
       /**
  -     * Create a dom4j document from the POM. Used for dvsl processing right now.
  -     * Hopefully we can make this more general so that people
  -     * can use the POM in XSLT transformations. This is not
  -     * working for some reason, I believe due to encoding problems.
  -     * This might be working now but I will test it later.
  -     */
  -    public Document createDocumentX()
  -        throws Exception
  -    {
  -        SAXContentHandler contentHandler = new SAXContentHandler();
  -        SAXBeanWriter saxBeanWriter = new SAXBeanWriter(contentHandler);
  -        saxBeanWriter.write(this);
  -        
  -        return contentHandler.getDocument();
  -    }
  -    
  -    /**
  -     * Create a dom4j document from the POM.
  -     */
  -    public Document createDocument()
  -        throws Exception
  -    {
  -        String p = MavenUtils.getProjectString(this);
  -        SAXReader reader = new SAXReader();
  -
  -        return reader.read(new InputStreamReader(
  -                               MavenUtils.getProjectInputStream(this)));
  -    }
  -
  -    /**
        * Set the site address where the documentation lives.
        *
        * @param siteAddress the hostname of the web server that hosts the
  @@ -873,5 +841,22 @@
       public String getLogo()
       {
           return logo;
  +    }
  +
  +    /**
  +     * Create a dom4j document from the POM. Used for dvsl processing right now.
  +     * Hopefully we can make this more general so that people
  +     * can use the POM in XSLT transformations. This is not
  +     * working for some reason, I believe due to encoding problems.
  +     * This might be working now but I will test it later.
  +     *
  +     * @param project Maven project object.
  +     * @return Document Dom4j document.
  +     */
  +    public Document createDocument()
  +        throws Exception
  +    {
  +        SAXReader reader = new SAXReader();
  +        return reader.read(new 
InputStreamReader(MavenUtils.getProjectInputStream(this)));
       }
   }
  
  
  
  1.1                  
jakarta-turbine-maven/src/java/org/apache/maven/util/JellyUtils.java
  
  Index: JellyUtils.java
  ===================================================================
  package org.apache.maven.util;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Maven" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Maven", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  import org.apache.commons.jelly.JellyContext;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.Script;
  import org.apache.commons.jelly.parser.XMLParser;
  
  import com.bluecast.xml.JAXPSAXParserFactory;
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  
  import java.net.URL;
  
  import javax.xml.parsers.SAXParserFactory;
  import org.xml.sax.XMLReader;
  
  /**
   * Utilities for Jelly.
   *
   * @see <a href="http://jakarta.apache.org/commons/sandbox/jelly/";>
   *      commons-jelly</a>
   * @author <a href="mailto:bob@;eng.werken.com">bob mcwhirter</a>
   * @author <a href="mailto:jason@;zenplex.com">Jason van Zyl</a>
   * @version $Id: JellyUtils.java,v 1.1 2002/10/19 01:47:22 jvanzyl Exp $
   */
  public class JellyUtils
  {
  
      /**
       * Run a jelly script.
       *
       * @param scriptFile Location of the script to run.
       * @param rootUrl Root explicit context of the script.
       * @param context Jelly context.
       * @param output Output sink.
       * @throws Exception If an error occurs while locating, compiling or
       *      executing the script.
       */
      public static void runScript(File scriptFile,
                                   URL rootUrl,
                                   JellyContext context,
                                   XMLOutput output)
          throws Exception
      {
          // if the scriptFile is not readable or is empty, just ignore it
          if (!scriptFile.canRead() || scriptFile.length() < 1)
          {
              return;
          }
  
          URL oldRoot = context.getRootURL();
          URL oldCurrent = context.getCurrentURL();
  
          if (rootUrl != null)
          {
              context.setRootURL(rootUrl);
              context.setCurrentURL(rootUrl);
          }
  
          Script script = compileScript(scriptFile, context);
          script.run(context,output);
  
          context.setRootURL(oldRoot);
          context.setCurrentURL(oldCurrent);
      }
  
      /**
       * Compile a jelly script.
       *
       * @param scriptFile Location of the script to run.
       * @param context Jelly context.
       * @throws Exception If an error occurs while locating or compiling the
       *      script.
       * @return The compiled script.
       */
      public static Script compileScript(File scriptFile,
                                         JellyContext context)
          throws Exception
      {
          return compileScript(new FileInputStream(scriptFile), context);
      }
  
      /**
       * Compile a jelly script.
       *
       * @param scriptInputStream Script input stream.
       * @param context Jelly context.
       * @throws Exception If an error occurs while locating or compiling the
       *      script.
       * @return The compiled script.
       */
      public static Script compileScript(InputStream scriptInputStream,
                                         JellyContext context)
          throws Exception
      {
          return compileScript(scriptInputStream, context, null);
      }
  
      /**
       * Compile a jelly script.
       *
       * @param scriptInputStream Script input stream.
       * @param context Jelly context.
       * @throws Exception If an error occurs while locating or compiling the
       *      script.
       * @return The compiled script.
       */
      public static Script compileScript(InputStream scriptInputStream,
                                         JellyContext context,
                                         String encoding)
          throws Exception
      {
          SAXParserFactory factory = new JAXPSAXParserFactory();
          factory.setNamespaceAware(true);
          XMLReader reader = factory.newSAXParser().getXMLReader();
          XMLParser parser = new XMLParser(reader);
          parser.setContext(context);
  
          Script script = null;
  
          if (encoding != null)
          {
              script = parser.parse(new InputStreamReader(scriptInputStream, 
encoding));
          }
          else
          {
              script = parser.parse(scriptInputStream);
          }
  
          script = script.compile();
  
          return script;
      }
  }
  
  
  
  1.11      +2 -2      jakarta-turbine-maven/src/plugins-build/j2ee/plugin.jelly
  
  Index: plugin.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/plugins-build/j2ee/plugin.jelly,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- plugin.jelly      28 Sep 2002 10:22:26 -0000      1.10
  +++ plugin.jelly      19 Oct 2002 01:47:22 -0000      1.11
  @@ -24,7 +24,7 @@
     <goal name="appserver:init">
       <define:taglib uri="serverLib">
         <define:jellybean name="server-started-check"
  -        className="org.apache.maven.jelly.tags.ServerStartedCheckTag" />
  +        className="org.apache.maven.j2ee.ServerStartedCheckTag" />
       </define:taglib>
       <server:server-started-check propertyName="maven.appserver.started"
           URL="${maven.appserver.url}"/>
  @@ -270,4 +270,4 @@
        
     </goal>
      
  -</project>
  \ No newline at end of file
  +</project>
  
  
  

--
To unsubscribe, e-mail:   <mailto:turbine-maven-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:turbine-maven-dev-help@;jakarta.apache.org>

Reply via email to