1010 RepositoryVerificationResult ,
1111 RepositoryVerificationStatus ,
1212 RepoVerifierToolSpecific ,
13- find_file_in_repo ,
1413)
1514from 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
1716from macaron .slsa_analyzer .package_registry .maven_central_registry import same_organization
1817
1918logger = logging .getLogger (__name__ )
2221class RepoVerifierGradle (RepoVerifierToolSpecific ):
2322 """A class to verify whether a repository with Gradle build tool links back to the artifact."""
2423
25- specific_tool = Gradle ()
26-
2724 def __init__ (
2825 self ,
2926 namespace : str ,
3027 name : str ,
3128 version : str ,
3229 reported_repo_url : str ,
3330 reported_repo_fs : str ,
31+ build_tool : BaseBuildTool ,
3432 provenance_repo_url : str | None ,
3533 ):
3634 """Initialize a RepoVerifierGradle instance.
@@ -47,17 +45,20 @@ def __init__(
4745 The URL of the repository reported by the publisher.
4846 reported_repo_fs : str
4947 The file system path of the reported repository.
48+ build_tool : BaseBuildTool
49+ The build tool used to build the package.
5050 provenance_repo_url : str | None
5151 The URL of the repository from a provenance file, or None if it, or the provenance, is not present.
5252 """
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 )
5454
5555 self .maven_verifier = RepoVerifierMaven (
5656 namespace = namespace ,
5757 name = name ,
5858 version = version ,
5959 reported_repo_url = reported_repo_url ,
6060 reported_repo_fs = reported_repo_fs ,
61+ build_tool = build_tool ,
6162 provenance_repo_url = provenance_repo_url ,
6263 )
6364
@@ -81,11 +82,11 @@ def verify_by_tool(self) -> RepositoryVerificationResult:
8182 if recognized_services_verification_result .status == RepositoryVerificationStatus .PASSED :
8283 return recognized_services_verification_result
8384
84- gradle_group_id = self ._extract_group_id_from_properties ()
85+ gradle_group_id = self .extract_group_id_from_properties ()
8586 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 ()
8788 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 ()
8990 if not gradle_group_id :
9091 logger .debug ("Could not find group from gradle manifests for %s" , self .reported_repo_url )
9192 return RepositoryVerificationResult (
@@ -149,17 +150,37 @@ def _extract_group_id_from_gradle_manifest(
149150
150151 return None
151152
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+ )
155164 return self ._extract_group_id_from_gradle_manifest (gradle_properties )
156165
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.
161168
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 )
165186 return self ._extract_group_id_from_gradle_manifest (build_gradle , quote_chars = {'"' }, delimiter = "=" )
0 commit comments