Skip to content

Commit b42052a

Browse files
rudra-superrrGMishx
authored andcommitted
fix(Release): listing the source files names for the license in release.
Signed-off-by: Rudra Chopra <[email protected]>
1 parent 900da12 commit b42052a

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/LicenseInfoHandler.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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));

backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/parsers/AbstractCLIParser.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.io.IOException;
4242
import java.io.InputStream;
4343
import java.util.*;
44+
import java.util.stream.Collectors;
4445
import java.util.stream.Stream;
4546
import java.util.stream.StreamSupport;
4647

@@ -161,7 +162,14 @@ protected LicenseNameWithText getLicenseNameWithTextFromLicenseNode(Node node) {
161162
Set<String> files = new HashSet<String>();
162163
String sourceFiles = findNamedSubelement(node, SOURCE_FILES_ELEMENT_NAME).map(AbstractCLIParser::normalizeEscapedXhtml).orElse(null);
163164
if (CommonUtils.isNotNullEmptyOrWhitespace(sourceFiles)) {
164-
files.addAll(Arrays.asList(sourceFiles.split(" ")));
165+
// Parse comma-separated files and join them with newlines, store as single entry
166+
String joinedFiles = Arrays.stream(sourceFiles.split(","))
167+
.map(String::trim)
168+
.filter(s -> !s.isEmpty())
169+
.collect(Collectors.joining("\n"));
170+
if (!joinedFiles.isEmpty()) {
171+
files.add(joinedFiles);
172+
}
165173
}
166174
return new LicenseNameWithText()
167175
.setLicenseText(findNamedSubelement(node, LICENSE_CONTENT_ELEMENT_NAME)

0 commit comments

Comments
 (0)