db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcai...@apache.org
Subject svn commit: r922711 - /db/jdo/bin/behead
Date Sun, 14 Mar 2010 01:22:13 GMT
Author: mcaisse
Date: Sun Mar 14 01:22:13 2010
New Revision: 922711

URL: http://svn.apache.org/viewvc?rev=922711&view=rev
Log:
Now works on any .java file. Invocation is unchanged.

Modified:
    db/jdo/bin/behead

Modified: db/jdo/bin/behead
URL: http://svn.apache.org/viewvc/db/jdo/bin/behead?rev=922711&r1=922710&r2=922711&view=diff
==============================================================================
--- db/jdo/bin/behead (original)
+++ db/jdo/bin/behead Sun Mar 14 01:22:13 2010
@@ -5,10 +5,10 @@
 #   to a file of the same name in the target directory
 #
 # Designed to be used to remove license header and imports from
-#    annotation and enum files in the JDO api project for import
-#    into the FrameMaker specification
+#    annotation, enum, and other java files in the JDO api project
+#    for import into the FrameMaker specification
 #
-# Tested on cygwin and Mac
+# Tested on cygwin, Linux, and Mac
 #
 USAGE="behead <source dir> <target dir>"
 if [ $# -ne 2 ]
@@ -20,32 +20,34 @@ fi
 SRCDIR=$1
 TARGETDIR=$2
 
-STARTPATTERN="^@"
-ENUMSTARTPATTERN="public enum"
-
 for FILE in `ls $SRCDIR/*.java`
 do
     ROOT=`basename $FILE .java`
     OUTFILE=${TARGETDIR}/${ROOT}.txt
-    IS_ENUM=0
+
+    # get appropriate start point for this file type
     if [ `grep -c "public enum" $FILE` -gt 0 ]
     then
-        STARTINDEX=`grep --max-count=1 -n "${ENUMSTARTPATTERN}" $FILE | cut -d: -f1 `
-        IS_ENUM=1
-    else
-        STARTINDEX=`grep --max-count=1 -n $STARTPATTERN $FILE | cut -d: -f1 `
-        IS_ENUM=0
+        STARTPATTERN="public enum"
+    elif [ `grep -c "public class" $FILE` -gt 0 ]
+    then
+        STARTPATTERN="public class"
+    elif [ `grep -c "public interface" $FILE` -gt 0 ]
+    then
+        STARTPATTERN="public interface"
+    elif [ `grep -c "^@" $FILE` -gt 0 ]
+    then
+        STARTPATTERN="^@"
+    else 
+        echo "Warning: no start point found for copying lines from $FILE"
+        continue
     fi
-        #echo $STARTINDEX
-        ENDINDEX=`wc -l $FILE | sed -e "s/^  *//" | cut -f1 -d" " `
-        #echo $ENDINDEX
-        NUMLINES=`expr $ENDINDEX - $STARTINDEX + 1`
-        echo Copying ${NUMLINES} lines from $FILE to $OUTFILE
-        if [ ${IS_ENUM} -eq 1 ]
-        then
-            # Workaround for Frame bug: Add blank line at beginning
-            tail -n ${NUMLINES} $FILE | sed -e "1H" -e "1g" > ${OUTFILE}
-        else
-            tail -n ${NUMLINES} $FILE > ${OUTFILE}
-        fi
+
+    STARTINDEX=`grep --max-count=1 -n "${STARTPATTERN}" $FILE | cut -d: -f1 `
+    ENDINDEX=`wc -l $FILE | sed -e "s/^  *//" | cut -f1 -d" " `
+    NUMLINES=`expr $ENDINDEX - $STARTINDEX + 1`
+
+    echo Copying ${NUMLINES} lines from $FILE to $OUTFILE
+    # Workaround for Frame bug: Add blank line at beginning
+    tail -n ${NUMLINES} $FILE | sed -e "1H" -e "1g" > ${OUTFILE}
 done



Mime
View raw message