@@ -255,6 +255,9 @@ def __init__(self, lang, capitalized_lang, ext, ql_path):
255
255
256
256
processed_packages = set ()
257
257
258
+ all_package_patterns = set (
259
+ (frameworks [fr ]["package" ] for fr in frameworks ))
260
+
258
261
# Write a row for each framework.
259
262
for framework in sorted (frameworks ):
260
263
row = []
@@ -269,12 +272,17 @@ def __init__(self, lang, capitalized_lang, ext, ql_path):
269
272
# Add the package name to the row
270
273
row .append ("``" + frameworks [framework ]["package" ] + "``" )
271
274
272
- prefix = frameworks [framework ]["package" ]
275
+ current_package_pattern = frameworks [framework ]["package" ]
273
276
274
277
# Collect statistics on the current framework
275
- # package name is either full name, such as "org.hibernate", or a prefix, such as "java.*"
278
+ # current_package_pattern is either full name, such as "org.hibernate", or a prefix, such as "java.*"
279
+ # Package patterns might overlap, in case of 'org.apache.commons.io' and 'org.apache.*', the statistics for
280
+ # the latter will not include the statistics for the former.
281
+ def package_match (package_name , pattern ): return (pattern .endswith (
282
+ "*" ) and package_name .startswith (pattern [:- 1 ])) or (not pattern .endswith ("*" ) and pattern == package_name )
283
+
276
284
def collect_framework (): return collect_package_stats (
277
- packages , cwes , lambda p : ( prefix . endswith ( "*" ) and p . startswith ( prefix [: - 1 ]) ) or ( not prefix . endswith ( "*" ) and prefix == p ))
285
+ packages , cwes , lambda p : package_match ( p , current_package_pattern ) and all ( len ( current_package_pattern ) >= len ( pattern ) or not package_match ( p , pattern ) for pattern in all_package_patterns ))
278
286
279
287
row , f_processed_packages = add_package_stats_to_row (
280
288
row , sorted_cwes , collect_framework )
0 commit comments