def handle_file(self, f, settings): """Perform a review of a single file. Args: f (reviewbot.processing.review.File): The file to process. settings (dict): Tool-specific settings. """ file_ext = settings['file_ext'].strip() if file_ext: ext = splitext(f.dest_file)[1][1:] if not ext.lower() in file_ext.split(','): # Ignore the file. return path = f.get_patched_file_path() if not path: return rulesets = settings['rulesets'] if rulesets.startswith('<?xml'): rulesets = make_tempfile(rulesets) outfile = make_tempfile() execute( [ config['pmd_path'], 'pmd', '-d', path, '-R', rulesets, '-f', 'csv', '-r', outfile ], ignore_errors=True) with open(outfile) as result: reader = csv.DictReader(result) for row in reader: try: f.comment(row['Description'], int(row['Line'])) except Exception as e: logging.error('Cannot parse line "%s": %s', row, e)
def handle_file(self, f, settings): """Perform a review of a single file. Args: f (reviewbot.processing.review.File): The file to process. settings (dict): Tool-specific settings. """ if not f.dest_file.lower().endswith('.java'): # Ignore the file. return path = f.get_patched_file_path() if not path: return cfgXml = make_tempfile(settings['config']) outfile = make_tempfile() execute([ 'java', '-jar', config['checkstyle_path'], '-c', cfgXml, '-f', 'xml', '-o', outfile, path, ], ignore_errors=True) try: root = ElementTree.parse(outfile).getroot() for row in root.iter('error'): f.comment(row.get('message'), int(row.get('line'))) except Exception as e: logging.error('Cannot parse xml file: %s', e)
def handle_file(self, f, settings): """Perform a review of a single file. Args: f (reviewbot.processing.review.File): The file to process. settings (dict): Tool-specific settings. """ filename = f.dest_file.lower() if not filename.endswith(('.c', '.cpp', '.cxx', '.m', '.mm')): # Ignore the file. return path = f.get_patched_file_path() if not path: return additional_args = [] configured_args = settings.get('cmdline_args') if configured_args: additional_args = shlex.split(configured_args) outfile = make_tempfile() command = ['clang', '-S', '--analyze'] if filename.endswith('.m'): command.append('-ObjC') elif filename.endswith('.mm'): command.append('-ObjC++') command += additional_args command += [ path, '-Xanalyzer', '-analyzer-output=plist', '-o', outfile ] self.output = execute(command, ignore_errors=True) results = plistlib.readPlist(outfile) for diagnostic in results['diagnostics']: file_index = diagnostic['location']['file'] filename = results['files'][file_index] if filename != f.dest_file: continue line, num_lines = self._find_linenums(diagnostic) f.comment(diagnostic['description'], line, num_lines)
def handle_file(self, f, settings): """Perform a review of a single file. Args: f (reviewbot.processing.review.File): The file to process. settings (dict): Tool-specific settings. """ filename = f.dest_file.lower() if not filename.endswith(('.c', '.cpp', '.cxx', '.m', '.mm')): # Ignore the file. return path = f.get_patched_file_path() if not path: return additional_args = [] configured_args = settings.get('cmdline_args') if configured_args: additional_args = shlex.split(configured_args) outfile = make_tempfile() command = ['clang', '-S', '--analyze'] if filename.endswith('.m'): command.append('-ObjC') elif filename.endswith('.mm'): command.append('-ObjC++') command += additional_args command += [path, '-Xanalyzer', '-analyzer-output=plist', '-o', outfile] self.output = execute(command, ignore_errors=True) results = plistlib.readPlist(outfile) for diagnostic in results['diagnostics']: file_index = diagnostic['location']['file'] filename = results['files'][file_index] if filename != f.dest_file: continue line, num_lines = self._find_linenums(diagnostic) f.comment(diagnostic['description'], line, num_lines)
def handle_file(self, f, settings): """Perform a review of a single file. Args: f (reviewbot.processing.review.File): The file to process. settings (dict): Tool-specific settings. """ if not f.dest_file.lower().endswith('.java'): # Ignore the file. return path = f.get_patched_file_path() if not path: return cfgXml = make_tempfile(settings['config']) outfile = make_tempfile() execute( [ 'java', '-jar', config['checkstyle_path'], '-c', cfgXml, '-f', 'xml', '-o', outfile, path, ], ignore_errors=True) try: root = ElementTree.parse(outfile).getroot() for row in root.iter('error'): f.comment(row.get('message'), int(row.get('line'))) except Exception as e: logging.error('Cannot parse xml file: %s', e)
def get_original_file_path(self): """Fetch the original file and return the filename of it. Returns: unicode: The filename of a new temporary file containing the original file contents. If the file is empty, return None. """ contents = self.original_file_contents if contents: return make_tempfile(contents, self.file_extension) else: return None
def get_patch_file_path(self): """Fetch the patch and return the filename of it. Returns: unicode: The filename of a new temporary file containing the patch contents. If the patch is empty, return None. """ patch_contents = self.patch_contents if patch_contents: return make_tempfile(patch_contents, '.diff') else: return None
def handle_files(self, files, settings): """Perform a review of all files. Args: files (list of reviewbot.processing.review.File): The files to process. settings (dict): Tool-specific settings. """ # Get any extra file extensions we should process. self.file_exts = None if settings['extra_ext_checks']: self.file_exts = tuple(settings['extra_ext_checks'].split(',')) # If any configuration was specified, create a temporary config file. self.config_file = None if settings['config']: self.config_file = make_tempfile(content=settings['config']) super(JSHintTool, self).handle_files(files, settings)
def handle_files(self, files, settings): """Perform a review of all files. Args: files (list of reviewbot.processing.review.File): The files to process. settings (dict): Tool-specific settings. """ # Get any extra file extensions we should process. self.file_exts = None if settings['extra_ext_checks']: self.file_exts = tuple( settings['extra_ext_checks'].split(',')) # If any configuration was specified, create a temporary config file. self.config_file = None if settings['config']: self.config_file = make_tempfile(content=settings['config']) super(JSHintTool, self).handle_files(files, settings)
def get_patched_file_path(self): """Fetch the patched file and return the filename of it. Returns: unicode: The filename of a new temporary file containing the patched file contents. If the file is empty, return None. """ if self.patched_file_path: return self.patched_file_path else: try: contents = self.patched_file_contents except APIError as e: if e.http_status == 404: # This was a deleted file. return None else: raise if contents: return make_tempfile(contents, self.file_extension) else: return None