Publisher Shell Script |
||||
Home > Java Pub Prep Script > | ||||
|
||||
Java Pub Prep Script Matthias Baerens Contact Links Disclaimer |
I store my source code in one file tree. While developing there come up some auxaliary files that should not be published. I needed a script that leeches given files into another directory and builds all files needed for publishing. So I use a project directory that contains sub-directories as "projects". In this subdirectories there must be a file named FILES.txt. This file lists every file from the source code tree (relative paths!) that should be published. Another file "build.xml" must be there for the ant building tool. It must contain a special target that is described below. These are the steps you have to do (presumed you habe an existing source tree and ant, zip and tar ready to run on your system):
FILES.txt /boot /etc /home . /user1 /java /src /pkg1 /Class1.java /Class2.java /Class3.java /pkg2 /pkg21 /Class1.java /Class2.java /Class3.java /pkg22 /Class1.java /Class2.java /Class3.java /pkg23 /pkg3 /Class1.java /Class2.java /Class3.javaAnd /home/user1/java/src is your source tree root and you want to bundle pkg1.Class3, pkg21.Class1, pkg22.Class1 and pkg3.Class2 in one project. Then your FILE.txt would look like this: pkg1/Class3.java pkg21/Class1.java pkg22/Class1.java pkg3/Class2.java
build.xml <target name="xjar" depends="build"> <jar destfile="../lib.jar" basedir="${build}" > <fileset dir="." excludes="${build}/**" /> </jar> <delete dir="${build}" /> </target> [...] <target name="docs" depends="build"> <jar destfile="../lib.jar" basedir="${build}" > <fileset dir="." excludes="${build}/**" /> </jar> <delete dir="${build}" /> </target> This is what the script does for you:
ATTENTION! You may free use, edit or distribute this script as you like. But it comes with NO WARRANTY at all! So here is the shell script:
# First fit the following three lines to your needs! DEST=/path/to/your/pub/dest # where to publish SOURCES=/path/to/your/source/root # souce home PROJECTS=/path/to/your/projects # project directory echo "Clean up... $DEST" rm -r $DEST/* echo "copy from $SOURCES:" cd $SOURCES shopt -s extglob # needed to exclude docs when deleting, see (*) for folder in $PROJECTS/*; do path=$folder if test -d $folder; then # isDirectory # Extracting project name and make a subfolder in $DEST IFS="/" set -- $folder project=${*:$[$#]} echo $project mkdir --parents "$DEST/$project/src" IFS=" " # copy source files while read line do echo "$SOURCES/$line => $DEST/$project/src/$line" cp -r $line --parents -t $DEST/$project/src done < "$path/FILES.txt" cp $path/* "$DEST/$project" # cd to project publishing dir and create packages and docs cd $DEST/$project zip -r ../$project.zip ./* # create zip file tar cvzf ../$project.tar.gz ./* # create tar.gz file ant xjar # create jar file ant docs # create documentation # at least clean up rm -r ./!(docs) # delete all but docs (*) mv ../$project.zip . mv ../$project.tar.gz . mv ../lib.jar ./$project.jar fi done |
|||
END |