3333 META_FILE_FAILED , MAVEN_METADATA_TEMPLATE ,
3434 ARCHETYPE_CATALOG_TEMPLATE , ARCHETYPE_CATALOG_FILENAME ,
3535 PACKAGE_TYPE_MAVEN )
36- from typing import Dict , List , Tuple
36+ from typing import Dict , List , Tuple , Union
3737from jinja2 import Template
3838from datetime import datetime
3939from zipfile import ZipFile , BadZipFile
@@ -218,7 +218,8 @@ def parse_gavs(pom_paths: List[str], root="/") -> Dict[str, Dict[str, List[str]]
218218 return gavs
219219
220220
221- def gen_meta_file (group_id , artifact_id : str , versions : list , root = "/" , digest = True ) -> List [str ]:
221+ def gen_meta_file (group_id , artifact_id : str ,
222+ versions : list , root = "/" , do_digest = True ) -> List [str ]:
222223 content = MavenMetadata (
223224 group_id , artifact_id , versions
224225 ).generate_meta_file_content ()
@@ -230,7 +231,7 @@ def gen_meta_file(group_id, artifact_id: str, versions: list, root="/", digest=T
230231 meta_files .append (final_meta_path )
231232 except FileNotFoundError as e :
232233 raise e
233- if digest :
234+ if do_digest :
234235 meta_files .extend (__gen_all_digest_files (final_meta_path ))
235236 return meta_files
236237
@@ -811,7 +812,7 @@ def _merge_directories_with_rename(src_dir: str, dest_dir: str, root: str):
811812 _handle_archetype_catalog_merge (src_file , dest_file )
812813 merged_count += 1
813814 logger .debug ("Merged archetype catalog: %s -> %s" , src_file , dest_file )
814- if os .path .exists (dest_file ):
815+ elif os .path .exists (dest_file ):
815816 duplicated_count += 1
816817 logger .debug ("Duplicated: %s, skipped" , dest_file )
817818 else :
@@ -1332,8 +1333,8 @@ def __wildcard_metadata_paths(paths: List[str]) -> List[str]:
13321333 new_paths .append (path [:- len (".xml" )] + ".*" )
13331334 elif path .endswith (".md5" )\
13341335 or path .endswith (".sha1" )\
1335- or path .endswith (".sha128 " )\
1336- or path .endswith (".sha256 " ):
1336+ or path .endswith (".sha256 " )\
1337+ or path .endswith (".sha512 " ):
13371338 continue
13381339 else :
13391340 new_paths .append (path )
@@ -1342,7 +1343,7 @@ def __wildcard_metadata_paths(paths: List[str]) -> List[str]:
13421343
13431344class VersionCompareKey :
13441345 'Used as key function for version sorting'
1345- def __init__ (self , obj ):
1346+ def __init__ (self , obj : str ):
13461347 self .obj = obj
13471348
13481349 def __lt__ (self , other ):
@@ -1373,36 +1374,61 @@ def __compare(self, other) -> int:
13731374 big = max (len (xitems ), len (yitems ))
13741375 for i in range (big ):
13751376 try :
1376- xitem = xitems [i ]
1377+ xitem : Union [ str , int ] = xitems [i ]
13771378 except IndexError :
13781379 return - 1
13791380 try :
1380- yitem = yitems [i ]
1381+ yitem : Union [ str , int ] = yitems [i ]
13811382 except IndexError :
13821383 return 1
1383- if xitem .isnumeric () and yitem .isnumeric ():
1384+ if (isinstance (xitem , str ) and isinstance (yitem , str ) and
1385+ xitem .isnumeric () and yitem .isnumeric ()):
13841386 xitem = int (xitem )
13851387 yitem = int (yitem )
1386- elif xitem .isnumeric () and not yitem .isnumeric ():
1388+ elif (isinstance (xitem , str ) and xitem .isnumeric () and
1389+ (not isinstance (yitem , str ) or not yitem .isnumeric ())):
13871390 return 1
1388- elif not xitem .isnumeric () and yitem .isnumeric ():
1389- return - 1
1390- if xitem > yitem :
1391- return 1
1392- elif xitem < yitem :
1391+ elif (isinstance (yitem , str ) and yitem .isnumeric () and
1392+ (not isinstance (xitem , str ) or not xitem .isnumeric ())):
13931393 return - 1
1394+ # At this point, both are the same type (both int or both str)
1395+ if isinstance (xitem , int ) and isinstance (yitem , int ):
1396+ if xitem > yitem :
1397+ return 1
1398+ elif xitem < yitem :
1399+ return - 1
1400+ elif isinstance (xitem , str ) and isinstance (yitem , str ):
1401+ if xitem > yitem :
1402+ return 1
1403+ elif xitem < yitem :
1404+ return - 1
13941405 else :
13951406 continue
13961407 return 0
13971408
13981409
1399- class ArchetypeCompareKey (VersionCompareKey ):
1400- 'Used as key function for GAV sorting'
1401- def __init__ (self , gav ):
1402- super ().__init__ (gav .version )
1410+ class ArchetypeCompareKey :
1411+ def __init__ (self , gav : ArchetypeRef ):
14031412 self .gav = gav
14041413
1405- # pylint: disable=unused-private-member
1414+ def __lt__ (self , other ):
1415+ return self .__compare (other ) < 0
1416+
1417+ def __gt__ (self , other ):
1418+ return self .__compare (other ) > 0
1419+
1420+ def __le__ (self , other ):
1421+ return self .__compare (other ) <= 0
1422+
1423+ def __ge__ (self , other ):
1424+ return self .__compare (other ) >= 0
1425+
1426+ def __eq__ (self , other ):
1427+ return self .__compare (other ) == 0
1428+
1429+ def __hash__ (self ):
1430+ return self .gav .__hash__ ()
1431+
14061432 def __compare (self , other ) -> int :
14071433 x = self .gav .group_id + ":" + self .gav .artifact_id
14081434 y = other .gav .group_id + ":" + other .gav .artifact_id
0 commit comments