def testAnalyzeScanResults(self):
     # Tests whitelisted vs. current files state logic.
     #
     # Whitelisted - in whitelist, and contains 3rd party code => OK
     # Missing - in whitelist, but doesn't exist
     # Stale - in whitelist, but is clean
     # Unknown - not in whitelist, but contains 3rd party code
     self.input_api.os_path.isfile = lambda x: x != 'Missing'
     self.assertEqual(
       (['Unknown'], ['Missing'], ['Stale']),
       copyright_scanner.AnalyzeScanResults(self.input_api, \
           ['Whitelisted', 'Missing', 'Stale'], ['Whitelisted', 'Unknown']))
Пример #2
0
def _CheckLicenseHeaders(excluded_dirs_list, whitelisted_files):
    """Checks that all files which are not in a listed third-party directory,
  and which do not use the standard Chromium license, are whitelisted.
  Args:
    excluded_dirs_list: The list of directories to exclude from scanning.
    whitelisted_files: The whitelist of files.
  Returns:
    ScanResult.Ok if all files with non-standard license headers are whitelisted
    and the whitelist contains no stale entries;
    ScanResult.Warnings if there are stale entries;
    ScanResult.Errors if new non-whitelisted entries found.
  """
    input_api = InputApi()
    files_to_scan = copyright_scanner.FindFiles(input_api, REPOSITORY_ROOT,
                                                ['.'], excluded_dirs_list)
    sharded_files_to_scan = _ShardList(files_to_scan, 2000)
    pool = multiprocessing.Pool()
    offending_files_chunks = pool.map_async(_FindCopyrightViolations,
                                            sharded_files_to_scan).get(999999)
    pool.close()
    pool.join()
    # Flatten out the result
    offending_files = \
      [item for sublist in offending_files_chunks for item in sublist]

    (unknown, missing,
     stale) = copyright_scanner.AnalyzeScanResults(input_api,
                                                   whitelisted_files,
                                                   offending_files)

    if unknown:
        print 'The following files contain a third-party license but are not in ' \
              'a listed third-party directory and are not whitelisted. You must ' \
              'add the following files to the whitelist.\n%s' % \
              '\n'.join(sorted(unknown))
    if missing:
        print 'The following files are whitelisted, but do not exist.\n%s' % \
            '\n'.join(sorted(missing))
    if stale:
        print 'The following files are whitelisted unnecessarily. You must ' \
              'remove the following files from the whitelist.\n%s' % \
              '\n'.join(sorted(stale))

    if unknown:
        code = ScanResult.Errors
    elif stale or missing:
        code = ScanResult.Warnings
    else:
        code = ScanResult.Ok

    problem_paths = sorted(set(unknown + missing + stale))
    return (code, problem_paths)