Skip to content

Commit 60ede2b

Browse files
authored
Fix the gradle direct/transitive issue (#106)
Signed-off-by: Jiyeong Seok <[email protected]>
1 parent bce6552 commit 60ede2b

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/fosslight_dependency/_package_manager.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
_license_scanner_macos = os.path.join('third_party', 'askalono', 'askalono_macos')
2828
_license_scanner_windows = os.path.join('third_party', 'askalono', 'askalono.exe')
2929

30+
gradle_config = ['runtimeClasspath', 'runtime']
31+
android_config = ['releaseRuntimeClasspath']
32+
3033

3134
class PackageManager:
3235
input_package_list_file = []
@@ -104,9 +107,8 @@ def run_gradle_task(self):
104107

105108
def add_allDeps_in_gradle(self):
106109
ret = False
107-
configuration = 'project.configurations.runtimeClasspath, project.configurations.runtime'
108-
if self.package_manager_name == 'android':
109-
configuration = 'project.configurations.releaseRuntimeClasspath'
110+
config = android_config if self.package_manager_name == 'android' else gradle_config
111+
configuration = ','.join([f'project.configurations.{c}' for c in config])
110112

111113
allDeps = f'''allprojects {{
112114
task allDeps(type: DependencyReportTask) {{
@@ -140,15 +142,24 @@ def exeucte_gradle_task(self, dependency_tree_fname):
140142
return ret
141143

142144
def parse_dependency_tree(self, f_name):
145+
config = android_config if self.package_manager_name == 'android' else gradle_config
143146
with open(f_name, 'r', encoding='utf8') as input_fp:
147+
packages_in_config = False
144148
for i, line in enumerate(input_fp.readlines()):
145149
try:
146150
line_bk = copy.deepcopy(line)
147-
re_result = re.findall(r'\-\-\-\s([^\:\s]+\:[^\:\s]+)\:([^\:\s]+)', line)
148-
if re_result:
149-
self.total_dep_list.append(re_result[0][0])
150-
if re.match(r'^[\+|\\]\-\-\-\s([^\:\s]+\:[^\:\s]+)\:([^\:\s]+)', line_bk):
151-
self.direct_dep_list.append(re_result[0][0])
151+
if not packages_in_config:
152+
filtered = next(filter(lambda c: re.findall(rf'^{c}\s\-', line), config), None)
153+
if filtered:
154+
packages_in_config = True
155+
else:
156+
if line == '':
157+
packages_in_config = False
158+
re_result = re.findall(r'\-\-\-\s([^\:\s]+\:[^\:\s]+)\:([^\:\s]+)', line)
159+
if re_result:
160+
self.total_dep_list.append(re_result[0][0])
161+
if re.match(r'^[\+|\\]\-\-\-\s([^\:\s]+\:[^\:\s]+)\:([^\:\s]+)', line_bk):
162+
self.direct_dep_list.append(re_result[0][0])
152163
except Exception as e:
153164
logger.error(f"Failed to parse dependency tree: {e}")
154165

0 commit comments

Comments
 (0)