Check to see if the Java class is in SVN.

I want to make sure the Java class is commented out before someone commits something to the SVN repository. Therefore, I want to implement the following workflow:

  • User changes something in class
  • User wants to execute class
  • Before committing to the SVN repository or something else, it checks to see if there are comments before the class and before the publicmethods (for Java AutoDoc).
  • If there are comments => Commit, otherwise return an error message

How can I understand that? I learned a lot about interceptions. But it was all about checking if the post / comment commit was set.

It would be very nice and helpful if someone could solve the problem.

+3
source share
1

, , CheckStyle.

CheckStyle -. xml config file CheckStyle, , / JavaDoc ( javadoc_check. xml):

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
                    "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <module name="TreeWalker">
        <module name="JavadocMethod">
            <property name="scope" value="public"/>
        </module>
        <module name="JavadocType">
            <property name="scope" value="public"/>
        </module>
    </module>
</module>

, pre_commit hook, :

#!/bin/bash

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

CHECKSTYLEJAR=/path/to/checkstyle-5.7/checkstyle-5.7-all.jar
CHECKSTYLECONFIG=/path/to/javadoc_check.xml

SVNLOOK=/usr/bin/svnlook
JAVA=/usr/bin/java

EXITSTATUS=0
ERRORMARKER=__ERROR_MARKER__

# Create temporary dir
TMPDIR=$(mktemp -d)

# Iterate on the files commited
while read changeline;
do
    # Get the filename
    file=${changeline:4}

    # Check if it an Updated or Added java file
    if [[ $file == *.java && ($changeline == U* || $changeline == A*) ]] ; then
        # Get the file content in a temporary file
        $SVNLOOK cat -t "$TXN" "$REPOS" "$file" > $TMPDIR/${file##*/}

        echo -e "\n=> Checking $file"
        # Check the file with checkstyle
        ( $JAVA -jar $CHECKSTYLEJAR -c $CHECKSTYLECONFIG $TMPDIR/${file##*/} 2>&1 || echo "$ERRORMARKER" 1>&2 ) | sed -e "s{$TMPDIR/{{"

        # Delete the temporary file
        rm $TMPDIR/${file##*/}
    fi
done < <($SVNLOOK changed -t "$TXN" "$REPOS") 3>&2 2>&1 1>&3 | grep "$ERRORMARKER" && EXITSTATUS=1 # Check for errors

# Delete temporary dir
rmdir $TMPDIR

exit $EXITSTATUS

CheckStyle CheckStyle.

, java JavaDoc /, , :

$ svn commit
Sending        test.java
Transmitting file data .svn: E165001: Commit failed (details follow):
svn: E165001: Commit blocked by pre-commit hook (exit code 1) with output:

=> Checking test.java
Starting audit...
test.java:9:1: Missing a Javadoc comment.
Audit done.

svn: E165001: Your commit message was left in a temporary file:
svn: E165001:    '/path/to/project/svn-commit.1.tmp'
$

, , , / java JavaDoc.

+1

All Articles