Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: tools/checkdeps/java_checker.py

Issue 10805042: Implement ability to specify temporarily-allowed dependencies in DEPS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to LKGR. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/checkdeps/cpp_checker.py ('k') | tools/checkdeps/rules.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 from rules import Rule
12
11 13
12 class JavaChecker(object): 14 class JavaChecker(object):
13 """Import checker for Java files. 15 """Import checker for Java files.
14 16
15 The CheckFile method uses real filesystem paths, but Java imports work in 17 The CheckFile method uses real filesystem paths, but Java imports work in
16 terms of package names. To deal with this, we have an extra "prescan" pass 18 terms of package names. To deal with this, we have an extra "prescan" pass
17 that reads all the .java files and builds a mapping of class name -> filepath. 19 that reads all the .java files and builds a mapping of class name -> filepath.
18 In CheckFile, we convert each import statement into a real filepath, and check 20 In CheckFile, we convert each import statement into a real filepath, and check
19 that against the rules in the DEPS files. 21 that against the rules in the DEPS files.
20 22
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 for clazz in re.findall('^import\s+(?:static\s+)?([\w\.]+)\s*;', line): 89 for clazz in re.findall('^import\s+(?:static\s+)?([\w\.]+)\s*;', line):
88 if clazz not in self._classmap: 90 if clazz not in self._classmap:
89 # Importing a class from outside the Chromium tree. That's fine -- 91 # Importing a class from outside the Chromium tree. That's fine --
90 # it's probably a Java or Android system class. 92 # it's probably a Java or Android system class.
91 continue 93 continue
92 include_path = os.path.relpath( 94 include_path = os.path.relpath(
93 self._classmap[clazz], self._base_directory) 95 self._classmap[clazz], self._base_directory)
94 # Convert Windows paths to Unix style, as used in DEPS files. 96 # Convert Windows paths to Unix style, as used in DEPS files.
95 include_path = include_path.replace(os.path.sep, '/') 97 include_path = include_path.replace(os.path.sep, '/')
96 (allowed, why_failed) = rules.DirAllowed(include_path) 98 (allowed, why_failed) = rules.DirAllowed(include_path)
97 if not allowed: 99 if allowed == Rule.DISALLOW:
98 if self._verbose: 100 if self._verbose:
99 result += '\nFor %s' % rules 101 result += '\nFor %s' % rules
100 result += 'Illegal include: "%s"\n Because of %s\n' % ( 102 result += 'Illegal include: "%s"\n Because of %s\n' % (
101 include_path, why_failed) 103 include_path, why_failed)
102 if '{' in line: 104 if '{' in line:
103 # This is code, so we're finished reading imports for this file. 105 # This is code, so we're finished reading imports for this file.
104 break 106 break
105 107
106 return result 108 return result
OLDNEW
« no previous file with comments | « tools/checkdeps/cpp_checker.py ('k') | tools/checkdeps/rules.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698