comparison mx/commands.py @ 5483:d554a6709d5e

minor improvement to annotation search function
author Doug Simon <doug.simon@oracle.com>
date Thu, 07 Jun 2012 09:47:35 +0200
parents 9f4783c0269e
children e09a1efdeafd
comparison
equal deleted inserted replaced
5482:9f4783c0269e 5483:d554a6709d5e
563 if _jacoco == 'on' or _jacoco == 'append': 563 if _jacoco == 'on' or _jacoco == 'append':
564 jacocoagent = mx.library("JACOCOAGENT", True) 564 jacocoagent = mx.library("JACOCOAGENT", True)
565 # Exclude all compiler tests and snippets 565 # Exclude all compiler tests and snippets
566 excludes = ['com.oracle.graal.compiler.tests.*'] 566 excludes = ['com.oracle.graal.compiler.tests.*']
567 for p in mx.projects(): 567 for p in mx.projects():
568 _add_classes_with_annotation(excludes, p, None, '@Snippet', includeInnerClasses=True) 568 _find_classes_with_annotations(excludes, p, None, ['@Snippet', '@ClassSubstitution'], includeInnerClasses=True)
569 _add_classes_with_annotation(excludes, p, None, '@ClassSubstitution', includeInnerClasses=True)
570 agentOptions = { 569 agentOptions = {
571 'append' : 'true' if _jacoco == 'append' else 'false', 570 'append' : 'true' if _jacoco == 'append' else 'false',
572 'bootclasspath' : 'true', 571 'bootclasspath' : 'true',
573 'includes' : 'com.oracle.*', 572 'includes' : 'com.oracle.*',
574 'excludes' : ':'.join(excludes) 573 'excludes' : ':'.join(excludes)
575 } 574 }
576 args = ['-javaagent:' + jacocoagent.get_path(True) + '=' + ','.join([k + '=' + v for k, v in agentOptions.items()])] + args 575 args = ['-javaagent:' + jacocoagent.get_path(True) + '=' + ','.join([k + '=' + v for k, v in agentOptions.items()])] + args
577 exe = join(_jdk(build), 'bin', mx.exe_suffix('java')) 576 exe = join(_jdk(build), 'bin', mx.exe_suffix('java'))
578 return mx.run([exe, '-' + vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd, timeout=timeout) 577 return mx.run([exe, '-' + vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd, timeout=timeout)
579 578
580 def _add_classes_with_annotation(classes, p, pkgRoot, annotation, includeInnerClasses=False): 579 def _find_classes_with_annotations(classes, p, pkgRoot, annotations, includeInnerClasses=False):
581 """ 580 """
582 Scan the sources of project 'p' for Java source files containing a line starting with 'annotation' 581 Scan the sources of project 'p' for Java source files containing a line starting with 'annotation'
583 (ignoring preceding whitespace) and add the fully qualified class name 582 (ignoring preceding whitespace) and add the fully qualified class name
584 to 'classes' for each Java source file matched. 583 to 'classes' for each Java source file matched.
585 """ 584 """
585 for a in annotations:
586 assert a.startswith('@')
586 pkgDecl = re.compile(r"^package\s+([a-zA-Z_][\w\.]*)\s*;$") 587 pkgDecl = re.compile(r"^package\s+([a-zA-Z_][\w\.]*)\s*;$")
587 for srcDir in p.source_dirs(): 588 for srcDir in p.source_dirs():
588 outputDir = p.output_dir() 589 outputDir = p.output_dir()
589 for root, _, files in os.walk(srcDir): 590 for root, _, files in os.walk(srcDir):
590 for name in files: 591 for name in files:
591 if name.endswith('.java') and name != 'package-info.java': 592 if name.endswith('.java') and name != 'package-info.java':
592 hasTest = False 593 annotationFound = False
593 with open(join(root, name)) as f: 594 with open(join(root, name)) as f:
594 pkg = None 595 pkg = None
595 for line in f: 596 for line in f:
596 if line.startswith("package "): 597 if line.startswith("package "):
597 match = pkgDecl.match(line) 598 match = pkgDecl.match(line)
598 if match: 599 if match:
599 pkg = match.group(1) 600 pkg = match.group(1)
600 else: 601 else:
601 if line.strip().startswith(annotation): 602 stripped = line.strip()
602 hasTest = True 603 for a in annotations:
604 if stripped == a or stripped.startswith(a + '('):
605 annotationFound = True
606 break
607 if annotationFound:
603 break 608 break
604 if hasTest: 609 if annotationFound:
605 basename = name[:-len('.java')] 610 basename = name[:-len('.java')]
606 assert pkg is not None 611 assert pkg is not None
607 if pkgRoot is None or pkg.startswith(pkgRoot): 612 if pkgRoot is None or pkg.startswith(pkgRoot):
608 pkgOutputDir = join(outputDir, pkg.replace('.', os.path.sep)) 613 pkgOutputDir = join(outputDir, pkg.replace('.', os.path.sep))
609 for e in os.listdir(pkgOutputDir): 614 for e in os.listdir(pkgOutputDir):
645 650
646 for proj in _unittests.iterkeys(): 651 for proj in _unittests.iterkeys():
647 p = mx.project(proj) 652 p = mx.project(proj)
648 classes = [] 653 classes = []
649 for pkg in _unittests[proj]: 654 for pkg in _unittests[proj]:
650 _add_classes_with_annotation(classes, p, pkg, '@Test') 655 _find_classes_with_annotations(classes, p, pkg, ['@Test'])
651 656
652 if len(pos) != 0: 657 if len(pos) != 0:
653 classes = [c for c in classes if containsAny(c, pos)] 658 classes = [c for c in classes if containsAny(c, pos)]
654 if len(neg) != 0: 659 if len(neg) != 0:
655 classes = [c for c in classes if not containsAny(c, neg)] 660 classes = [c for c in classes if not containsAny(c, neg)]
675 680
676 for proj in _jtttests.iterkeys(): 681 for proj in _jtttests.iterkeys():
677 p = mx.project(proj) 682 p = mx.project(proj)
678 classes = [] 683 classes = []
679 for pkg in _jtttests[proj]: 684 for pkg in _jtttests[proj]:
680 _add_classes_with_annotation(classes, p, pkg, '@Test') 685 _find_classes_with_annotations(classes, p, pkg, ['@Test'])
681 686
682 if len(pos) != 0: 687 if len(pos) != 0:
683 classes = [c for c in classes if containsAny(c, pos)] 688 classes = [c for c in classes if containsAny(c, pos)]
684 if len(neg) != 0: 689 if len(neg) != 0:
685 classes = [c for c in classes if not containsAny(c, neg)] 690 classes = [c for c in classes if not containsAny(c, neg)]