summaryrefslogtreecommitdiffstats
path: root/check_java_packages
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-08-27 14:30:37 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-08-27 14:30:37 +0200
commit0ff9f57850df1a9db6c45f40d9752692d06a8f4b (patch)
tree5fcd1e2338a9b294d6dc7589c1c24cb08c495e86 /check_java_packages
parentbb726e02dc766e585e4fd0f0c4f7d8e5a7faec16 (diff)
downloadbin-0ff9f57850df1a9db6c45f40d9752692d06a8f4b.zip
bin-0ff9f57850df1a9db6c45f40d9752692d06a8f4b.tar.gz
add check_java_packages
Diffstat (limited to 'check_java_packages')
-rwxr-xr-xcheck_java_packages41
1 files changed, 41 insertions, 0 deletions
diff --git a/check_java_packages b/check_java_packages
new file mode 100755
index 0000000..f90e520
--- /dev/null
+++ b/check_java_packages
@@ -0,0 +1,41 @@
+#! /bin/bash
+
+if [ $# -lt 1 ]; then
+ echo "missing PATH argument"
+ exit 1
+fi
+
+TOPDIR=$1
+ERRORS=.check_package.err
+
+RESET="\033[0m"
+RED="\033[0;31m"
+BROWN="\033[0;33m"
+GREEN="\033[0;32m"
+
+cd $TOPDIR
+find . -name *.java | while read file; do
+ CORRECT=$(echo $file | sed 's/\.\///; s/\/\+/\./g; s/\.\w\+.java//')
+ N=$(cat $file | grep package | wc -l)
+ if [ $N -gt 1 ]; then
+ echo -e "$file : $BROWN more then 1 package directive$RESET";
+ touch $ERRORS
+ continue
+ fi
+ PACKAGE=$(cat $file | grep package)
+ if [ -z "$PACKAGE" ]; then
+ echo -e "$file : $BROWN missing package directive$RESET";
+ touch $ERRORS
+ continue
+ fi
+ PACKAGE=$(echo "$PACKAGE" | sed 's/ *package *//; s/ *; *$//;')
+ if [ "$PACKAGE" != "${CORRECT}" ]; then
+ echo -e "$file : $RED$PACKAGE$RESET -> $GREEN$CORRECT$RESET";
+ touch $ERRORS
+ fi
+done
+
+if [ -r "$ERRORS" ]; then
+ rm $ERRORS
+ exit 1
+fi