Search in sources :

Example 6 with ValueDifference

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();
}
Also used : ActiveRuleDiff(org.sonar.server.qualityprofile.QProfileComparison.ActiveRuleDiff) RuleKey(org.sonar.api.rule.RuleKey) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) ValueDifference(com.google.common.collect.MapDifference.ValueDifference)

Example 7 with ValueDifference

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;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ValueDifference(com.google.common.collect.MapDifference.ValueDifference) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Map(java.util.Map) SortedMap(java.util.SortedMap) Maps.newTreeMap(com.google.common.collect.Maps.newTreeMap)

Example 8 with ValueDifference

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()));
        }
    }
}
Also used : GlobalProperties(org.sonarsource.sonarlint.core.proto.Sonarlint.GlobalProperties) ValueDifference(com.google.common.collect.MapDifference.ValueDifference) Map(java.util.Map)

Example 9 with ValueDifference

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();
}
Also used : ActiveRuleDiff(org.sonar.server.qualityprofile.QProfileComparison.ActiveRuleDiff) RuleKey(org.sonar.api.rule.RuleKey) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) ValueDifference(com.google.common.collect.MapDifference.ValueDifference)

Aggregations

ValueDifference (com.google.common.collect.MapDifference.ValueDifference)9 Map (java.util.Map)4 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 RuleKey (org.sonar.api.rule.RuleKey)2 ActiveRuleDiff (org.sonar.server.qualityprofile.QProfileComparison.ActiveRuleDiff)2 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 Maps.newTreeMap (com.google.common.collect.Maps.newTreeMap)1 BigInteger (java.math.BigInteger)1 SortedMap (java.util.SortedMap)1 ComponentDescriptor (org.eclipse.n4js.utils.ComponentDescriptor)1 NodeRef (org.locationtech.geogig.api.NodeRef)1 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)1 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)1 RuleDto (org.sonar.db.rule.RuleDto)1 GlobalProperties (org.sonarsource.sonarlint.core.proto.Sonarlint.GlobalProperties)1 PluginReferences (org.sonarsource.sonarlint.core.proto.Sonarlint.PluginReferences)1 QProfiles (org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles)1 QProfile (org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles.QProfile)1