forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci_check_gradle_dependencies.py
62 lines (52 loc) · 2.28 KB
/
ci_check_gradle_dependencies.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
import logging
import re
from typing import Any
from ci_workflow.ci_check import CiCheckSource
from ci_workflow.ci_target import CiTarget
from git.git_repository import GitRepository
from manifests.input_manifest import InputComponent
from system.properties_file import PropertiesFile
class CiCheckGradleDependencies(CiCheckSource):
def __init__(self, component: InputComponent, git_repo: GitRepository, target: CiTarget, args: Any) -> None:
super().__init__(component, git_repo, target, args)
self.gradle_project = args if args else None
self.dependencies = self.__get_dependencies()
def __get_dependencies(self) -> PropertiesFile:
cmd = " ".join(
filter(
None,
[
f"./gradlew {self.gradle_project or ''}:dependencies",
f"-Dopensearch.version={self.target.opensearch_version}",
f"-Dbuild.snapshot={str(self.target.snapshot).lower()}",
f"-Dbuild.version_qualifier={str(self.target.qualifier)}" if self.target.qualifier else None,
"--configuration compileOnly",
'| grep -e "---"',
]
)
)
lines = self.git_repo.output(cmd)
stack = ["root"]
props = PropertiesFile("")
for line in lines.split("\n"):
# e.g. "| +--- org.opensearch:opensearch-core:1.1.0-SNAPSHOT"
# see job_scheduler_dependencies.txt in tests for an example
match = re.search(r"---\s(.*):([0-9,\w,.-]*)[\s]*", line)
if match:
levels = line.count(" ") + line.count("---")
while levels < len(stack):
del stack[-1]
if levels == len(stack):
stack[-1] = match.group(1).strip()
elif levels > len(stack):
stack.append(match.group(1).strip())
key = "/".join(stack)
value = match.group(2).strip()
logging.debug(f"{key}={value}")
props[key] = value
return props