rubys       01/10/10 12:19:33

  Modified:    proposal/gump/java Project.java
               proposal/gump/stylesheet build.xsl
  Log:
  XSL=>Java
  
  Revision  Changes    Path
  1.5       +74 -5     jakarta-alexandria/proposal/gump/java/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/jakarta-alexandria/proposal/gump/java/Project.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Project.java      2001/10/08 13:49:07     1.4
  +++ Project.java      2001/10/10 19:19:33     1.5
  @@ -14,7 +14,9 @@
       private Document document;
       private Element element;
       private String name;
  +    private Element ant = null;
       private Hashtable depends = new Hashtable();
  +    private Hashtable jars = new Hashtable();
   
       /**
        * Create a set of Project definitions based on XML nodes.
  @@ -25,9 +27,12 @@
              new Project((Element)elements.nextElement());
           }
   
  -        // expand dependencies for easier generation
  +        // Resolve all references so that the XML can be processed in
  +        // one pass.
           for (Enumeration e=projects.elements(); e.hasMoreElements();) {
  -            ((Project)(e.nextElement())).expandDepends();
  +            Project p = ((Project)(e.nextElement()));
  +            p.expandDepends();
  +            p.resolveProperties();
           }
       }
   
  @@ -50,7 +55,6 @@
           name = element.getAttribute("name");
   
           Element home = null;
  -        Element ant = null;
   
           Node child=element.getFirstChild();
           for (; child != null; child=child.getNextSibling()) {
  @@ -62,6 +66,8 @@
                   ant = (Element)child;
               } else if (child.getNodeName().equals("home")) {
                   home = (Element)child;
  +            } else if (child.getNodeName().equals("jar")) {
  +                jars.put(((Element)child).getAttribute("id"), child);
               }
           }
   
  @@ -72,6 +78,12 @@
               genDepends(ant);
           }
   
  +        // if only one jar is found, make sure that it can be accessed without
  +        // specifying an id.
  +        if (jars.size() == 1) {
  +            jars.put("", jars.elements().nextElement());
  +        }
  +
           projects.put(name, this);
       }
   
  @@ -195,11 +207,68 @@
                   if (child.getNodeName().equals("jar")) {
                       depend.appendChild(child.cloneNode(false));
                   } else if (child.getNodeName().equals("ant")) {
  -                    depend.appendChild(child.cloneNode(false));
  +                    depend.appendChild(document.createElement("ant"));
                   } else if (child.getNodeName().equals("script")) {
  -                    depend.appendChild(child.cloneNode(false));
  +                    depend.appendChild(document.createElement("script"));
                   }
               }
  +        }
  +    }
  +
  +    /**
  +     * Resolve property references, based on the value of "reference"
  +     * attribute (if present).  Supported values for reference are:
  +     *
  +     * <ul>
  +     * <li> home: the home directory for the referenced project </li>
  +     * <li> jar: the simple name (path relative to home) of the jar in a 
  +     * referenced project. </li>
  +     * <li> jarpath: the fully qualified path of the jar in a referenced 
  +     * project. </li>
  +     * <li> srcdir: the srcdir for the module containing the project. </li>
  +     * <li> path: a path which is to be interpreted relative to the srcdir 
  +     * for the module containing this project </li>
  +     * </ul>
  +     */
  +    private void resolveProperties() throws Exception {
  +        if (ant == null) return;
  +
  +        Node child=ant.getFirstChild();
  +        for (;child!=null; child=child.getNextSibling()) {
  +            if (!child.getNodeName().equals("property")) continue;
  +            Element property = (Element) child;
  +            if (property.getAttributeNode("value") != null) continue;
  +
  +            String reference = property.getAttribute("reference");
  +            String projectName = property.getAttribute("project");
  +            Project project = (Project) projects.get(projectName);
  +
  +            String value = null;
  +
  +            if (reference.equals("home")) {
  +                value = project.get("home");
  +                property.setAttribute("type", "path");
  +            } else if (reference.equals("jar")) {
  +                String id = property.getAttribute("id");
  +                Element jar = (Element)project.jars.get(id);
  +                value = jar.getAttribute("name"); 
  +            } else if (reference.equals("jarpath")) {
  +                String id = property.getAttribute("id");
  +                Element jar = (Element)project.jars.get(id);
  +                value = project.get("home") + "/" + jar.getAttribute("name"); 
  +                property.setAttribute("type", "path");
  +            } else if (reference.equals("srcdir")) {
  +                Module module = Module.find(projectName);
  +                value = module.getSrcDir();
  +                property.setAttribute("type", "path");
  +            } else if (property.getAttributeNode("path") != null) {
  +                Module module = Module.find(this.get("module"));
  +                value = module.getSrcDir();
  +                value += "/" + property.getAttribute("path");
  +                property.setAttribute("type", "path");
  +            }
  +
  +            if (value != null) property.setAttribute("value", value);
           }
       }
   }
  
  
  
  1.38      +5 -63     jakarta-alexandria/proposal/gump/stylesheet/build.xsl
  
  Index: build.xsl
  ===================================================================
  RCS file: /home/cvs/jakarta-alexandria/proposal/gump/stylesheet/build.xsl,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- build.xsl 2001/10/09 23:40:35     1.37
  +++ build.xsl 2001/10/10 19:19:33     1.38
  @@ -263,10 +263,11 @@
     <xsl:template match="project[not(ant) and not(script)]"/>
   
     <xsl:template match="ant">
  -    <xsl:variable name="module" select="ancestor::project/@module"/>
  -    <xsl:variable name="srcdir" select="/workspace/module[@name=$module]/@srcdir"/>
   
       <xsl:if test="@basedir">
  +      <xsl:variable name="module" select="ancestor::project/@module"/>
  +      <xsl:variable name="srcdir" 
  +        select="/workspace/module[@name=$module]/@srcdir"/>
         <chdir dir="{$srcdir}/{@basedir}"/>
       </xsl:if>
   
  @@ -283,68 +284,9 @@
         </xsl:choose>
   
         <xsl:apply-templates select="@*[name()!='target']"/>
  -      <xsl:apply-templates select="*[name()!='property']"/>
  +      <xsl:apply-templates select="/workspace/property"/>
  +      <xsl:apply-templates select="*"/>
   
  -      <xsl:for-each select="/workspace/property|property">
  -        <xsl:variable name="name" select="@name"/>
  -        <xsl:choose>
  -          <xsl:when test="@reference='home'">
  -            <xsl:variable name="project" select="@project"/>
  -            <xsl:for-each select="/workspace/project[@name=$project]">
  -              <property name="{$name}" value="{@home}" type="path"/>
  -            </xsl:for-each>
  -          </xsl:when>
  -
  -          <xsl:when test="@reference='jar'">
  -            <xsl:variable name="project" select="@project"/>
  -            <xsl:if test="@id">
  -              <xsl:variable name="id" select="@id"/>
  -              <xsl:for-each select="/workspace/project[@name=$project]">
  -                <property name="{$name}" value="{jar[@id=$id]/@name}"/>
  -              </xsl:for-each>
  -            </xsl:if>
  -            <xsl:if test="not(@id)">
  -              <xsl:for-each select="/workspace/project[@name=$project]/jar">
  -                <property name="{$name}" value="{@name}"/>
  -              </xsl:for-each>
  -            </xsl:if>
  -          </xsl:when>
  -
  -          <xsl:when test="@reference='jarpath'">
  -            <xsl:variable name="project" select="@project"/>
  -            <xsl:if test="@id">
  -              <xsl:variable name="id" select="@id"/>
  -              <xsl:for-each select="/workspace/project[@name=$project]">
  -                <property name="{$name}" value="{@home}/{jar[@id=$id]/@name}" 
type="path"/>
  -              </xsl:for-each>
  -            </xsl:if>
  -            <xsl:if test="not(@id)">
  -              <xsl:for-each select="/workspace/project[@name=$project]/jar">
  -                <property name="{$name}" value="{../@home}/{@name}" type="path"/>
  -              </xsl:for-each>
  -            </xsl:if>
  -          </xsl:when>
  -
  -          <xsl:when test="@reference='srcdir'">
  -            <xsl:variable name="project" select="@project"/>
  -            <xsl:for-each select="/workspace/project[@name=$project]">
  -              <xsl:variable name="module" select="@module"/>
  -              <xsl:for-each select="/workspace/module[@name=$module]">
  -                <property name="{$name}" value="{@srcdir}" type="path"/>
  -              </xsl:for-each>
  -            </xsl:for-each>
  -          </xsl:when>
  -
  -          <xsl:when test="@path">
  -            <property name="{$name}" value="{$srcdir}/{@path}" type="path"/>
  -          </xsl:when>
  -
  -          <xsl:otherwise>
  -            <property name="{$name}" value="{@value}"/>
  -          </xsl:otherwise>
  -        </xsl:choose>
  -
  -      </xsl:for-each>
       </xsl:copy>
     </xsl:template>
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to