equal
deleted
inserted
replaced
14 # |
14 # |
15 # Description: |
15 # Description: |
16 # Checks that all the java source files declare a package and that |
16 # Checks that all the java source files declare a package and that |
17 # the directory within a java source file is located corresponds |
17 # the directory within a java source file is located corresponds |
18 # properly to the package. |
18 # properly to the package. |
19 # |
|
20 # Ignores tsrc directories unless the option -all is given. |
|
21 |
19 |
22 import sys, os, re |
20 import sys, os, re |
23 |
21 |
24 |
22 |
25 def main(): |
23 def main(): |
26 |
24 |
27 root = sys.argv[1] |
25 files = [] |
28 all = len(sys.argv) > 2 and sys.argv[2] == '-all' |
|
29 |
|
30 |
26 |
31 # Create a reg exp matching to "package x.y.z;" with whitespace ignored |
27 # Create a reg exp matching to "package x.y.z;" with whitespace ignored |
32 regex = re.compile("\\s*package\\s*([\\w.]*);.*", re.IGNORECASE) |
28 regex = re.compile("\\s*package\\s*([\\w.]*);.*", re.IGNORECASE) |
33 |
29 |
34 def visitFun(arg, dirname, names): |
30 def visitFun(arg, dirname, names): |
35 |
31 |
36 # Skip SVN directories |
32 # Skip SVN directories |
37 if dirname.find("\\.svn") != -1: |
33 if dirname.find("\\.svn") != -1: |
38 return |
34 return names |
39 |
35 |
40 # Skip tsrc |
|
41 if not all and dirname.find("\\tsrc") != -1: |
|
42 return |
|
43 |
|
44 for f in names: |
36 for f in names: |
45 if not f.endswith(".java"): |
37 if not f.endswith(".java"): |
46 continue |
38 continue |
47 |
39 |
48 try: |
40 try: |
69 file.close() |
61 file.close() |
70 |
62 |
71 except IOError: |
63 except IOError: |
72 print "Error reading the file " + fname |
64 print "Error reading the file " + fname |
73 |
65 |
74 os.path.walk(sys.argv[1], visitFun, None) |
66 os.path.walk(sys.argv[1], visitFun, files) |
75 |
67 |
76 |
68 |
77 if __name__ == "__main__": |
69 if __name__ == "__main__": |
78 main() |
70 main() |