10
10
RepositoryVerificationResult ,
11
11
RepositoryVerificationStatus ,
12
12
RepoVerifierToolSpecific ,
13
- find_file_in_repo ,
14
13
)
15
14
from macaron .repo_verifier .repo_verifier_maven import RepoVerifierMaven
16
- from macaron .slsa_analyzer .build_tool import Gradle
15
+ from macaron .slsa_analyzer .build_tool . base_build_tool import BaseBuildTool , file_exists
17
16
from macaron .slsa_analyzer .package_registry .maven_central_registry import same_organization
18
17
19
18
logger = logging .getLogger (__name__ )
22
21
class RepoVerifierGradle (RepoVerifierToolSpecific ):
23
22
"""A class to verify whether a repository with Gradle build tool links back to the artifact."""
24
23
25
- specific_tool = Gradle ()
26
-
27
24
def __init__ (
28
25
self ,
29
26
namespace : str ,
30
27
name : str ,
31
28
version : str ,
32
29
reported_repo_url : str ,
33
30
reported_repo_fs : str ,
31
+ build_tool : BaseBuildTool ,
34
32
provenance_repo_url : str | None ,
35
33
):
36
34
"""Initialize a RepoVerifierGradle instance.
@@ -47,17 +45,20 @@ def __init__(
47
45
The URL of the repository reported by the publisher.
48
46
reported_repo_fs : str
49
47
The file system path of the reported repository.
48
+ build_tool : BaseBuildTool
49
+ The build tool used to build the package.
50
50
provenance_repo_url : str | None
51
51
The URL of the repository from a provenance file, or None if it, or the provenance, is not present.
52
52
"""
53
- super ().__init__ (namespace , name , version , reported_repo_url , reported_repo_fs , provenance_repo_url )
53
+ super ().__init__ (namespace , name , version , reported_repo_url , reported_repo_fs , build_tool , provenance_repo_url )
54
54
55
55
self .maven_verifier = RepoVerifierMaven (
56
56
namespace = namespace ,
57
57
name = name ,
58
58
version = version ,
59
59
reported_repo_url = reported_repo_url ,
60
60
reported_repo_fs = reported_repo_fs ,
61
+ build_tool = build_tool ,
61
62
provenance_repo_url = provenance_repo_url ,
62
63
)
63
64
@@ -81,11 +82,11 @@ def verify_by_tool(self) -> RepositoryVerificationResult:
81
82
if recognized_services_verification_result .status == RepositoryVerificationStatus .PASSED :
82
83
return recognized_services_verification_result
83
84
84
- gradle_group_id = self ._extract_group_id_from_properties ()
85
+ gradle_group_id = self .extract_group_id_from_properties ()
85
86
if not gradle_group_id :
86
- gradle_group_id = self ._extract_group_id_from_build_groovy ()
87
+ gradle_group_id = self .extract_group_id_from_build_groovy ()
87
88
if not gradle_group_id :
88
- gradle_group_id = self ._extract_group_id_from_build_kotlin ()
89
+ gradle_group_id = self .extract_group_id_from_build_kotlin ()
89
90
if not gradle_group_id :
90
91
logger .debug ("Could not find group from gradle manifests for %s" , self .reported_repo_url )
91
92
return RepositoryVerificationResult (
@@ -149,17 +150,37 @@ def _extract_group_id_from_gradle_manifest(
149
150
150
151
return None
151
152
152
- def _extract_group_id_from_properties (self ) -> str | None :
153
- """Extract the group id from the gradle.properties file."""
154
- gradle_properties = find_file_in_repo (Path (self .reported_repo_fs ), "gradle.properties" )
153
+ def extract_group_id_from_properties (self ) -> str | None :
154
+ """Extract the group id from the gradle.properties file.
155
+
156
+ Returns
157
+ -------
158
+ str | None
159
+ The extracted group id if found, otherwise None.
160
+ """
161
+ gradle_properties = file_exists (
162
+ self .reported_repo_fs , "gradle.properties" , filters = self .build_tool .path_filters
163
+ )
155
164
return self ._extract_group_id_from_gradle_manifest (gradle_properties )
156
165
157
- def _extract_group_id_from_build_groovy (self ) -> str | None :
158
- """Extract the group id from the build.gradle file."""
159
- build_gradle = find_file_in_repo (Path (self .reported_repo_fs ), "build.gradle" )
160
- return self ._extract_group_id_from_gradle_manifest (build_gradle , quote_chars = {"'" , '"' }, delimiter = " " )
166
+ def extract_group_id_from_build_groovy (self ) -> str | None :
167
+ """Extract the group id from the build.gradle file.
161
168
162
- def _extract_group_id_from_build_kotlin (self ) -> str | None :
163
- """Extract the group id from the build.gradle.kts file."""
164
- build_gradle = find_file_in_repo (Path (self .reported_repo_fs ), "build.gradle.kts" )
169
+ Returns
170
+ -------
171
+ str | None
172
+ The extracted group id if found, otherwise None.
173
+ """
174
+ build_gradle = file_exists (self .reported_repo_fs , "build.gradle" , filters = self .build_tool .path_filters )
175
+ return self ._extract_group_id_from_gradle_manifest (build_gradle , quote_chars = {"'" , '"' }, delimiter = "=" )
176
+
177
+ def extract_group_id_from_build_kotlin (self ) -> str | None :
178
+ """Extract the group id from the build.gradle.kts file.
179
+
180
+ Returns
181
+ -------
182
+ str | None
183
+ The extracted group id if found, otherwise None.
184
+ """
185
+ build_gradle = file_exists (self .reported_repo_fs , "build.gradle.kts" , filters = self .build_tool .path_filters )
165
186
return self ._extract_group_id_from_gradle_manifest (build_gradle , quote_chars = {'"' }, delimiter = "=" )
0 commit comments