build/buildutils/checkcopyrights.py
branchRCL_3
changeset 23 e5618cc85d74
parent 18 9ac0a0a7da70
equal deleted inserted replaced
21:4376525cdefb 23:e5618cc85d74
    11 # Nokia Corporation - initial contribution.
    11 # Nokia Corporation - initial contribution.
    12 #
    12 #
    13 # Contributors:
    13 # Contributors:
    14 #
    14 #
    15 # Description:
    15 # Description:
    16 #   Checks that all the source files have a proper copyright header. 
    16 #   Checks that all the source files have a proper EPL copyright header.
    17 #   Ignores number of known 3rd party source files and directories.
    17 #   Ignores number of known 3rd party source files and directories.
    18 #
    18 #
    19 #    Run this script on a clean workarea in order to avoid warnings
    19 #   Run this script on a clean workarea in order to avoid warnings
    20 #    about exported files and qmake generated files.
    20 #   about exported files and qmake generated files.
    21 #
    21 #
    22 #    The excluded directories should be checked every now and then
    22 #   The excluded directories should be checked every now and then
    23 #    so that there won't be other problems (like files without any
    23 #   so that there won't be other problems (like files without any header).
    24 #    header).
       
    25 
    24 
    26 import sys, os, re
    25 import sys, os, re
    27 
    26 
    28 # Specify here the file types to be checked
    27 # Specify here the file types to be checked
    29 checkedFileTypes = [".cpp", ".h", ".java", ".py", ".mk"]
    28 checkedFileTypes = [".cpp", ".h", ".java", ".py", ".mk"]
    30 
    29 
    31 # Include here the directories to be ignored
       
    32 ignoredDirectories = [
       
    33     "javaextensions\\bluetooth\\bluecove",  # Bluecove
       
    34     "javacommons\\jvms\\j9\\s60\\inc",      # IBM J9
       
    35     "javauis\\eswt_akn",                    # eSWT checked separately
       
    36     "javauis\\eswt_qt",                     # eSWT checked separately
       
    37     "javauis\\tsrc\\fute\\eswt\\",          # eSWT checked separately
       
    38     "javaextensions\\webservices",          # Webservices not delivered
       
    39     "jrt\\tools",                           # Tools not delivered
       
    40     "\\internal"                            # Internal directories not delivered
       
    41     ]
       
    42 
    30 
    43 # Include here any individual files to be ignored
    31 # The copyright texts to be searched for
    44 ignoredFiles = [
    32 copyrightText1 = "Nokia Corporation and/or its subsidiary(-ies)"
    45     "javacommons\\jvms\\cldc_1.1.1\\javasrc\\java\\util\\Timer.java",       # Apache license
    33 copyrightText2 = "Eclipse Public License v1.0"
    46     "javacommons\\jvms\\cldc_1.1.1\\javasrc\\java\\util\\TimerTask.java",   # Apache license
       
    47     "javacommons\\jvms\\cldc_1.1.1\\tsrc\\javasrc\\com\\nokia\\mj\\test\\java\\util\\TimerTaskTest.java",   # Apache license
       
    48     "javacommons\\jvms\\cldc_1.1.1\\tsrc\\javasrc\\com\\nokia\\mj\\test\\java\\util\\TimerTest.java",       # Apache license
       
    49     "javacommons\\utils\\inc\\convertutf.h",                                # Unicode Inc.
       
    50     "javacommons\\utils\\src\\convertutf.cpp"                               # Unicode Inc.
       
    51 ]
       
    52 
       
    53 # The copyright text to be checked
       
    54 copyrightText = "Nokia Corporation and/or its subsidiary(-ies)"
       
    55 
    34 
    56 
    35 
    57 def main():
    36 def main():
       
    37 
       
    38     root = sys.argv[1]
       
    39     if root[-1] != '\\':
       
    40         root = root + '\\'
       
    41 
       
    42     # Include here the directories to be ignored
       
    43     ignoredDirectories = [
       
    44         root + "javaextensions\\bluetooth\\bluecove",  # Bluecove
       
    45         root + "javacommons\\jvms\\j9\\s60\\inc",      # IBM J9
       
    46         root + "javauis\\eswt_akn",                    # eSWT checked separately
       
    47         root + "javauis\\eswt_qt",                     # eSWT checked separately
       
    48         root + "javauis\\tsrc\\fute\\eswt\\",          # eSWT checked separately
       
    49         root + "javaextensions\\webservices",          # Webservices not delivered
       
    50         root + "tools",                                # Tools not delivered
       
    51         "\\internal"                                   # Internal directories not delivered
       
    52         ]
       
    53      
       
    54     # Include here any individual files to be ignored
       
    55     ignoredFiles = [
       
    56         root + "javacommons\\jvms\\cldc_1.1.1\\javasrc\\java\\util\\Timer.java",       # Apache license
       
    57         root + "javacommons\\jvms\\cldc_1.1.1\\javasrc\\java\\util\\TimerTask.java",   # Apache license
       
    58         root + "javacommons\\jvms\\cldc_1.1.1\\tsrc\\javasrc\\com\\nokia\\mj\\test\\java\\util\\TimerTaskTest.java",   # Apache license
       
    59         root + "javacommons\\jvms\\cldc_1.1.1\\tsrc\\javasrc\\com\\nokia\\mj\\test\\java\\util\\TimerTest.java",       # Apache license
       
    60         root + "javacommons\\utils\\inc\\convertutf.h",                                # Unicode Inc.
       
    61         root + "javacommons\\utils\\src\\convertutf.cpp"                               # Unicode Inc.
       
    62     ]
       
    63 
    58     
    64     
    59     def visitFun(arg, dirname, names):
    65     def visitFun(arg, dirname, names):
    60 
    66 
    61         # Skip SVN directories
    67         # Skip SVN directories
    62         if dirname.find("\\.svn") != -1:
    68         if dirname.find("\\.svn") != -1:
    92             lastDot = f.rfind(".")
    98             lastDot = f.rfind(".")
    93             if lastDot == -1 or not f[lastDot:] in checkedFileTypes:
    99             if lastDot == -1 or not f[lastDot:] in checkedFileTypes:
    94                 # print "Ignoring file", f
   100                 # print "Ignoring file", f
    95                 continue
   101                 continue
    96 
   102 
    97             # Check if the file contains the copyright text
   103             # Check if the file contains the copyright texts
    98             try:                       
   104             try:                       
    99                 file = open(fname)
   105                 file = open(fname)
       
   106                 
       
   107                 # Search for the first text
   100                 found = False
   108                 found = False
   101                 line = file.readline()
   109                 line = file.readline()
   102                 while line != "":
   110                 while line != "":
   103                     if copyrightText in line:
   111                     if copyrightText1 in line:
   104                         found = True
   112                         found = True
   105                         break;
   113                         break;
   106                     line = file.readline()                
   114                     line = file.readline()
       
   115                 
       
   116                 # Search the second copyright text as well
       
   117                 if found:
       
   118                     found = False
       
   119                     line = file.readline()
       
   120                     while line != "":
       
   121                         if copyrightText2 in line:
       
   122                             found = True
       
   123                             break;
       
   124                         line = file.readline()
       
   125 
   107                 file.close()
   126                 file.close()
   108                                     
   127                                     
   109             except IOError:
   128             except IOError:
   110                 print "Error reading the file " + fname
   129                 print "Error reading the file " + fname
   111                 
   130                 
   112             if not found:
   131             if not found:
   113                 print fname
   132                 print fname
   114                 continue
   133                 continue
   115                 
   134     
   116     os.path.walk(sys.argv[1], visitFun, None)
   135     os.path.walk(root, visitFun, None)
   117 
   136 
   118 
   137 
   119 if __name__ == "__main__":
   138 if __name__ == "__main__":
   120     main()
   139     main()