def _get_requirements_build_gradle(path: str) -> list: """ Get list of requirements from Maven project. Files supported are build.gradle :param path: Project path """ reqs = [] for file_path in full_paths_in_dir(path): if not file_path.endswith('build.gradle'): continue with open(file_path, encoding='latin-1') as file_fd: file_content = file_fd.read() string = MatchFirst([quotedString('"'), quotedString("'")]) string.setParseAction(lambda x: [x[0][1:-1]]) grammars: list = [ Suppress(Keyword('compile') + Optional('(')) + string.copy()('package'), Suppress(Keyword('compile') + Optional('(')) + Suppress(Keyword('group') + ':') + string.copy()('group') + Suppress(',') + Suppress(Keyword('name') + ':') + string.copy()('name') + Suppress(',') + Suppress(Keyword('version') + ':') + string.copy()('version'), ] for grammar in grammars: for tokens, _, _ in grammar.scanString(file_content): matches = tokens.asDict() if 'package' in matches: if ':' in matches['package']: name, version = matches['package'].rsplit(':', 1) else: name, version = matches['package'], None reqs.append((file_path, name, version)) else: reqs.append( (file_path, f"{matches['group']}:{matches['name']}", matches['version'])) reqs.append( (file_path, matches['group'], matches['version'])) return reqs