Skip to content

Commit

Permalink
fix(licenseinfo): Update merge handling for licenseInfo objects
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Maier <thomas.maier@evosoft.com>
  • Loading branch information
maierthomas committed Jul 16, 2018
1 parent cfd7d72 commit d7c6fec
Showing 1 changed file with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
import java.io.StringWriter;
import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public abstract class OutputGenerator<T> {
protected static final String VELOCITY_TOOLS_FILE = "velocity-tools.xml";
Expand Down Expand Up @@ -119,13 +121,38 @@ protected LicenseInfoParsingResult mergeLicenseInfoParsingResults(LicenseInfoPar
!getComponentLongName(r1).equals(getComponentLongName(r2))){
throw new IllegalArgumentException("Only successful parsing results for the same release can be merged");
}

LicenseInfoParsingResult r = new LicenseInfoParsingResult(r1);
r.getLicenseInfo().getLicenseNamesWithTexts().addAll(r2.getLicenseInfo().getLicenseNamesWithTexts());
r.getLicenseInfo().getCopyrights().addAll(r2.getLicenseInfo().getCopyrights());
r.getLicenseInfo().getFilenames().addAll(r2.getLicenseInfo().getFilenames());

if (r.isSetLicenseInfo()) {
r.getLicenseInfo().setLicenseNamesWithTexts(Stream.concat(
getCollectionStream(r, LicenseInfo::getLicenseNamesWithTexts, Collections::emptySet),
getCollectionStream(r2, LicenseInfo::getLicenseNamesWithTexts, Collections::emptySet))
.collect(Collectors.toSet()));

r.getLicenseInfo().setCopyrights(Stream.concat(
getCollectionStream(r, LicenseInfo::getCopyrights, Collections::emptySet),
getCollectionStream(r2, LicenseInfo::getCopyrights, Collections::emptySet))
.collect(Collectors.toSet()));

r.getLicenseInfo().setFilenames(Stream.concat(
getCollectionStream(r, LicenseInfo::getFilenames, Collections::emptyList),
getCollectionStream(r2, LicenseInfo::getFilenames, Collections::emptyList))
.collect(Collectors.toList()));
} else {
r.setLicenseInfo(r2.getLicenseInfo());
}

return r;
}

private <T extends Collection<U>, U> Stream<U> getCollectionStream(LicenseInfoParsingResult r, Function<LicenseInfo, T> collectionExtractor, Supplier<T> defaultEmpty) {
return Optional.of(r)
.map(LicenseInfoParsingResult::getLicenseInfo)
.map(collectionExtractor)
.orElse(defaultEmpty.get()).stream();
}

@NotNull
protected SortedMap<String, Set<String>> getSortedAcknowledgements(Map<String, LicenseInfoParsingResult> sortedLicenseInfos) {
Map<String, Set<String>> acknowledgements = Maps.filterValues(Maps.transformValues(sortedLicenseInfos, pr -> Optional
Expand Down

0 comments on commit d7c6fec

Please sign in to comment.