OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Checks Java files for illegal imports.""" | 5 """Checks Java files for illegal imports.""" |
6 | 6 |
7 import codecs | 7 import codecs |
8 import os | 8 import os |
9 import re | 9 import re |
10 | 10 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 for line in f: | 89 for line in f: |
90 for clazz in re.findall('^import\s+(?:static\s+)?([\w\.]+)\s*;', line): | 90 for clazz in re.findall('^import\s+(?:static\s+)?([\w\.]+)\s*;', line): |
91 if clazz not in self._classmap: | 91 if clazz not in self._classmap: |
92 # Importing a class from outside the Chromium tree. That's fine -- | 92 # Importing a class from outside the Chromium tree. That's fine -- |
93 # it's probably a Java or Android system class. | 93 # it's probably a Java or Android system class. |
94 continue | 94 continue |
95 include_path = os.path.relpath( | 95 include_path = os.path.relpath( |
96 self._classmap[clazz], self._base_directory) | 96 self._classmap[clazz], self._base_directory) |
97 # Convert Windows paths to Unix style, as used in DEPS files. | 97 # Convert Windows paths to Unix style, as used in DEPS files. |
98 include_path = include_path.replace(os.path.sep, '/') | 98 include_path = include_path.replace(os.path.sep, '/') |
99 rule = rules.RuleApplyingTo(include_path) | 99 rule = rules.RuleApplyingTo(include_path, filepath) |
100 if rule.allow == Rule.DISALLOW: | 100 if rule.allow == Rule.DISALLOW: |
101 dependee_status.AddViolation( | 101 dependee_status.AddViolation( |
102 results.DependencyViolation(include_path, rule, rules)) | 102 results.DependencyViolation(include_path, rule, rules)) |
103 if '{' in line: | 103 if '{' in line: |
104 # This is code, so we're finished reading imports for this file. | 104 # This is code, so we're finished reading imports for this file. |
105 break | 105 break |
106 | 106 |
107 return dependee_status | 107 return dependee_status |
OLD | NEW |