build/buildutils/checkjavapackages.py
changeset 35 85266cc22c7f
parent 23 98ccebc37403
child 83 26b2b12093af
equal deleted inserted replaced
26:dc7c549001d5 35:85266cc22c7f
    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.
    19 
    21 
    20 import sys, os, re
    22 import sys, os, re
    21 
    23 
    22 
    24 
    23 def main():
    25 def main():
    24 
    26 
    25     files = []
    27     root = sys.argv[1]
       
    28     all = len(sys.argv) > 2 and sys.argv[2] == '-all'
       
    29     
    26     
    30     
    27     # Create a reg exp matching to "package x.y.z;" with whitespace ignored
    31     # Create a reg exp matching to "package x.y.z;" with whitespace ignored
    28     regex = re.compile("\\s*package\\s*([\\w.]*);.*", re.IGNORECASE)
    32     regex = re.compile("\\s*package\\s*([\\w.]*);.*", re.IGNORECASE)
    29 
    33 
    30     def visitFun(arg, dirname, names):
    34     def visitFun(arg, dirname, names):
    31 
    35 
    32         # Skip SVN directories
    36         # Skip SVN directories
    33         if dirname.find("\\.svn") != -1:
    37         if dirname.find("\\.svn") != -1:
    34             return names
    38             return
    35             
    39             
       
    40         # Skip tsrc
       
    41         if not all and dirname.find("\\tsrc") != -1:
       
    42             return
       
    43                     
    36         for f in names:
    44         for f in names:
    37             if not f.endswith(".java"):
    45             if not f.endswith(".java"):
    38                 continue
    46                 continue
    39                 
    47                 
    40             try:
    48             try:
    61                 file.close()
    69                 file.close()
    62                                     
    70                                     
    63             except IOError:
    71             except IOError:
    64                 print "Error reading the file " + fname
    72                 print "Error reading the file " + fname
    65                 
    73                 
    66     os.path.walk(sys.argv[1], visitFun, files)
    74     os.path.walk(sys.argv[1], visitFun, None)
    67 
    75 
    68 
    76 
    69 if __name__ == "__main__":
    77 if __name__ == "__main__":
    70     main()
    78     main()