cziegeler 02/01/11 01:35:28 Modified: . build.bat build.sh build.xml Added: tools/bin ant ant.bat antRun antRun.bat fix-packages.py lcp.bat runant.pl tools/lib ant-1.4.1-optional.jar ant-1.4.1.jar tools/src ClassAvailable.java SitemapTool.java Removed: bin ant ant.bat antRun antRun.bat fix-packages.py lcp.bat runant.pl bin/src ClassAvailable.java SitemapTool.java lib ant_1_4-optional.jar ant_1_4.jar Log: Moved build system to tools directory Revision Changes Path 1.9 +7 -2 xml-cocoon2/build.bat Index: build.bat =================================================================== RCS file: /home/cvs/xml-cocoon2/build.bat,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- build.bat 13 Sep 2001 10:28:49 -0000 1.8 +++ build.bat 11 Jan 2002 09:35:27 -0000 1.9 @@ -2,13 +2,18 @@ rem ---------------------------------------------------------------------------- rem build.bat - Win32 Build Script for Apache Cocoon rem -rem $Id: build.bat,v 1.8 2001/09/13 10:28:49 cziegeler Exp $ +rem $Id: build.bat,v 1.9 2002/01/11 09:35:27 cziegeler Exp $ rem ---------------------------------------------------------------------------- +rem ----- Copy Xalan and Xerces for the build system ------------------------ +copy lib\xerces*.jar tools\lib +copy lib\xalan*.jar tools\lib +copy lib\xml-api*.jar tools\lib + rem ----- Verify and Set Required Environment Variables ------------------------ if not "%ANT_HOME%" == "" goto gotAntHome -set ANT_HOME=. +set ANT_HOME=tools :gotAntHome call %ANT_HOME%\bin\ant %1 %2 %3 %4 %5 %6 %7 %8 %9 1.8 +7 -3 xml-cocoon2/build.sh Index: build.sh =================================================================== RCS file: /home/cvs/xml-cocoon2/build.sh,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- build.sh 26 Nov 2001 22:40:33 -0000 1.7 +++ build.sh 11 Jan 2002 09:35:27 -0000 1.8 @@ -4,8 +4,12 @@ echo "Apache Cocoon 2 Build System" echo "----------------------------" -chmod u+x ./bin/antRun -chmod u+x ./bin/ant +cp ./lib/xalan*.jar ./tools/lib +cp ./lib/xerces*.jar ./tools/lib +cp ./lib/xml-api*.jar ./tools/lib + +chmod u+x ./tools/bin/antRun +chmod u+x ./tools/bin/ant unset ANT_HOME @@ -13,7 +17,7 @@ export CP unset CLASSPATH -$PWD/bin/ant -logger org.apache.tools.ant.NoBannerLogger -emacs $@ +$PWD/bin/tools/ant -logger org.apache.tools.ant.NoBannerLogger -emacs $@ CLASSPATH=$CP export CLASSPATH 1.131 +10 -11 xml-cocoon2/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/build.xml,v retrieving revision 1.130 retrieving revision 1.131 diff -u -r1.130 -r1.131 --- build.xml 8 Jan 2002 10:27:11 -0000 1.130 +++ build.xml 11 Jan 2002 09:35:27 -0000 1.131 @@ -168,6 +168,7 @@ <property name="test.dir" value="${src.dir}/test"/> <property name="lib.dir" value="./lib"/> <property name="bin.dir" value="./bin"/> + <property name="tools.dir" value="./tools"/> <property name="docs.dir" value="${src.dir}/documentation/xdocs"/> <property name="images.dir" value="${src.dir}/documentation/images"/> <property name="webapp.dir" value="${src.dir}/webapp"/> @@ -231,8 +232,8 @@ <filter token="database-password" value="${database-password}"/> <!-- compile the ant tasks --> - <mkdir dir="bin/anttasks"/> - <javac srcdir="bin/src" destdir="bin/anttasks"/> + <mkdir dir="${tools.dir}/anttasks"/> + <javac srcdir="${tools.dir}/src" destdir="${tools.dir}/anttasks"/> </target> @@ -244,7 +245,7 @@ <!-- A simple task to test for a class --> <taskdef name="ClassAvailable" classname="ClassAvailable" - classpath="./bin/anttasks"/> + classpath="./tools/anttasks"/> <available property="jaxen.present" classname="org.jaxen.dom.XPath"> <classpath refid="classpath"/> @@ -830,7 +831,7 @@ <target name="prepare-webapp" depends="copy-webapp"> <!-- A task to change the sitemap. It is used to add optional components --> <taskdef name="SitemapTool" classname="SitemapTool" - classpath="./bin/anttasks"/> + classpath="${tools.dir}/anttasks"/> <!-- Invoke the SitemapTool to add optional entries --> <SitemapTool directory="${build.src}" @@ -861,8 +862,6 @@ <copy todir="${build.war}/WEB-INF/lib"> <fileset dir="${lib.dir}"> <include name="*.jar"/> - <exclude name="ant*.jar"/> - <exclude name="stylebook*.jar"/> <exclude name="servlet*.jar"/> </fileset> </copy> @@ -885,8 +884,6 @@ <copy todir="${build.war}/WEB-INF/lib"> <fileset dir="${scratchpad.lib}"> <include name="*.jar"/> - <exclude name="ant*.jar"/> - <exclude name="stylebook*.jar"/> <exclude name="servlet*.jar"/> </fileset> </copy> @@ -1091,10 +1088,14 @@ <mkdir dir="${dist.src.dir}/src/webapp"/> <mkdir dir="${dist.src.dir}/docs"/> <mkdir dir="${dist.src.dir}/docs/apidocs"/> + <mkdir dir="${dist.src.dir}/tools"/> <copy todir="${dist.src.dir}/bin"> <fileset dir="${bin.dir}"/> </copy> + <copy todir="${dist.src.dir}/tools"> + <fileset dir="${tools.dir}"/> + </copy> <copy todir="${dist.src.dir}/src/documentation"> <fileset dir="${build.context}"/> @@ -1178,7 +1179,7 @@ <chmod perm="+x" file="${dist.src.dir}/run.sh"/> <chmod perm="+x" file="${dist.src.dir}/build.sh"/> - <chmod perm="+x" file="${dist.src.dir}/bin/antRun"/> + <chmod perm="+x" file="${dist.src.dir}/tools/bin/antRun"/> <fixcrlf srcdir="${dist.src.dir}" includes="**.sh" eol="lf"/> <fixcrlf srcdir="${dist.src.dir}" includes="antRun" eol="lf"/> <fixcrlf srcdir="${dist.src.dir}" includes="**.bat" eol="crlf"/> @@ -1225,8 +1226,6 @@ <copy todir="${dist.bin.dir}/webapp/WEB-INF/lib"> <fileset dir="${lib.dir}"> <include name="*.jar"/> - <exclude name="ant*.jar"/> - <exclude name="stylebook*.jar"/> <exclude name="servlet*.jar"/> </fileset> </copy> 1.1 xml-cocoon2/tools/bin/ant Index: ant =================================================================== #! /bin/sh if [ -f "$HOME/.antrc" ] ; then . $HOME/.antrc fi # Cygwin support. $cygwin _must_ be set to either true or false. case "`uname`" in CYGWIN*) cygwin=true ;; *) cygwin=false ;; esac # For Cygwin, ensure paths are in UNIX format before anything is touched if $cygwin; then [ -n "$ANT_HOME" ] && ANT_HOME=`cygpath --unix "$ANT_HOME"` [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"` fi if [ "$ANT_HOME" = "" ] ; then # try to find ANT if [ -d /opt/ant ] ; then ANT_HOME=/opt/ant fi if [ -d ${HOME}/opt/ant ] ; then ANT_HOME=${HOME}/opt/ant fi ## resolve links - $0 may be a link to ant's home PRG=$0 progname=`basename $0` while [ -h "$PRG" ] ; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '.*/.*' > /dev/null; then PRG="$link" else PRG="`dirname $PRG`/$link" fi done ANT_HOME=`dirname "$PRG"`/.. fi if [ "$JAVA_HOME" != "" ] ; then if [ "$JAVACMD" = "" ] ; then JAVACMD=$JAVA_HOME/bin/java fi else if [ "$JAVACMD" = "" ] ; then JAVACMD=java fi fi # add in the dependency .jar files DIRLIBS=${ANT_HOME}/lib/*.jar for i in ${DIRLIBS} do # if the directory is empty, then it will return the input string # this is stupid, so case for it if [ "$i" != "${DIRLIBS}" ] ; then LOCALCLASSPATH=$LOCALCLASSPATH:"$i" fi done if [ "$CLASSPATH" != "" ] ; then LOCALCLASSPATH=$CLASSPATH:$LOCALCLASSPATH fi if [ "$JAVA_HOME" != "" ] ; then if test -f $JAVA_HOME/lib/tools.jar ; then LOCALCLASSPATH=$LOCALCLASSPATH:$JAVA_HOME/lib/tools.jar fi if test -f $JAVA_HOME/lib/classes.zip ; then LOCALCLASSPATH=$LOCALCLASSPATH:$JAVA_HOME/lib/classes.zip fi else echo "Warning: JAVA_HOME environment variable is not set." echo " If build fails because sun.* classes could not be found" echo " you will need to set the JAVA_HOME environment variable" echo " to the installation directory of java." fi # supply JIKESPATH to Ant as jikes.class.path if [ "$JIKESPATH" != "" ] ; then if [ "$ANT_OPTS" != "" ] ; then ANT_OPTS="$ANT_OPTS -Djikes.class.path=$JIKESPATH" else ANT_OPTS=-Djikes.class.path=$JIKESPATH fi fi # For Cygwin, switch paths to Windows format before running java if $cygwin; then ANT_HOME=`cygpath --path --windows "$ANT_HOME"` JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` LOCALCLASSPATH=`cygpath --path --windows "$LOCALCLASSPATH"` fi $JAVACMD -classpath "$LOCALCLASSPATH" -Dant.home="${ANT_HOME}" $ANT_OPTS org.apache.tools.ant.Main "$@" 1.1 xml-cocoon2/tools/bin/ant.bat Index: ant.bat =================================================================== @echo off if exist "%HOME%\antrc_pre.bat" call "%HOME%\antrc_pre.bat" if not "%OS%"=="Windows_NT" goto win9xStart :winNTStart @setlocal rem %~dp0 is name of current script under NT set DEFAULT_ANT_HOME=%~dp0 rem : operator works similar to make : operator set DEFAULT_ANT_HOME=%DEFAULT_ANT_HOME:\bin\=% if %ANT_HOME%a==a set ANT_HOME=%DEFAULT_ANT_HOME% set DEFAULT_ANT_HOME= rem On NT/2K grab all arguments at once set ANT_CMD_LINE_ARGS=%* goto doneStart :win9xStart rem Slurp the command line arguments. This loop allows for an unlimited number of rem agruments (up to the command line limit, anyway). set ANT_CMD_LINE_ARGS= :setupArgs if %1a==a goto doneStart set ANT_CMD_LINE_ARGS=%ANT_CMD_LINE_ARGS% %1 shift goto setupArgs :doneStart rem This label provides a place for the argument list loop to break out rem and for NT handling to skip to. rem find ANT_HOME if not "%ANT_HOME%"=="" goto checkJava rem check for ant in Program Files on system drive if not exist "%SystemDrive%\Program Files\ant" goto checkSystemDrive set ANT_HOME=%SystemDrive%\Program Files\ant goto checkJava :checkSystemDrive rem check for ant in root directory of system drive if not exist "%SystemDrive%\ant" goto noAntHome set ANT_HOME=%SystemDrive%\ant goto checkJava :noAntHome echo ANT_HOME is not set and ant could not be located. Please set ANT_HOME. goto end :checkJava set _JAVACMD=%JAVACMD% set LOCALCLASSPATH="%CLASSPATH%" for %%i in ("%ANT_HOME%\lib\*.jar") do call "%ANT_HOME%\bin\lcp.bat" "%%i" if "%JAVA_HOME%" == "" goto noJavaHome if "%_JAVACMD%" == "" set _JAVACMD=%JAVA_HOME%\bin\java if exist "%JAVA_HOME%\lib\tools.jar" call "%ANT_HOME%\bin\lcp.bat" "%JAVA_HOME%\lib\tools.jar" if exist "%JAVA_HOME%\lib\classes.zip" call "%ANT_HOME%\bin\lcp.bat" "%JAVA_HOME%\lib\classes.zip" goto checkJikes :noJavaHome if "%_JAVACMD%" == "" set _JAVACMD=java echo. echo Warning: JAVA_HOME environment variable is not set. echo If build fails because sun.* classes could not be found echo you will need to set the JAVA_HOME environment variable echo to the installation directory of java. echo. :checkJikes if not "%JIKESPATH%" == "" goto runAntWithJikes :runAnt %_JAVACMD% -classpath %LOCALCLASSPATH% -Dant.home="%ANT_HOME%" %ANT_OPTS% org.apache.tools.ant.Main %ANT_CMD_LINE_ARGS% goto end :runAntWithJikes %_JAVACMD% -classpath %LOCALCLASSPATH% -Dant.home="%ANT_HOME%" -Djikes.class.path=%JIKESPATH% %ANT_OPTS% org.apache.tools.ant.Main %ANT_CMD_LINE_ARGS% :end set LOCALCLASSPATH= set _JAVACMD= set ANT_CMD_LINE_ARGS= if not "%OS%"=="Windows_NT" goto mainEnd :winNTend @endlocal :mainEnd if exist "%HOME%\antrc_post.bat" call "%HOME%\antrc_post.bat" 1.1 xml-cocoon2/tools/bin/antRun Index: antRun =================================================================== #! /bin/sh # Args: DIR command cd "$1" CMD="$2" shift shift exec $CMD "$@" 1.1 xml-cocoon2/tools/bin/antRun.bat Index: antRun.bat =================================================================== @echo off # Change drive and directory to %1 (Win9X only for NT/2K use "cd /d") cd %1 %1\ set ANT_RUN_CMD=%2 shift shift set PARAMS= :loop if ""%1 == "" goto runCommand set PARAMS=%PARAMS% %1 shift goto loop :runCommand rem echo %ANT_RUN_CMD% %PARAMS% %ANT_RUN_CMD% %PARAMS% 1.1 xml-cocoon2/tools/bin/fix-packages.py Index: fix-packages.py =================================================================== #! /usr/bin/env python # # Mass string translation for java/xml files (change Wanted re for other files) # # Author: Peter Donald <[EMAIL PROTECTED]> # # Adapted from fixid.py in python distribution under Tools # import sys import re import string import os from stat import * import getopt err = sys.stderr.write dbg = err out = sys.stdout.write def usage(): progname = sys.argv[0] err('Usage: ' + progname + ' [-s file] ... file-or-directory ...\n') err('\n') err('-s substfile : add a file of substitutions\n') err('\n') err('Each non-empty non-comment line in a substitution file must\n') err('contain exactly two words separated by a | character.\n') def main(): try: opts, args = getopt.getopt(sys.argv[1:], 'crs:') except getopt.error, msg: err('Options error: ' + str(msg) + '\n') usage() sys.exit(2) bad = 0 if not args: # No arguments usage() sys.exit(2) for opt, arg in opts: if opt == '-s': addsubst(arg) initre() for arg in args: if os.path.isdir(arg): if recursedown(arg): bad = 1 elif os.path.islink(arg): err(arg + ': will not process symbolic links\n') bad = 1 else: if fix(arg): bad = 1 sys.exit(bad) # Change this regular expression to select a different set of files Wanted = '^[a-zA-Z0-9_\-]+\.(java|xml|xinfo)$' def wanted(name): return None <> re.match(Wanted, name) def recursedown(dirname): dbg('recursedown(' + `dirname` + ')\n') bad = 0 try: names = os.listdir(dirname) except os.error, msg: err(dirname + ': cannot list directory: ' + str(msg) + '\n') return 1 names.sort() subdirs = [] for name in names: if name in (os.curdir, os.pardir): continue fullname = os.path.join(dirname, name) if os.path.islink(fullname): pass elif os.path.isdir(fullname): subdirs.append(fullname) elif wanted(name): if fix(fullname): bad = 1 for fullname in subdirs: if recursedown(fullname): bad = 1 return bad def fix(filename): dbg('fix(' + `filename` + ')\n') # File replacement mode try: f = open(filename, 'r') except IOError, msg: err(filename + ': cannot open: ' + str(msg) + '\n') return 1 head, tail = os.path.split(filename) tempname = os.path.join(head, '@' + tail) # If we find a match, we rewind the file and start over but # now copy everything to a temp file. lineno = 0 g = None while 1: line = f.readline() if not line: break lineno = lineno + 1 newline = fixline(line) if newline != line: if g is None: try: g = open(tempname, 'w') except IOError, msg: f.close() err(tempname+': cannot create: '+ str(msg)+'\n') return 1 f.seek(0) lineno = 0 out(filename + ':\n') continue # restart from the beginning out(`lineno` + '\n') out('< ' + line) out('> ' + newline) if g is not None: g.write(newline) # End of file f.close() if not g: return 0 # No changes # Finishing touch -- move files # First copy the file's mode to the temp file try: statbuf = os.stat(filename) os.chmod(tempname, statbuf[ST_MODE] & 07777) except os.error, msg: err(tempname + ': warning: chmod failed (' + str(msg) + ')\n') # Then make a backup of the original file as filename~ try: os.rename(filename, filename + '~') except os.error, msg: err(filename + ': warning: backup failed (' + str(msg) + ')\n') # Now move the temp file to the original file try: os.rename(tempname, filename) except os.error, msg: err(filename + ': rename failed (' + str(msg) + ')\n') return 1 # Return succes return 0 def initre(): global SearcherExpr keys = Dict.keys() keyCount = len(keys) i = 0 reStr = "" while i < len(keys): if i != 0: reStr = reStr + '|' reStr = reStr + keys[i] i = i + 1 SearcherExpr = re.compile( reStr ) def fixline(line): global Program ## print '-->', `line` i = 0 while i < len(line): match = SearcherExpr.search(line, i) if match == None: break found = match.group(0) i = match.start() n = len(found) if Dict.has_key(found): subst = Dict[found] line = line[:i] + subst + line[i+n:] n = len(subst) i = i + n return line Dict = {} NotInComment = {} def addsubst(substfile): try: fp = open(substfile, 'r') except IOError, msg: err(substfile + ': cannot read substfile: ' + str(msg) + '\n') sys.exit(1) lineno = 0 while 1: line = fp.readline() if not line: break lineno = lineno + 1 try: i = string.index(line, '#') except string.index_error: i = -1 # Happens to delete trailing \n words = string.split(line[:i],'|') if not words: continue if len(words) <> 2: err(substfile + ':' + `lineno` + ': warning: bad line: ' + line) continue [key, value] = words ## print 'Will replace ', key, ' with ', value Dict[key] = value fp.close() main() 1.1 xml-cocoon2/tools/bin/lcp.bat Index: lcp.bat =================================================================== set LOCALCLASSPATH=%1;%LOCALCLASSPATH% 1.1 xml-cocoon2/tools/bin/runant.pl Index: runant.pl =================================================================== #!/usr/bin/perl ####################################################################### # # runant.pl # # wrapper script for invoking ant in a platform with Perl installed # this may include cgi-bin invocation, which is considered somewhat daft. # (slo: that should be a separate file which can be derived from this # and returns the XML formatted output) # # the code is not totally portable due to classpath and directory splitting # issues. oops. (NB, use File::Spec::Functions will help and the code is # structured for the catfile() call, but because of perl version funnies # the code is not included. # # created: 2000-8-24 # last modified: 2000-8-24 # author: Steve Loughran [EMAIL PROTECTED] ####################################################################### # # Assumptions: # # - the "java" executable/script is on the command path # - ANT_HOME has been set # - target platform uses ":" as classpath separator or perl indicates it is dos/win32 # - target platform uses "/" as directory separator. #be fussy about variables use strict; #platform specifics (disabled) #use File::Spec::Functions; #turn warnings on during dev; generates a few spurious uninitialised var access warnings #use warnings; #and set $debug to 1 to turn on trace info my $debug=0; ####################################################################### # # check to make sure environment is setup # my $HOME = $ENV{ANT_HOME}; if ($HOME eq "") { die "\n\nANT_HOME *MUST* be set!\n\n"; } my $JAVACMD = $ENV{JAVACMD}; $JAVACMD = "java" if $JAVACMD eq ""; #ISSUE: what java wants to split up classpath varies from platform to platform #and perl is not too hot at hinting which box it is on. #here I assume ":" 'cept on win32 and dos. Add extra tests here as needed. my $s=":"; if(($^O eq "MSWin32") || ($^O eq "dos")) { $s=";"; } #build up standard classpath my $localpath=$ENV{CLASSPATH}; if ($localpath eq "") { print "warning: no initial classpath\n" if ($debug); $localpath=""; } #add jar files. I am sure there is a perl one liner to do this. my $jarpattern="$HOME/lib/*.jar"; my @jarfiles =glob($jarpattern); print "jarfiles=@jarfiles\n" if ($debug); my $jar; foreach $jar (@jarfiles ) { $localpath.="$s$jar"; } #if Java home is defined, look for tools.jar & classes.zip and add to classpath my $JAVA_HOME = $ENV{JAVA_HOME}; if ($JAVA_HOME ne "") { my $tools="$JAVA_HOME/lib/tools.jar"; if (-e "$tools") { $localpath .= "$s$tools"; } my $classes="$JAVA_HOME/lib/classes.zip"; if (-e $classes) { $localpath .= "$s$classes"; } } else { print "\n\nWarning: JAVA_HOME environment variable is not set.\n". "If the build fails because sun.* classes could not be found\n". "you will need to set the JAVA_HOME environment variable\n". "to the installation directory of java\n"; } #jikes my @ANT_OPTS=split $ENV{ANT_OPTS}; if($ENV{JIKESPATH} ne "") { push @ANT_OPTS, "-Djikes.class.path=$ENV{JIKESPATH}"; } #construct arguments to java my @ARGS; push @ARGS, "-classpath", "$localpath", "-Dant.home=$HOME"; push @ARGS, @ANT_OPTS; push @ARGS, "org.apache.tools.ant.Main"; push @ARGS, @ARGV; print "\n $JAVACMD @ARGS\n\n" if ($debug); my $returnValue = system $JAVACMD, @ARGS; if ($returnValue eq 0) { exit 0; } else { # only 0 and 1 are widely recognized as exit values # so change the exit value to 1 exit 1; } 1.1 xml-cocoon2/tools/lib/ant-1.4.1-optional.jar <<Binary file>> 1.1 xml-cocoon2/tools/lib/ant-1.4.1.jar <<Binary file>> 1.1 xml-cocoon2/tools/src/ClassAvailable.java Index: ClassAvailable.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ import java.io.*; import java.util.*; import java.util.zip.*; import org.apache.tools.ant.*; import org.apache.tools.ant.taskdefs.*; import org.apache.tools.ant.types.*; /** * Will set the given property if the requested class is available in the * specified classpath. The found class is not loaded! * This class is heavily based on the available task in the ant package: * @author Stefano Mazzocchi <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> * * This task searches only in the defined path but not in the parents path * unless explicitly overridden by the value of ${build.sysclasspath} * like the original available task does. * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Revision: 1.1 $ $Date: 2002/01/11 09:35:28 $ */ public class ClassAvailable extends Task { /** * A hashtable of zip files opened by the classloader */ private Hashtable zipFiles = new Hashtable(); private String property; private String classname; private Path classpath; private String value = "true"; public void setClasspath(Path classpath) { createClasspath().append(classpath); } public Path createClasspath() { if (this.classpath == null) { this.classpath = new Path(this.project); } return this.classpath.createPath(); } public void setClasspathRef(Reference r) { createClasspath().setRefid(r); } public void setProperty(String property) { this.property = property; } public void setValue(String value) { this.value = value; } public void setClassname(String classname) { if (!"".equals(classname)) { this.classname = classname; } } public void execute() throws BuildException { if (property == null) { throw new BuildException("property attribute is required", location); } if (eval()) { this.project.setProperty(property, value); } } public boolean eval() throws BuildException { if (classname == null) { throw new BuildException("At least one of (classname|file|resource) is required", location); } if (classpath != null) { classpath.setProject(project); classpath = classpath.concatSystemClasspath("ignore"); } if (!findClassInComponents(classname)) { log("Unable to load class " + classname + " to set property " + property, Project.MSG_VERBOSE); return false; } return true; } /** * Get an inputstream to a given resource in the given file which may * either be a directory or a zip file. * * @param file the file (directory or jar) in which to search for the resource. * @param resourceName the name of the resource for which a stream is required. * * @return a stream to the required resource or null if the resource cannot be * found in the given file object */ private boolean contains(File file, String resourceName) { try { if (!file.exists()) { return false; } if (file.isDirectory()) { File resource = new File(file, resourceName); if (resource.exists()) { return true; } } else { // is the zip file in the cache ZipFile zipFile = (ZipFile)zipFiles.get(file); if (zipFile == null) { zipFile = new ZipFile(file); zipFiles.put(file, zipFile); } ZipEntry entry = zipFile.getEntry(resourceName); if (entry != null) { return true; } } } catch (Exception e) { log("Ignoring Exception " + e.getClass().getName() + ": " + e.getMessage() + " reading resource " + resourceName + " from " + file, Project.MSG_VERBOSE); } return false; } /** * Find a class on the given classpath. */ private boolean findClassInComponents(String name) { // we need to search the components of the path to see if we can find the // class we want. final String classname = name.replace('.', '/') + ".class"; final String[] list = classpath.list(); boolean found = false; int i = 0; while (i < list.length && found == false) { final File pathComponent = (File)project.resolveFile(list[i]); found = this.contains(pathComponent, classname); i++; } return found; } } 1.1 xml-cocoon2/tools/src/SitemapTool.java Index: SitemapTool.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ import java.io.*; import java.util.*; import org.apache.tools.ant.*; import org.apache.tools.ant.taskdefs.*; import org.apache.tools.ant.types.*; /** * Add components to the sitemap * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Revision: 1.1 $ $Date: 2002/01/11 09:35:28 $ */ public final class SitemapTool extends Task { private String sitemap; private String directory; private String extension; public void setSitemap(String sitemap) { this.sitemap = sitemap; } public void setDirectory(String directory) { this.directory = directory; } public void setExtension(String extension) { this.extension = extension; } public void execute() throws BuildException { if (this.sitemap == null) { throw new BuildException("sitemap attribute is required", location); } if (this.extension == null) { throw new BuildException("extension attribute is required", location); } if (this.directory == null) { throw new BuildException("directory attribute is required", location); } try { // process recursive this.process(new File(this.directory), this.extension, this.sitemap); } catch (IOException ioe) { throw new BuildException("IOException: " + ioe); } } /** * Scan recursive */ private void process(final File directoryFile, final String ext, final String sitemapLocation) throws IOException, BuildException { final File[] files = directoryFile.listFiles(); for(int i = 0; i < files.length; i++) { if (files[i].isDirectory() == true) { this.process(files[i], ext, sitemapLocation); } else { if (files[i].getName().endsWith("."+ext) == true) { System.out.println("Reading: " + files[i].getAbsolutePath()); final String data = this.load(files[i].getAbsolutePath()); // separate the data by lines final StringTokenizer st = new StringTokenizer(data); while (st.hasMoreElements() == true) { // now get the properties of a line. These are separated by a "|" final String line = (String)st.nextElement(); final StringTokenizer prop = new StringTokenizer(line, "|"); String category = null; String componentName = null; String className = null; String configuration = null; String label = null; String mimeType = null; while (prop.hasMoreElements() == true) { final String property = (String)prop.nextElement(); final int pos = property.indexOf(":"); final String propName = property.substring(0, pos); final String propVal = property.substring(pos+1); if (propName.equals("category")) category = propVal; else if (propName.equals("componentName")) componentName = propVal; else if (propName.equals("componentClass")) className = propVal; else if (propName.equals("configuration")) configuration = propVal; else if (propName.equals("label")) label = propVal; else if (propName.equals("mimeType")) mimeType = propVal; else throw new BuildException("Unknown property " + propName + " in file " + files[i].getAbsolutePath()); } // Test for required values if (category == null) { throw new BuildException("category property is required in file " + files[i].getAbsolutePath(), location); } if (componentName == null) { throw new BuildException("componentName property is required in file " + files[i].getAbsolutePath(), location); } if (className == null) { throw new BuildException("componentClass property is required in file " + files[i].getAbsolutePath(), location); } this.add(sitemapLocation, category, componentName, className, configuration, label, mimeType); } } } } } /** * Add entry to sitemap */ private void add(final String sitemapLocation, final String category, final String componentName, final String className, final String configuration, final String label, final String mimeType) throws IOException { final String data = load( sitemapLocation ); final String searchString = new StringBuffer( "</map:" ) .append( category ) .append( ">" ).toString(); final int pos = data.indexOf( searchString ); int categoryStartPos = data.indexOf(new StringBuffer( "<map:" ) .append( category ) .append( ">" ).toString() ); if ( categoryStartPos == -1 ) categoryStartPos = data.indexOf(new StringBuffer( "<map:" ) .append( category ) .append( " " ).toString() ); if ( categoryStartPos != -1 && categoryStartPos < pos && pos != -1 ) { // the category exists, now search if a component // with the name already exists int componentPos = data.substring( categoryStartPos, pos ).indexOf( new StringBuffer( "name=\"" ) .append( componentName ) .append( "\"" ).toString() ); if ( componentPos == -1 ) { StringBuffer buffer = new StringBuffer( data.substring( 0, pos ) ) .append( "<map:" ) .append( category.substring( 0, category.length() - 1 ) ) .append( " name=\"" ) .append( componentName ) .append( "\" src=\"" ).append( className ).append( "\"" ) .append( " logger=\"sitemap.") .append( category.substring( 0, category.length() - 1 ) ) .append( '.' ) .append( componentName ) .append( '\"'); if ( null != mimeType && mimeType.length() > 0) { buffer.append( " mime-type=\"" ).append( mimeType ).append( "\"" ); } if ( null != label && label.length() > 0) { buffer.append( " label=\"" ).append( label ).append( "\"" ); } if ( null != configuration ) { buffer.append( ">\n" ).append( configuration ).append( "\n" ) .append( "</map:" ).append( category.substring( 0, category.length() - 1 ) ).append( ">\n" ); } else { buffer.append( "/>\n" ); } buffer.append( data.substring( pos ) ).toString(); this.save( sitemapLocation, buffer.toString() ); } } } /** * Load a file and return the content as a string. */ public String load( String filename ) throws IOException { FileInputStream fis; fis = new FileInputStream( filename ); int available; byte[] data = null; byte[] tempData; byte[] copyData; do { available = 1024; tempData = new byte[available]; available = fis.read( tempData, 0, available ); if ( available > 0 ) { copyData = new byte[( data == null ? 0 : data.length ) + available]; if ( data != null ) { System.arraycopy( data, 0, copyData, 0, data.length ); } System.arraycopy( tempData, 0, copyData, ( data == null ? 0 : data.length ), available ); data = copyData; } } while ( available > 0 ); fis.close(); return ( data != null ? new String( data ) : "" ); } /** * Save the string to a file */ public void save( String filename, String data ) throws IOException { FileWriter fw = new FileWriter( filename ); fw.write( data ); fw.close(); } }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]