Skip to content

Commit

Permalink
new vendor list
Browse files Browse the repository at this point in the history
  • Loading branch information
LoRexxar committed Dec 30, 2021
1 parent 2015445 commit 1ad0ed7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
22 changes: 21 additions & 1 deletion core/vendors.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ def __init__(self, task_id, project_id, target, files):
self.ext_list = []
self.exist_file_list = []

# java temp vendor list
self.java_temp_vendor_list = {}

for lan in VENDOR_FILE_DICT:
self.vendor_file_list.extend(VENDOR_FILE_DICT[lan])

Expand Down Expand Up @@ -363,6 +366,19 @@ def check_vendor(self):
for parent in parents:
default_version = parent.getchildren()[2].text

# 匹配通用配置
if pom_ns:
java_base_xpath_reg = ".//{%s}properties" % pom_ns
else:
java_base_xpath_reg = ".//properties"

base_tags = root.findall(java_base_xpath_reg)

if base_tags:
btags = base_tags[0].getchildren()
for btag in btags:
self.java_temp_vendor_list[btag.tag.replace("{%s}" % pom_ns, "")] = btag.text

# 匹配dependency
if pom_ns:
xpath_reg = ".//{%s}dependency" % pom_ns
Expand All @@ -373,7 +389,7 @@ def check_vendor(self):
for child in childs:
group_id = child.getchildren()[0].text
artifact_id = child.getchildren()[1].text
if len(child.getchildren()) > 2:
if len(child.getchildren()) > 2 and "version" in child.getchildren()[2].tag:
version = child.getchildren()[2].text
else:
version = default_version
Expand All @@ -391,6 +407,10 @@ def check_vendor(self):
version = default_version
continue

if varname in self.java_temp_vendor_list:
version = self.java_temp_vendor_list[varname]
continue

if pom_ns:
var_xpath_reg = ".//{%s}%s" % (pom_ns, varname)
else:
Expand Down
23 changes: 12 additions & 11 deletions web/index/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def update_and_new_project_vendor(project_id, name, version, language, source=No
if vendor:
# 兼容性处理,如果source未指定,先更新source进去
if not vendor.source:
vendor.version = version
vendor.source = source
vendor.ext = ext
vendor.version = version
Expand All @@ -109,19 +110,19 @@ def update_and_new_project_vendor(project_id, name, version, language, source=No
else:
vendor = ProjectVendors.objects.filter(project_id=project_id, hash=hash).first()

if vendor:
if vendor.version != version:
logger.debug("[Vendors] Component {} update to version {}".format(name, version))
if vendor:
if vendor.version != version:
logger.debug("[Vendors] Component {} update to version {}".format(name, version))

vendor.version = version
try:
vendor.save()
except IntegrityError:
logger.warn("[Model Save] vendor model not changed")
vendor.version = version
try:
vendor.save()
except IntegrityError:
logger.warn("[Model Save] vendor model not changed")

else:
v = ProjectVendors(project_id=project_id, name=name, version=version, language=language, ext=ext)
v.save()
else:
v = ProjectVendors(project_id=project_id, name=name, version=version, language=language, ext=ext)
v.save()

return True

Expand Down

0 comments on commit 1ad0ed7

Please sign in to comment.