Search in sources :

Example 1 with ValueDifference

use of com.google.common.collect.MapDifference.ValueDifference in project sonarlint-core by SonarSource.

the class PluginsUpdateChecker method checkForUpdates.

public void checkForUpdates(DefaultStorageUpdateCheckResult result, List<SonarAnalyzer> pluginList) {
    PluginReferences serverPluginReferences = pluginReferenceDownloader.fetchPlugins(pluginList);
    PluginReferences storagePluginReferences = storageReader.readPluginReferences();
    Map<String, String> serverPluginHashes = serverPluginReferences.getReferenceList().stream().collect(Collectors.toMap(PluginReference::getKey, PluginReference::getHash));
    Map<String, String> storagePluginHashes = storagePluginReferences.getReferenceList().stream().collect(Collectors.toMap(PluginReference::getKey, PluginReference::getHash));
    MapDifference<String, String> pluginDiff = Maps.difference(storagePluginHashes, serverPluginHashes);
    if (!pluginDiff.areEqual()) {
        for (Map.Entry<String, String> entry : pluginDiff.entriesOnlyOnLeft().entrySet()) {
            result.appendToChangelog(String.format("Plugin '%s' removed", entry.getKey()));
        }
        for (Map.Entry<String, String> entry : pluginDiff.entriesOnlyOnRight().entrySet()) {
            result.appendToChangelog("Plugin '" + entry.getKey() + "' added");
        }
        for (Map.Entry<String, ValueDifference<String>> entry : pluginDiff.entriesDiffering().entrySet()) {
            result.appendToChangelog("Plugin '" + entry.getKey() + "' updated");
        }
    }
}
Also used : PluginReferences(org.sonarsource.sonarlint.core.proto.Sonarlint.PluginReferences) ValueDifference(com.google.common.collect.MapDifference.ValueDifference) Map(java.util.Map)

Example 2 with ValueDifference

use of com.google.common.collect.MapDifference.ValueDifference in project sonarlint-core by SonarSource.

the class QualityProfilesUpdateChecker method checkForUpdates.

public void checkForUpdates(DefaultStorageUpdateCheckResult result) {
    QProfiles serverQualityProfiles = qualityProfilesDownloader.fetchQualityProfiles();
    QProfiles storageQProfiles = storageReader.readQProfiles();
    Map<String, QProfile> serverPluginHashes = serverQualityProfiles.getQprofilesByKeyMap();
    Map<String, QProfile> storagePluginHashes = storageQProfiles.getQprofilesByKeyMap();
    MapDifference<String, QProfile> pluginDiff = Maps.difference(storagePluginHashes, serverPluginHashes);
    if (!pluginDiff.areEqual()) {
        for (Map.Entry<String, QProfile> entry : pluginDiff.entriesOnlyOnLeft().entrySet()) {
            result.appendToChangelog(String.format("Quality profile '%s' for language '%s' removed", entry.getValue().getName(), entry.getValue().getLanguageName()));
        }
        for (Map.Entry<String, QProfile> entry : pluginDiff.entriesOnlyOnRight().entrySet()) {
            result.appendToChangelog(String.format("Quality profile '%s' for language '%s' added", entry.getValue().getName(), entry.getValue().getLanguageName()));
        }
        for (Map.Entry<String, ValueDifference<QProfile>> entry : pluginDiff.entriesDiffering().entrySet()) {
            result.appendToChangelog(String.format("Quality profile '%s' for language '%s' updated", entry.getValue().rightValue().getName(), entry.getValue().rightValue().getLanguageName()));
        }
    }
}
Also used : ValueDifference(com.google.common.collect.MapDifference.ValueDifference) Map(java.util.Map) QProfile(org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles.QProfile) QProfiles(org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles)

Example 3 with ValueDifference

use of com.google.common.collect.MapDifference.ValueDifference in project netvirt by opendaylight.

the class TunnelUnderlayNetworkChangeListener method handleTepIpsUpdateEvent.

private void handleTepIpsUpdateEvent(OpenvswitchOtherConfigs origLocalIps, OpenvswitchOtherConfigs updatedLocalIps, String nodeId) {
    Map<String, String> origLocalIpMap = Optional.ofNullable(bridgeMgr.getMultiValueMap(origLocalIps.getOtherConfigValue())).orElse(Collections.emptyMap());
    Map<String, String> updatedLocalIpMap = Optional.ofNullable(bridgeMgr.getMultiValueMap(updatedLocalIps.getOtherConfigValue())).orElse(Collections.emptyMap());
    MapDifference<String, String> mapDiff = Maps.difference(origLocalIpMap, updatedLocalIpMap);
    // Handling only underlay network updates for existing for TEP ips
    // Added and removed TEP ips will be handled by
    // TunnelStateChangeListener
    Map<String, ValueDifference<String>> entriesDiffering = mapDiff.entriesDiffering();
    if (entriesDiffering == null || entriesDiffering.isEmpty()) {
        LOG.trace("No underlay network changes detected for for node {}", nodeId);
        return;
    }
    Optional<BigInteger> dpIdOpt = bridgeMgr.getDpIdFromManagerNodeId(nodeId);
    if (!dpIdOpt.isPresent()) {
        LOG.debug("Failed to get DPN id for node {}", nodeId);
        return;
    }
    BigInteger dpId = dpIdOpt.get();
    for (Entry<String, ValueDifference<String>> entry : entriesDiffering.entrySet()) {
        String srcTepIp = entry.getKey();
        ValueDifference<String> valueDiff = entry.getValue();
        String origUnderlayNetwork = valueDiff.leftValue();
        String updatedUnderlayNetwork = valueDiff.rightValue();
        handleTepIpChangeEvent(dpId, srcTepIp, origUnderlayNetwork, updatedUnderlayNetwork);
    }
}
Also used : ValueDifference(com.google.common.collect.MapDifference.ValueDifference) BigInteger(java.math.BigInteger)

