1#!/bin/sh -
2
3# The examples must be hand-edited after they are copied:
4# - add EnvironmentConfig.setInitializeCache(true), setInitializeLocking(true)
5# - add DatabaseConfig.setType(DatabaseType.BTREE)
6# - add null databaseName param to openDatabase() and openSecondaryDatabase()
7
8COPY_EXAMPLES=0
9
10JEDIR=$1
11if [ $# -eq 1 ] ; then
12    DBDIR=..
13else
14    DBDIR=$2
15fi
16
17if [ ! -d "$DBDIR/dbinc" -o ! -f "$JEDIR/build.xml" ] ; then
18	echo >&2 "Usage $0 /path/to/je [ /path/to/db ]"
19	exit 1
20fi
21
22JEDIR=$(cd "$JEDIR" ; /bin/pwd)
23DBDIR=$(cd "$DBDIR" ; /bin/pwd)
24
25JESRC="$JEDIR/src"
26JETEST="$JEDIR/test"
27JEEXAMPLES="$JEDIR/examples"
28DBSRC="$DBDIR/java/src"
29DBTEST="$DBDIR/test/scr024/src"
30DBEXAMPLES="$DBDIR/examples_java/src"
31DIRMATCH="com/sleepycat/\(\(asm\)\|\(bind\)\|\(collections\)\|\(persist\)\|\(util\)\)"
32EXAMPLESMATCH="^\./\(\(collections\)\|\(persist\)\)"
33
34cd "$JESRC"
35for d in `find . -type d | grep -v CVS | grep $DIRMATCH` ; do
36    #echo "$DBSRC/$d"
37    mkdir -p "$DBSRC/$d"
38done
39cd "$JETEST"
40for d in `find . -type d | grep -v CVS | grep $DIRMATCH` ; do
41    #echo "$DBTEST/$d"
42    mkdir -p "$DBTEST/$d"
43done
44if [ $COPY_EXAMPLES -eq 1 ] ; then
45    cd "$JEEXAMPLES"
46    for d in `find . -type d | grep -v CVS | grep $EXAMPLESMATCH` ; do
47        #echo "$DBEXAMPLES/$d"
48        mkdir -p "$DBEXAMPLES/$d"
49    done
50fi
51
52E1='s/com\.sleepycat\.je/com.sleepycat.db/g'
53E2='/<!-- begin JE only -->/,/<!-- end JE only -->/d'
54E3='s/LockConflictException/DeadlockException/g'
55E4='s/$Id:.*\$/$Id$/'
56E5='s/TransactionGettingStarted/gsg_txn\/JAVA/'
57EXCLUDESRC="\(\(DeletedClassException\)\|\(IncompatibleClassException\)\|\(StoreExistsException\)\|\(StoreNotFoundException\)\)"
58#EXCLUDESRC="\(\(ClassEnhancerTask\)\|\(DeletedClassException\)\|\(IncompatibleClassException\)\|\(StoreExistsException\)\|\(StoreNotFoundException\)\)"
59EXCLUDETESTS="\(\(ConvertAndAddTest\)\|\(DevolutionTest\)\|\(TestVersionCompatibility\)\|\(XACollectionTest\)\)"
60
61cd "$JESRC"
62for f in `find . -name '*.java' -o -name "package.html" | grep $DIRMATCH | grep -v $EXCLUDESRC` ; do
63    #echo $DBSRC/$f
64    sed -e "$E1" -e "$E2" -e "$E3" -e "$E4" -e "$E5" < $f \
65        > $DBSRC/$f.sed.out
66    diff -q -I "\$\Id:" $DBSRC/$f $DBSRC/$f.sed.out || \
67        mv -f $DBSRC/$f.sed.out $DBSRC/$f
68    rm -f $DBSRC/$f.sed.out
69done
70
71cd "$JETEST"
72for f in `find . -name '*.java' -o -name "*.java.original" | grep $DIRMATCH | grep -v $EXCLUDETESTS` \
73        ; do
74    #echo $DBTEST/$f
75    sed -e "$E1" -e "$E2" -e "$E3" -e "$E4" -e "$E5" < $f \
76        > $DBTEST/$f.sed.out
77    diff -q -I "\$\Id:" $DBTEST/$f $DBTEST/$f.sed.out || \
78        mv -f $DBTEST/$f.sed.out $DBTEST/$f
79    rm -f $DBTEST/$f.sed.out
80done
81
82if [ $COPY_EXAMPLES -eq 1 ] ; then
83    cd "$JEEXAMPLES"
84    for f in `find . -name '*.java' | grep $EXAMPLESMATCH` ; do
85        #echo $DBEXAMPLES/$f
86        sed -e "$E1" -e "$E2" -e "$E3" -e "$E4" -e "$E5" < $f \
87            > $DBEXAMPLES/$f.sed.out
88        diff -q -I "\$\Id:" $DBEXAMPLES/$f $DBEXAMPLES/$f.sed.out || \
89            mv -f $DBEXAMPLES/$f.sed.out $DBEXAMPLES/$f
90        rm -f $DBEXAMPLES/$f.sed.out
91    done
92fi
93
94exit 0
95