Skip to content

Commit

Permalink
Fix the issue for go.work (go 1.18 or later) (#199)
Browse files Browse the repository at this point in the history
Signed-off-by: jiyeong.seok <jiyeong.seok@lge.com>
  • Loading branch information
dd-jy authored May 14, 2024
1 parent 4244879 commit a5e4baf
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/fosslight_dependency/package_manager/Go.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from bs4 import BeautifulSoup
import urllib.request
import re
import shutil
import fosslight_util.constant as constant
import fosslight_dependency.constant as const
from fosslight_dependency._package_manager import PackageManager, get_url_to_purl
Expand All @@ -24,6 +25,8 @@ class Go(PackageManager):
is_run_plugin = False
dn_url = 'https://pkg.go.dev/'
tmp_file_name = 'tmp_go_list.json'
go_work = 'go.work'
tmp_go_work = 'go.work.tmp'

def __init__(self, input_dir, output_dir):
super().__init__(self.package_manager_name, self.dn_url, input_dir, output_dir)
Expand All @@ -33,6 +36,8 @@ def __init__(self, input_dir, output_dir):
def __del__(self):
if os.path.isfile(self.tmp_file_name):
os.remove(self.tmp_file_name)
if os.path.isfile(self.tmp_go_work):
shutil.move(self.tmp_go_work, self.go_work)

def parse_dependency_tree(self, go_deptree_txt):
for line in go_deptree_txt.split('\n'):
Expand All @@ -49,6 +54,9 @@ def parse_dependency_tree(self, go_deptree_txt):
def run_plugin(self):
ret = True

if os.path.isfile(self.go_work):
shutil.move(self.go_work, self.tmp_go_work)

logger.info("Execute 'go list -m -mod=mod -json all' to obtain package info.")
cmd = f"go list -m -mod=mod -json all > {self.tmp_file_name}"

Expand All @@ -64,6 +72,8 @@ def run_plugin(self):
if ret_cmd_tree != 0:
self.parse_dependency_tree(ret_cmd_tree)

if os.path.isfile(self.tmp_go_work):
shutil.move(self.tmp_go_work, self.go_work)
return ret

def parse_oss_information(self, f_name):
Expand Down

0 comments on commit a5e4baf

Please sign in to comment.