You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@gump.apache.org by bo...@apache.org on 2003/01/16 18:04:47 UTC

cvs commit: jakarta-gump/stylesheet move.xsl bash.xsl win2k.xsl

bodewig     2003/01/16 09:04:46

  Modified:    .        gen.bat gen.sh
               java     Jenny.java
               stylesheet bash.xsl win2k.xsl
  Added:       stylesheet move.xsl
  Log:
  Going with the "good idead, crappy code" mantra 8-)
  
  Cache files that are external to Gump in a new cache directory, use
  cached files if we cannot reach the external resource.
  
  How it works:
  
  * gen.* creates a cache directoy.
  
  * Jenny
    o adds cache-as attributes to external nodes.
    o uses a cached version (if present) for external nodes that cannot
      get expanded
  
  * gen.* creates move.xml (because I wanted to abuse the move template
    from bash.xsl and win2k.xsl)
  
  * gen.* creates move.(sh|bat) via (bash|win2k).xsl
  
  * gen.* calls move.* after publishing the files, thus saving the
    cached stuff.
  
  Please note that I'm doing the .bat stuff in blind flight.
  
  Revision  Changes    Path
  1.25      +12 -0     jakarta-gump/gen.bat
  
  Index: gen.bat
  ===================================================================
  RCS file: /home/cvs/jakarta-gump/gen.bat,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- gen.bat	1 Jan 2003 06:46:43 -0000	1.24
  +++ gen.bat	16 Jan 2003 17:04:45 -0000	1.25
  @@ -19,6 +19,7 @@
   
   if exist work rmdir /s /q work
   mkdir work
  +if not exist cache mkdir cache
   
   @REM ********************************************************************
   
  @@ -101,12 +102,23 @@
   java org.apache.xalan.xslt.Process -text -in work\merge.xml -xsl stylesheet\nag.xsl -out work\naglist
   if not errorlevel 0 goto fail
   
  +echo Generate move instructions for cached files
  +java org.apache.xalan.xslt.Process -xml -in work\merge.xml -xsl stylesheet\move.xsl -out work\move.xml
  +if not errorlevel 0 goto fail
  +
  +echo Generate move script for cached files
  +java org.apache.xalan.xslt.Process -text -in work\move.xml -xsl stylesheet\win2k.xsl -out work\move.bat
  +if not errorlevel 0 goto fail
  +
   @REM ********************************************************************
   
   echo Publishing
   cd work
   call puball ..\%SOURCE%
   cd ..
  +
  +echo saving cached files
  +call work\move.bat
   
   goto eof
   :fail
  
  
  
  1.37      +14 -0     jakarta-gump/gen.sh
  
  Index: gen.sh
  ===================================================================
  RCS file: /home/cvs/jakarta-gump/gen.sh,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- gen.sh	13 Jul 2002 23:41:37 -0000	1.36
  +++ gen.sh	16 Jan 2003 17:04:46 -0000	1.37
  @@ -43,6 +43,7 @@
   
   test -d work && rm -rf work
   mkdir work
  +test -d cache || mkdir cache
   
   # ********************************************************************
   
  @@ -147,6 +148,16 @@
   java org.apache.xalan.xslt.Process -text -in work/merge.xml -xsl stylesheet/nag.xsl -out work/naglist || \
   export FAIL=1
   
  +echo Generate move instructions for cached files
  +test -n "$FAIL" || \
  +java org.apache.xalan.xslt.Process -xml -in work/merge.xml -xsl stylesheet/move.xsl -out work/move.xml || \
  +export FAIL=1
  +
  +echo Generate move script for cached files
  +test -n "$FAIL" || \
  +java org.apache.xalan.xslt.Process -text -in work/move.xml -xsl stylesheet/bash.xsl -out work/move.sh || \
  +export FAIL=1
  +
   # **** publish ***
   if test -z "$FAIL"; then
     echo
  @@ -156,6 +167,9 @@
     bash puball.sh ../$SOURCE
     cd ..
   fi
  +
  +echo saving cached files
  +test -n "$FAIL" || bash work/move.sh
   
   test -z "$FAIL" || echo "*** FAILED ***"
   
  
  
  
  1.21      +47 -5     jakarta-gump/java/Jenny.java
  
  Index: Jenny.java
  ===================================================================
  RCS file: /home/cvs/jakarta-gump/java/Jenny.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- Jenny.java	12 Dec 2002 03:17:23 -0000	1.20
  +++ Jenny.java	16 Jan 2003 17:04:46 -0000	1.21
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -171,7 +171,7 @@
          Attr href = node.getAttributeNode("href");
          
          if (href != null && !node.getNodeName().equals("url")) {
  -           String source=href.getValue();
  +           String source = href.getValue();
              if (source.startsWith("http://") && !online) {
                  throw new ConnectException("Not online");
              }
  @@ -189,6 +189,7 @@
                      source=source.substring(source.lastIndexOf("/")+1);
                  }
   
  +               String cacheName = getCachedNodeName(node);
                  node.removeAttribute("href");
                  node.setAttribute("defined-in", source);
   
  @@ -220,6 +221,7 @@
                      output (sub, "work/" + prefix + source + ".xml");
                      node.setAttribute("defined-in", source);
                      node.setAttribute("extern-prefix",prefix);
  +                   node.setAttribute("cache-as", cacheName);
                  }
              }
          }
  @@ -258,6 +260,35 @@
                      System.err.println("Failed to expand "
                                         + name.toString());
                      System.err.println("   - " + t);
  +                   
  +                   String cache = getCachedNodeName(elem);
  +                   File f = new File(cache);
  +                   if (f.exists()) {
  +                       Node sub = parse(cache);
  +                       Document doc = elem.getOwnerDocument();
  +                       Element copy = null;
  +                       Node firstNode = sub.getFirstChild();
  +                       for (Node childNode = firstNode; childNode != null; 
  +                            childNode = childNode.getNextSibling()) {
  +                           if (childNode.getNodeType() == Node.ELEMENT_NODE) {
  +                               copy = (Element)doc.importNode(childNode, true);
  +                               break;
  +                           }
  +                       }
  +
  +                       moveChildren(elem, copy);
  +
  +                       elem.getParentNode().replaceChild(copy, elem);
  +
  +                       cache = cache.substring(6 /* "cache/".length() */,
  +                                               cache.length() 
  +                                               - 4 /* ".xml".length() */);
  +
  +                       copy.setAttribute("defined-in", cache);
  +                       copy.setAttribute("extern-prefix", "../cache/");
  +
  +                       child = copy;
  +                   }
                  }
              }
          }
  @@ -397,5 +428,16 @@
               e.printStackTrace();
               System.exit(99);
           }
  +    }
  +
  +    /**
  +     * Name of the cache file.
  +     */
  +    private String getCachedNodeName(Element node) {
  +        String hrefAttribute = node.getAttribute("href");
  +        return "cache/" 
  +            + hrefAttribute.replace('/', '_').replace(':', '_')
  +                           .replace('*', '_').replace('~', '_')
  +            + ".xml";
       }
   }
  
  
  
  1.85      +9 -0      jakarta-gump/stylesheet/bash.xsl
  
  Index: bash.xsl
  ===================================================================
  RCS file: /home/cvs/jakarta-gump/stylesheet/bash.xsl,v
  retrieving revision 1.84
  retrieving revision 1.85
  diff -u -r1.84 -r1.85
  --- bash.xsl	14 Jan 2003 15:49:52 -0000	1.84
  +++ bash.xsl	16 Jan 2003 17:04:46 -0000	1.85
  @@ -926,4 +926,13 @@
       </xsl:choose>
     </xsl:template>
   
  +  <!-- =================================================================== -->
  +  <!--          Generate the move script for the cached files              -->
  +  <!-- =================================================================== -->
  +
  +  <xsl:template match="movefiles">
  +    <xsl:text>#!/bin/bash&#10;</xsl:text>
  +    <xsl:apply-templates/>
  +  </xsl:template>
  +
   </xsl:stylesheet>
  
  
  
  1.44      +9 -0      jakarta-gump/stylesheet/win2k.xsl
  
  Index: win2k.xsl
  ===================================================================
  RCS file: /home/cvs/jakarta-gump/stylesheet/win2k.xsl,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- win2k.xsl	14 Jan 2003 15:49:52 -0000	1.43
  +++ win2k.xsl	16 Jan 2003 17:04:46 -0000	1.44
  @@ -816,4 +816,13 @@
       </xsl:choose>
     </xsl:template>
   
  +  <!-- =================================================================== -->
  +  <!--          Generate the move script for the cached files              -->
  +  <!-- =================================================================== -->
  +
  +  <xsl:template match="movefiles">
  +    <xsl:text>@echo off&#10;</xsl:text>
  +    <xsl:apply-templates/>
  +  </xsl:template>
  +
   </xsl:stylesheet>
  
  
  
  1.1                  jakarta-gump/stylesheet/move.xsl
  
  Index: move.xsl
  ===================================================================
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  
    <xsl:output indent="yes"/>
  
    <xsl:template match="text()|@*" />
  
    <xsl:template match="workspace">
      <movefiles>
        <xsl:apply-templates/>
      </movefiles>
    </xsl:template>
  
    <xsl:template match="*[@cache-as]">
      <move todir="{@cache-as}" file="work/{@extern-prefix}{@name}.xml"/>
    </xsl:template>
  </xsl:stylesheet>
  
  

