@@ -15,8 +15,13 @@ class Artifact:
1515 name : str
1616 hash : object
1717 component : object
18- module_name : str
19- module_hash : str
18+ module : object
19+
20+ @dataclass
21+ class Module :
22+ name : str
23+ hash : object
24+
2025
2126@dataclass
2227class Hash :
@@ -37,8 +42,12 @@ def main():
3742 "url_prefixes" : [f"{ maven_repo } /{ path } " for maven_repo in maven_repos ],
3843 "path" : path ,
3944 "name" : artifact .name ,
40- "module_name" : artifact .module_name ,
41- "module_hash" : artifact .module_hash ,
45+ "module" : {
46+ "name" : artifact .module .name ,
47+ "hash" : toSri (artifact .module .hash .algo , artifact .module .hash .value ),
48+ "hash_algo" : artifact .module .hash .algo ,
49+ "hash_value" : artifact .module .hash .value ,
50+ } if artifact .module is not None else None ,
4251 "component" : {
4352 "group" : artifact .component .group ,
4453 "name" : artifact .component .name ,
@@ -71,9 +80,8 @@ def parse(xml_file):
7180 name = component_elem .get ("name" )
7281 version = component_elem .get ("version" )
7382 component_obj = Component (group = group , name = name , version = version )
74- module_name = None
75- module_hash = None
7683
84+ component_artifacts = []
7785 for artifact_elem in component_elem .findall ("default:artifact" , namespaces ):
7886 artifact_name = artifact_elem .get ("name" )
7987 hash_obj = None
@@ -83,13 +91,22 @@ def parse(xml_file):
8391 value = elem .get ("value" )
8492 hash_obj = Hash (algo = algo , value = value )
8593
86- artifact_obj = Artifact (name = artifact_name , hash = hash_obj , component = component_obj , module_name = module_name , module_hash = module_hash )
87- artifacts .append (artifact_obj )
88-
89- if artifact_name .endswith (".module" ):
90- module_name = artifact_name
91- module_hash = toSri (hash_obj .algo , hash_obj .value )
92-
94+ artifact_obj = Artifact (name = artifact_name , hash = hash_obj , component = component_obj , module = None )
95+ component_artifacts .append (artifact_obj )
96+
97+ # keep reference to Gradle module metadata if it exist
98+ module_name = f"{ name } -{ version } .module"
99+ module_artifact = next (
100+ (artifact for artifact in component_artifacts if artifact .name == module_name ),
101+ None ,
102+ )
103+ if module_artifact is not None :
104+ module = Module (name = module_artifact .name , hash = module_artifact .hash )
105+ for artifact in component_artifacts :
106+ if artifact is not module_artifact :
107+ artifact .module = module
108+
109+ artifacts .extend (component_artifacts )
93110 return artifacts
94111
95112
0 commit comments