On Thu, 27 Mar 2003, Ben Walding wrote:

> I've committed a patch along these lines.
> 
> <exclude name="WEB-INF/classes/**/*.class"/>

I don't know if anyone else would find this useful, but I develop under 
linux and I just set up a fake webapp made up of symlinks. Everything in 
src/webapp is linked except for WEB-INF which is a directory and then 
anything in src/webapp/WEB-INF is linked into that. Also though 
WEB-INF/classes is linked to target/classes and WEB-INF/lib is linked to 
lib.

The end effect is something that looks like the end webapp, and leaves 
the regular build structure in tact.

There are three problems:
  1. It is system dependent
  2. Ant does not know what a symlink is and just follows them; so:
      <a:delete dir="webapp" /> will eat up most of your project as ant 
      follows the links and removes the originals. rm -r will only delete 
      the symlinks.
  3. Tomcat won't follow symlinks by default, so the resource loader has 
      to be told to allow it. In server.xml:
        <Context path="/ops" docBase="ops" debug="0" reloadable="true">
          <Resources className="org.apache.naming.resources.FileDirContext"
           allowLinking="true" />
        </Context>

After everything is set up though it just works and java:compile will be 
enough to let you see the changes to your webapp. (Well, when changing 
things other than java source files maven isn't needed to see changes.)

Will
#!/usr/bin/python

import os
import re
import grp

# To easily test a webapp it is convenient to not have to build
# the entire war and deply it, but to instead set up a fake
# webapp created out of symlinks.

# Webapp source dir
webappdir = "src/webapp/"

# Number of dirs to trim off source
trimcount = 1

webconfig = "WEB-INF"
skipdirs = [".svn"]
libdirs = ["target/classes", "lib"]

logdir = webappdir + "logs/"
logdirumask = 02070 # g+rwxs
tomcatgrp = "tomcat"

if not os.name == "posix":
    raise NameError, "Uses symlinks; needs a unixesque os, not " + os.name

def downpath(path):
    """Converts a path into the path needed for a relative link"""
    return re.sub("[^/]+/*", "../", path)

def cutpath(path, trimcount = 1):
    return re.sub("[^/]+/", "", path, trimcount)

def safelink(origpath, newpath):
    if not os.path.exists(newpath):
        try:
            os.symlink(origpath, newpath)
            print "Linked %s => %s" % (origpath, newpath)
        except OSError, (errno, errstr):
            print "Error linking %s => %s (%s)" \
                  % (origpath, newpath, errstr)
    else:
        print "Skipped: " + newpath
                                                                            
def linkdir(path, trimcount):
    """Links all the files in a directory into another directory"""
    print "Setting up links to: " + path
    newpath = cutpath(path, trimcount)
    if not os.path.exists(newpath):
        print "Creating: " + newpath
        os.mkdir(newpath)
    for file in os.listdir(path):
        newfile = newpath + file
        if not skipdirs.__contains__(file) and file != webconfig:
            safelink(downpath(newpath) + path + file, \
                     newfile)
        elif file == webconfig:
            linkdir(path + file + "/", trimcount)

linkdir(webappdir, trimcount)

# Trim / off name or link thinks it is supposed to
# go in the direcotry
safelink(downpath(cutpath(webappdir)) + logdir, \
         logdir[:-1])
try:
    gid = grp.getgrnam(tomcatgrp)[2]
    if gid != os.stat(logdir)[5]:
        os.chown(logdir, os.getuid(), gid)
        print "Owned %s to :%s" % (logdir, tomcatgrp)
    
    mode = os.stat(logdir)[0]
    if mode != mode | logdirumask:
        os.chmod(logdir, mode | logdirumask)
        print "Set permissions on %s to from %o to %o" \
              % (logdir, mode, mode | logdirumask)
except KeyError:
    print 'Could not get group "' + tomcatgrp + '"'

dest = cutpath(webappdir) + webconfig + "/"

for dir in libdirs:
    safelink(downpath(dest) + dir, \
             dest + re.sub("[^/]+/+", "", dir))
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to