| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 if d.startswith('.'): | 49 if d.startswith('.'): |
| 50 dirs.remove(d) | 50 dirs.remove(d) |
| 51 # Skip the "out" directory, as dealing with generated files is awkward. | 51 # Skip the "out" directory, as dealing with generated files is awkward. |
| 52 # We don't want paths like "out/Release/lib.java" in our DEPS files. | 52 # We don't want paths like "out/Release/lib.java" in our DEPS files. |
| 53 # TODO(husky): We need some way of determining the "real" path to | 53 # TODO(husky): We need some way of determining the "real" path to |
| 54 # a generated file -- i.e., where it would be in source control if | 54 # a generated file -- i.e., where it would be in source control if |
| 55 # it weren't generated. | 55 # it weren't generated. |
| 56 if d == 'out': | 56 if d == 'out': |
| 57 dirs.remove(d) | 57 dirs.remove(d) |
| 58 # Skip third-party directories. | 58 # Skip third-party directories. |
| 59 if d == 'third_party': | 59 if d in ('third_party', 'ThirdParty'): |
| 60 dirs.remove(d) | 60 dirs.remove(d) |
| 61 for f in files: | 61 for f in files: |
| 62 if f.endswith('.java'): | 62 if f.endswith('.java'): |
| 63 self._PrescanFile(os.path.join(root, f)) | 63 self._PrescanFile(os.path.join(root, f)) |
| 64 | 64 |
| 65 def _PrescanFile(self, filepath): | 65 def _PrescanFile(self, filepath): |
| 66 if self._verbose: | 66 if self._verbose: |
| 67 print 'Prescanning: ' + filepath | 67 print 'Prescanning: ' + filepath |
| 68 with codecs.open(filepath, encoding='utf-8') as f: | 68 with codecs.open(filepath, encoding='utf-8') as f: |
| 69 short_class_name, _ = os.path.splitext(os.path.basename(filepath)) | 69 short_class_name, _ = os.path.splitext(os.path.basename(filepath)) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 98 include_path = include_path.replace(os.path.sep, '/') | 98 include_path = include_path.replace(os.path.sep, '/') |
| 99 rule = rules.RuleApplyingTo(include_path, filepath) | 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 |