Mercurial > hg > truffle
comparison mxtool/mx.py @ 5762:b30cced39597
generalized functionality for finding classes based on searching for patterns in source code and moved it from commands.py to mx.py
used above functionality to find classes manually excluded from JaCoCo processing
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 04 Jul 2012 21:56:48 +0200 |
parents | dfcb73ac6ba2 |
children | 613a3ddb9a71 |
comparison
equal
deleted
inserted
replaced
5761:856a54bae703 | 5762:b30cced39597 |
---|---|
258 return join(self.dir, 'jasmin_classes') | 258 return join(self.dir, 'jasmin_classes') |
259 | 259 |
260 def append_to_classpath(self, cp, resolve): | 260 def append_to_classpath(self, cp, resolve): |
261 if not self.native: | 261 if not self.native: |
262 cp.append(self.output_dir()) | 262 cp.append(self.output_dir()) |
263 | |
264 def find_classes_with_matching_source_line(self, pkgRoot, function, includeInnerClasses=False): | |
265 """ | |
266 Scan the sources of this project for Java source files containing a line for which | |
267 'function' returns true. The fully qualified class name of each existing class | |
268 corresponding to a matched source file is returned in a list. | |
269 """ | |
270 classes = [] | |
271 pkgDecl = re.compile(r"^package\s+([a-zA-Z_][\w\.]*)\s*;$") | |
272 for srcDir in self.source_dirs(): | |
273 outputDir = self.output_dir() | |
274 for root, _, files in os.walk(srcDir): | |
275 for name in files: | |
276 if name.endswith('.java') and name != 'package-info.java': | |
277 matchFound = False | |
278 with open(join(root, name)) as f: | |
279 pkg = None | |
280 for line in f: | |
281 if line.startswith("package "): | |
282 match = pkgDecl.match(line) | |
283 if match: | |
284 pkg = match.group(1) | |
285 if function(line.strip()): | |
286 matchFound = True | |
287 if pkg and matchFound: | |
288 break | |
289 | |
290 if matchFound: | |
291 basename = name[:-len('.java')] | |
292 assert pkg is not None | |
293 if pkgRoot is None or pkg.startswith(pkgRoot): | |
294 pkgOutputDir = join(outputDir, pkg.replace('.', os.path.sep)) | |
295 for e in os.listdir(pkgOutputDir): | |
296 if includeInnerClasses: | |
297 if e.endswith('.class') and (e.startswith(basename) or e.startswith(basename + '$')): | |
298 classes.append(pkg + '.' + e[:-len('.class')]) | |
299 elif e == basename + '.class': | |
300 classes.append(pkg + '.' + basename) | |
301 return classes | |
302 | |
263 | 303 |
264 class Library(Dependency): | 304 class Library(Dependency): |
265 def __init__(self, suite, name, path, mustExist, urls): | 305 def __init__(self, suite, name, path, mustExist, urls): |
266 Dependency.__init__(self, suite, name) | 306 Dependency.__init__(self, suite, name) |
267 self.path = path.replace('/', os.sep) | 307 self.path = path.replace('/', os.sep) |