Re: cvs commit: jakarta-gump/stylesheet move.xsl bash.xsl win2k.xsl

Posted by Stefan Bodewig <bo...@apache.org>.
On Thu, 16 Jan 2003, Sam Ruby <ru...@apache.org> wrote:

> +1!  Both to the sentiment, and to the code.  ;-)

Cool.

Something that I find a bit ugly is the mangled name, but I couldn't
come up with something easier that was unique and human identifiable
at the same time.  And then I'm not sure whether it could cause any
filename or command line length issues as these names tend to be
rather long.

But the whole mangling code is in a single place, one wouldn't have to
change anything but the getCachedNodeName method to use a different
algorithm.

> I ran a test on windows... appeared to cache the files it could
> access, and not die because there were ones that it could not.

Great.

> Note: this should work on the build machines...

If you place the two files from my home dir at icarus (see other mail)
into the cache directory, cocoon and a couple of other projects will
no longer get dropped.

> but one thing I'd like to note: the following step is always done
> from a clean checkout, so it will not benefit from the cache:
> 
> http://cvs.apache.org/builds/gump/latest/gump.html
> 
> As this step is for verification purposes, this actually is a good
> thing.

I agree.

Stefan

Re: cvs commit: jakarta-gump/stylesheet move.xsl bash.xsl win2k.xsl

Posted by Sam Ruby <ru...@apache.org>.
bodewig@apache.org wrote:
> 
>   Going with the "good idead, crappy code" mantra 8-)
>   
>   Cache files that are external to Gump in a new cache directory, use
>   cached files if we cannot reach the external resource.

+1!  Both to the sentiment, and to the code.  ;-)

I ran a test on windows... appeared to cache the files it could access, 
and not die because there were ones that it could not.

Note: this should work on the build machines... but one thing I'd like 
to note: the following step is always done from a clean checkout, so it 
will not benefit from the cache:

http://cvs.apache.org/builds/gump/latest/gump.html

As this step is for verification purposes, this actually is a good thing.

- Sam Ruby


Re: cvs commit: jakarta-gump/stylesheet move.xsl bash.xsl win2k.xsl

Posted by Stefan Bodewig <bo...@apache.org>.
You can find the latest Gump descriptors for the ant-contrib projects
at <http://cvs.apache.org/~bodewig/gump/> using the current naming
convention.

If you place them into the cache directory, Gump should use them.

Stefan