// The plugin should at least return an empty set, but check for null too.
if (details == null) {
return null;
}
ResourceContainer container = inventoryManager.getResourceContainer(resourceId);
Set<ResourcePackageDetails> updatedPackageSet = new HashSet<ResourcePackageDetails>(details);
Set<ResourcePackageDetails> existingInstalledPackagesSet = new HashSet<ResourcePackageDetails>(
container.getInstalledPackages());
// Strip out content that have been removed (i.e. not returned on the latest discovery)
int originalPackageCount = existingInstalledPackagesSet.size();
existingInstalledPackagesSet.retainAll(updatedPackageSet);
int removedPackagesCount = originalPackageCount - existingInstalledPackagesSet.size();
if (removedPackagesCount > 0) {
if (LOG.isDebugEnabled()) {
LOG.debug("Removed [" + removedPackagesCount + "] obsolete packages for resource id [" + resourceId
+ "]");
}
}
// Strip from updated list content that are already known for the resource, we don't need to do anything
updatedPackageSet.removeAll(existingInstalledPackagesSet);
// Remaining content in updated list are "new" content
if (!updatedPackageSet.isEmpty()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Found [" + updatedPackageSet.size() + "] new packages for resource id [" + resourceId + "]");
}
}
// Add new content (yes, existingInstalledPackagesSet is same as details, but use the container's reference)
existingInstalledPackagesSet.addAll(updatedPackageSet);
// Add merged (current) list to the resource container
container.setInstalledPackages(existingInstalledPackagesSet);
// Package and send to server
ContentDiscoveryReport report = new ContentDiscoveryReport();
report.addAllDeployedPackages(existingInstalledPackagesSet);
report.setResourceId(resourceId);