Skip to content

Commit

Permalink
Cleanup and give better debug output for exclude patterns in findbugs…
Browse files Browse the repository at this point in the history
… and errorprone (pantsbuild#4408)
  • Loading branch information
cheister authored and lenucksi committed Apr 22, 2017
1 parent 7889d76 commit c933ccd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def prepare(cls, options, round_manager):

@memoized_property
def _exclude_patterns(self):
return "(" + ")|(".join(self.get_options().exclude_patterns) + ")"
return [re.compile(x) for x in set(self.get_options().exclude_patterns or [])]

def _is_errorprone_target(self, target):
if not target.has_sources(self._JAVA_SOURCE_EXTENSION):
Expand All @@ -67,9 +67,11 @@ def _is_errorprone_target(self, target):
if target.is_synthetic:
self.context.log.debug('Skipping [{}] because it is a synthetic target'.format(target.address.spec))
return False
if self.get_options().exclude_patterns and re.match(self._exclude_patterns, target.address.spec):
self.context.log.debug('Skipping [{}] because it matches exclude pattern'.format(target.address.spec))
return False
for pattern in self._exclude_patterns:
if pattern.search(target.address.spec):
self.context.log.debug(
"Skipping [{}] because it matches exclude pattern '{}'".format(target.address.spec, pattern.pattern))
return False
return True

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ def register_options(cls, register):
],
main=cls._FINDBUGS_MAIN,
custom_rules=[
Shader.exclude_package('edu.umd.cs.findbugs',
recursive=True),
Shader.exclude_package('edu.umd.cs.findbugs', recursive=True),
])

@classmethod
Expand All @@ -83,7 +82,7 @@ def cache_target_dirs(self):

@memoized_property
def _exclude_patterns(self):
return "(" + ")|(".join(self.get_options().exclude_patterns) + ")"
return [re.compile(x) for x in set(self.get_options().exclude_patterns or [])]

def _is_findbugs_target(self, target):
if not isinstance(target, (JavaLibrary, JUnitTests)):
Expand All @@ -92,9 +91,11 @@ def _is_findbugs_target(self, target):
if target.is_synthetic:
self.context.log.debug('Skipping [{}] because it is a synthetic target'.format(target.address.spec))
return False
if self.get_options().exclude_patterns and re.match(self._exclude_patterns, target.address.spec):
self.context.log.debug('Skipping [{}] because it matches exclude pattern'.format(target.address.spec))
return False
for pattern in self._exclude_patterns:
if pattern.search(target.address.spec):
self.context.log.debug(
"Skipping [{}] because it matches exclude pattern '{}'".format(target.address.spec, pattern.pattern))
return False
return True

def execute(self):
Expand Down

0 comments on commit c933ccd

Please sign in to comment.