use of com.google.common.collect.MapDifference.ValueDifference in project sonarqube by SonarSource.
the class CompareAction method writeDifferences.
private void writeDifferences(JsonWriter json, Map<RuleKey, ActiveRuleDiff> modified, Map<RuleKey, RuleDto> rulesByKey, Map<String, RuleRepositoryDto> repositoriesByKey) {
json.beginArray();
for (Entry<RuleKey, ActiveRuleDiff> diffEntry : modified.entrySet()) {
RuleKey key = diffEntry.getKey();
ActiveRuleDiff value = diffEntry.getValue();
json.beginObject();
RuleDto rule = rulesByKey.get(key);
writeRule(json, rule, repositoriesByKey.get(rule.getRepositoryKey()));
json.name(ATTRIBUTE_LEFT).beginObject();
json.prop(ATTRIBUTE_SEVERITY, value.leftSeverity());
json.name(ATTRIBUTE_PARAMS).beginObject();
for (Entry<String, ValueDifference<String>> valueDiff : value.paramDifference().entriesDiffering().entrySet()) {
json.prop(valueDiff.getKey(), valueDiff.getValue().leftValue());
}
for (Entry<String, String> valueDiff : value.paramDifference().entriesOnlyOnLeft().entrySet()) {
json.prop(valueDiff.getKey(), valueDiff.getValue());
}
// params
json.endObject();
// left
json.endObject();
json.name(ATTRIBUTE_RIGHT).beginObject();
json.prop(ATTRIBUTE_SEVERITY, value.rightSeverity());
json.name(ATTRIBUTE_PARAMS).beginObject();
for (Entry<String, ValueDifference<String>> valueDiff : value.paramDifference().entriesDiffering().entrySet()) {
json.prop(valueDiff.getKey(), valueDiff.getValue().rightValue());
}
for (Entry<String, String> valueDiff : value.paramDifference().entriesOnlyOnRight().entrySet()) {
json.prop(valueDiff.getKey(), valueDiff.getValue());
}
// params
json.endObject();
// right
json.endObject();
// rule
json.endObject();
}
json.endArray();
}
use of com.google.common.collect.MapDifference.ValueDifference in project GeoGig by boundlessgeo.
the class TreeDifference method findChanges.
/**
* Finds child refs that are named the same, point to different trees, but are not pure metadata
* changes
*
* @return a sorted map of old/new references to a trees that have changed, deepest paths first
*/
public SortedMap<NodeRef, NodeRef> findChanges() {
SortedMap<String, MutableTree> leftEntries = leftTree.getChildrenAsMap();
SortedMap<String, MutableTree> rightEntries = rightTree.getChildrenAsMap();
final Map<NodeRef, NodeRef> pureMetadataChanges = findPureMetadataChanges();
SortedMapDifference<String, MutableTree> difference;
difference = difference(leftEntries, rightEntries);
SortedMap<String, ValueDifference<MutableTree>> entriesDiffering;
entriesDiffering = difference.entriesDiffering();
SortedMap<NodeRef, NodeRef> matches = Maps.newTreeMap(MutableTree.DEEPEST_FIRST_COMPARATOR);
for (Map.Entry<String, ValueDifference<MutableTree>> e : entriesDiffering.entrySet()) {
String nodePath = e.getKey();
String parentPath = NodeRef.parentPath(nodePath);
ValueDifference<MutableTree> vd = e.getValue();
MutableTree left = vd.leftValue();
MutableTree right = vd.rightValue();
NodeRef lref = new NodeRef(left.getNode(), parentPath, ObjectId.NULL);
NodeRef rref = new NodeRef(right.getNode(), parentPath, ObjectId.NULL);
if (!pureMetadataChanges.containsKey(lref)) {
matches.put(lref, rref);
}
}
return matches;
}
use of com.google.common.collect.MapDifference.ValueDifference in project sonarlint-core by SonarSource.
the class GlobalSettingsUpdateChecker method checkForUpdates.
public void checkForUpdates(String serverVersion, DefaultStorageUpdateCheckResult result) {
GlobalProperties serverGlobalProperties = globalPropertiesDownloader.fetchGlobalSettings(serverVersion);
GlobalProperties storageGlobalProperties = storageReader.readGlobalProperties();
MapDifference<String, String> propDiff = Maps.difference(filter(storageGlobalProperties.getPropertiesMap()), filter(serverGlobalProperties.getPropertiesMap()));
if (!propDiff.areEqual()) {
result.appendToChangelog("Global settings updated");
for (Map.Entry<String, String> entry : propDiff.entriesOnlyOnLeft().entrySet()) {
LOG.debug("Property '{}' removed", entry.getKey());
}
for (Map.Entry<String, String> entry : propDiff.entriesOnlyOnRight().entrySet()) {
LOG.debug("Property '{}' added with value '{}'", entry.getKey(), formatValue(entry.getKey(), entry.getValue()));
}
for (Map.Entry<String, ValueDifference<String>> entry : propDiff.entriesDiffering().entrySet()) {
LOG.debug("Value of property '{}' changed from '{}' to '{}'", entry.getKey(), formatLeftDiff(entry.getKey(), entry.getValue().leftValue(), entry.getValue().rightValue()), formatRightDiff(entry.getKey(), entry.getValue().leftValue(), entry.getValue().rightValue()));
}
}
}
use of com.google.common.collect.MapDifference.ValueDifference in project sonarqube by SonarSource.
the class CompareAction method writeDifferences.
private void writeDifferences(JsonWriter json, Map<RuleKey, ActiveRuleDiff> modified, Map<RuleKey, RuleDefinitionDto> rulesByKey, Map<String, RuleRepositoryDto> repositoriesByKey) {
json.beginArray();
for (Entry<RuleKey, ActiveRuleDiff> diffEntry : modified.entrySet()) {
RuleKey key = diffEntry.getKey();
ActiveRuleDiff value = diffEntry.getValue();
json.beginObject();
RuleDefinitionDto rule = rulesByKey.get(key);
writeRule(json, rule, repositoriesByKey.get(rule.getRepositoryKey()));
json.name(ATTRIBUTE_LEFT).beginObject();
json.prop(ATTRIBUTE_SEVERITY, value.leftSeverity());
json.name(ATTRIBUTE_PARAMS).beginObject();
for (Entry<String, ValueDifference<String>> valueDiff : value.paramDifference().entriesDiffering().entrySet()) {
json.prop(valueDiff.getKey(), valueDiff.getValue().leftValue());
}
for (Entry<String, String> valueDiff : value.paramDifference().entriesOnlyOnLeft().entrySet()) {
json.prop(valueDiff.getKey(), valueDiff.getValue());
}
// params
json.endObject();
// left
json.endObject();
json.name(ATTRIBUTE_RIGHT).beginObject();
json.prop(ATTRIBUTE_SEVERITY, value.rightSeverity());
json.name(ATTRIBUTE_PARAMS).beginObject();
for (Entry<String, ValueDifference<String>> valueDiff : value.paramDifference().entriesDiffering().entrySet()) {
json.prop(valueDiff.getKey(), valueDiff.getValue().rightValue());
}
for (Entry<String, String> valueDiff : value.paramDifference().entriesOnlyOnRight().entrySet()) {
json.prop(valueDiff.getKey(), valueDiff.getValue());
}
// params
json.endObject();
// right
json.endObject();
// rule
json.endObject();
}
json.endArray();
}
Aggregations