Svn PRE-COMMIT Hook to scan java class content

The first time I make such a hook ..

I need a pre-commit hook that scans all java classes for commit, it should check for any character in the class and avoid commit if some of them are found, such as characters or †, etc. I think a good way to do this dynamically changing can bring all these invalid characters to a plan file so that it can be easily changed if we need to ...

I start with a simple hook that I wrote a long time ago.

Now problem BIG gets the location of the working copy files. I have to scan the contents.

I have tried many svnlook commands, but I really cannot catch this information in a pre-commit hook ....

Getting a lot of information, but not a local file path. I use this to search for content ...

 OUTPUT="$($SVNLOOK changed -t $TXN $REPOS)"
 echo $SVNLOOK changed -t $TXN $REPOS 1>&2
 echo "$BASEDIR" 1>&2
 echo "${OUTPUT}" 1>&2
 echo "$TXN $REPOS" 1>&2  

Maybe this is my approach wrong?

Thank you so much!

UPDATED

Thanks to "CaffeineAddiction", you know that this is always a "BIG QUESTION" when you do something for the first time.

In fact, the real problem after all, after one day of trying was another, the SVN error related to the char client:

 Error output could not be translated from the native locale to UTF-8

Now this last question has been resolved, and the script is working, you can see it below, you just need to decorate it, by the way thanks for you, I will get some ideas from you:

 REPOS="$1"
 TXN="$2"

 SVNLOOK=/usr/bin/svnlook

 OUTPUT="$($SVNLOOK changed -t $TXN $REPOS | awk '{print $2}')"

 for LINE in $OUTPUT
 do
   FILE=`echo $LINE`
   MESSAGE=`$SVNLOOK cat -t "$TXN" "$REPOS" "${FILE}"`
   echo "File is: $FILE" 1>&2
   echo "${MESSAGE}" > /tmp/app.txt
   grep -P -n '[\x80-\xFF]' /tmp/app.txt | cut -f1 -d: 1>&2
 done
+4
source share
1 answer

, , . gjslint javascript, SVN. , :

#!/bin/sh

SVNLOOK=/usr/bin/svnlook
GJSLINT=/usr/local/bin/gjslint

ECHO=$(which echo)
GREP=$(which grep)
SED=$(which sed)

## Used for Debug
#MYRUNLOG=/run/svn-pre-commit/pre-commit.log
#touch $MYRUNLOG
#echo "" > $MYRUNLOG

MYTEMPJS=/run/svn-pre-commit/temp.js
touch $MYTEMPJS
echo "" > $MYTEMPJS

MYTEMPLOG=/run/svn-pre-commit/gjslint.log
touch $MYTEMPLOG
echo "" > $MYTEMPLOG

REPOS="$1"
TXN="$2"

FILES_CHANGED=`$SVNLOOK changed -t$TXN $REPOS | $SED -e "s/^....//g"`
LINTERROR=0

for FILE in $FILES_CHANGED
do
    if $ECHO $FILE | $GREP "\.js$"
    then
        if ! $ECHO "$REPOS/$FILE" | $GREP "/paweb5/\|/pamc/"; then exit 0; fi
        if $ECHO "$REPOS/$FILE" | $GREP "/doc/"; then exit 0; fi
        if $ECHO "$REPOS/$FILE" | $GREP "/docs/"; then exit 0; fi
        $SVNLOOK cat -t$TXN $REPOS $FILE > $MYTEMPJS
        $ECHO "$REPO/$FILE" >> $MYTEMPLOG
        $GJSLINT --strict --disable 0001 $MYTEMPJS >> $MYTEMPLOG
        GJSL_ERROR_CODE=$?
        if [ $GJSL_ERROR_CODE != 0 ]
        then
            LINTERROR=1
        fi
        $ECHO "~~~" >> $MYTEMPLOG
    fi
done

if [ $LINTERROR != 0 ]
then
  echo "..........................................................................." >&2
  while read line; do
    if $ECHO $line | $GREP "Line\|no errors\|new errors\|paweb5\|~~~"
    then
      echo $line >&2
    fi
  done < $MYTEMPLOG
  echo "..........................................................................." >&2
  exit 1
fi

# If we got here, nothing is wrong.
exit 0

, " ", , $SVNLOOK cat -t$TXN $REPOS $FILE > $MYTEMPJS

script,

+2

All Articles