Example 4 with ValueDifference

use of com.google.common.collect.MapDifference.ValueDifference in project n4js by eclipse.

the class AbstractN4JSPreferenceStoreAccessor method populateCompilerConfiguration.

/**
 * @param outputName
 *            the output name that identifies the output configuration but in our case also the registered compiler.
 * @param compilerDescriptor
 *            the compiler descriptor holding the values either stored last time this details page was used or the
 *            default values for the compiler
 */
public void populateCompilerConfiguration(String outputName, T compilerDescriptor) {
    // defaults
    preferenceInitializer.initialize(scopedAccessor);
    boolean initialLoad = false;
    ComponentDescriptor currentlyStoredCompilerDescriptor = compilerDescriptor.getCurrentlyStoredComponentDescriptor();
    if (currentlyStoredCompilerDescriptor == null) {
        // default configuration
        currentlyStoredCompilerDescriptor = compilerDescriptor;
        initialLoad = true;
    }
    Map<String, String> originalSettings = currentlyStoredCompilerDescriptor.fillMap(outputName);
    IPreferenceStore preferenceStore = getPreferenceStore();
    // populate
    // use a copy here has we don't want to change the default values provided by the registered compilers
    @SuppressWarnings("unchecked") T newCompilerDescriptor = (T) compilerDescriptor.copy();
    for (IComponentProperties<T> prop : getComponentPropertiesValues()) {
        if (prop.getType() == Boolean.class) {
            prop.setValueInCompilerDescriptor(newCompilerDescriptor, outputName, preferenceStore.getBoolean(prop.getKey(outputName)));
        } else {
            prop.setValueInCompilerDescriptor(newCompilerDescriptor, outputName, preferenceStore.getString(prop.getKey(outputName)));
        }
    }
    Map<String, String> currentSettings = newCompilerDescriptor.fillMap(outputName);
    Map<String, ValueDifference<String>> changes = getPreferenceChanges(originalSettings, currentSettings);
    if (!initialLoad) {
        compilerDescriptor.setChanges(changes);
    }
    compilerDescriptor.setCurrentlyStoredComponentDescriptor(newCompilerDescriptor);
}
Also used : ComponentDescriptor(org.eclipse.n4js.utils.ComponentDescriptor) ValueDifference(com.google.common.collect.MapDifference.ValueDifference) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 5 with ValueDifference

use of com.google.common.collect.MapDifference.ValueDifference in project n4js by eclipse.

the class AbstractN4JSPreferencePage method getPreferenceChanges.

/**
 * @return a map keyed by the preference store key (e.g. outlet.es5.autobuilding for compiler (resp. output
 *         configuration) with name 'es5' and property 'autobuilding') containing old and new value. Only keys whose
 *         values has been changed are included. This map contains the changes of all registered compilers
 */
public Map<String, ValueDifference<String>> getPreferenceChanges() {
    if (entriesDiffering == null) {
        for (Triple<String, String, DESCR_TYPE> compiler : components) {
            DESCR_TYPE compilerDescriptor = compiler.getThird();
            String outputName = compiler.getFirst();
            boolean initialLoad = false;
            @SuppressWarnings("unchecked") DESCR_TYPE currentlyStoredCompilerDescriptor = (DESCR_TYPE) compilerDescriptor.getCurrentlyStoredComponentDescriptor();
            if (currentlyStoredCompilerDescriptor == null) {
                // default configuration
                currentlyStoredCompilerDescriptor = compilerDescriptor;
                initialLoad = true;
            }
            Map<String, String> originalSettings = currentlyStoredCompilerDescriptor.fillMap(outputName);
            List<IPreferenceStore> preferenceStores = field.getPreferenceStores();
            // populate
            // use a copy here has we don't want to change the default values provided by the registered compilers
            @SuppressWarnings("unchecked") DESCR_TYPE newCompilerDescriptor = (DESCR_TYPE) compilerDescriptor.copy();
            for (IPreferenceStore preferenceStore : preferenceStores) {
                setDescriptorValuesFromPreferences(preferenceStore, outputName, newCompilerDescriptor);
            }
            Map<String, String> currentSettings = newCompilerDescriptor.fillMap(outputName);
            Map<String, ValueDifference<String>> changes = getPreferenceChanges(originalSettings, currentSettings);
            if (!initialLoad) {
                compilerDescriptor.setChanges(changes);
            }
            compilerDescriptor.setCurrentlyStoredComponentDescriptor(newCompilerDescriptor);
        }
        entriesDiffering = new HashMap<>();
        for (Triple<String, String, DESCR_TYPE> compiler : components) {
            entriesDiffering.putAll(compiler.getThird().getChanges());
        }
    }
    return entriesDiffering;
}
Also used : ValueDifference(com.google.common.collect.MapDifference.ValueDifference) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

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