@@ -1062,6 +1062,40 @@ private LicenseInfoParsingResult getLicenseInfoForAttachment(Release release, At
10621062 })).flatMap (Collection ::stream ).collect (Collectors .toList ());
10631063 filterEmptyLicenses (results );
10641064
1065+ // Merge duplicate licenses in licenseInfoResult by combining their sourceFiles
1066+ for (LicenseInfoParsingResult result : results ) {
1067+ if (result .getLicenseInfo () != null && result .getLicenseInfo ().getLicenseNamesWithTexts () != null ) {
1068+ Set <LicenseNameWithText > originalLicenses = result .getLicenseInfo ().getLicenseNamesWithTexts ();
1069+ Map <String , LicenseNameWithText > mergedLicenses = new LinkedHashMap <>();
1070+
1071+ for (LicenseNameWithText license : originalLicenses ) {
1072+ String licenseName = license .getLicenseName ();
1073+ if (mergedLicenses .containsKey (licenseName )) {
1074+ // Merge sourceFiles from duplicate license into the first occurrence
1075+ LicenseNameWithText existing = mergedLicenses .get (licenseName );
1076+ if (existing .getSourceFiles () != null && license .getSourceFiles () != null ) {
1077+ // Extract the newline-separated strings from both sets
1078+ String existingFiles = existing .getSourceFiles ().iterator ().next ();
1079+ String newFiles = license .getSourceFiles ().iterator ().next ();
1080+ // Combine them with newline separator
1081+ String mergedFiles = existingFiles + "\n " + newFiles ;
1082+ // Create new set with the merged string
1083+ Set <String > mergedSet = new HashSet <>();
1084+ mergedSet .add (mergedFiles );
1085+ existing .setSourceFiles (mergedSet );
1086+ } else if (existing .getSourceFiles () == null && license .getSourceFiles () != null ) {
1087+ existing .setSourceFiles (license .getSourceFiles ());
1088+ }
1089+ } else {
1090+ mergedLicenses .put (licenseName , license );
1091+ }
1092+ }
1093+
1094+ // Update the licenseNamesWithTexts with merged data
1095+ result .getLicenseInfo ().setLicenseNamesWithTexts (new HashSet <>(mergedLicenses .values ()));
1096+ }
1097+ }
1098+
10651099 results = assignReleaseToLicenseInfoParsingResults (results , release );
10661100 results = assignComponentToLicenseInfoParsingResults (results , release , user );
10671101 licenseInfoCacheForEvaluation .put (attachment .getAttachmentContentId (), results .get (0 ));
0 commit comments