/** * Determines if two property sources are different. */ protected boolean changed(MapPropertySource mp1, MapPropertySource mp2) { if (mp1 == mp2) return false; if (mp1 == null && mp2 != null || mp1 != null && mp2 == null) return true; Map<String, Object> s1 = mp1.getSource(); Map<String, Object> s2 = mp2.getSource(); return s1 == null ? s2 != null : !s1.equals(s2); }
environment.getPropertySources().addFirst(ps); ps.getSource().putAll(convertInlinedPropertiesToMap(inlinedProperties));
private void assertEnumerablePropertySource() { if (getPropertySource() instanceof MapPropertySource) { try { ((MapPropertySource) getPropertySource()).getSource().size(); } catch (UnsupportedOperationException ex) { throw new IllegalArgumentException( "PropertySource must be fully enumerable"); } } }
public static CacheKey get(EnumerablePropertySource<?> source) { if (source instanceof MapPropertySource) { return new CacheKey(((MapPropertySource) source).getSource().keySet()); } return new CacheKey(source.getPropertyNames()); }
/** * Copy from {@link BusEnvironmentPostProcessor#addOrReplace(MutablePropertySources, Map)} * * @param propertySources {@link MutablePropertySources} * @param map Default RocketMQ Bus Properties */ private void addOrReplace(MutablePropertySources propertySources, Map<String, Object> map) { MapPropertySource target = null; if (propertySources.contains(PROPERTY_SOURCE_NAME)) { PropertySource<?> source = propertySources.get(PROPERTY_SOURCE_NAME); if (source instanceof MapPropertySource) { target = (MapPropertySource) source; for (String key : map.keySet()) { if (!target.containsProperty(key)) { target.getSource().put(key, map.get(key)); } } } } if (target == null) { target = new MapPropertySource(PROPERTY_SOURCE_NAME, map); } if (!propertySources.contains(PROPERTY_SOURCE_NAME)) { propertySources.addLast(target); } }
/** * Copy from BusEnvironmentPostProcessor#addOrReplace(MutablePropertySources, Map) * * @param propertySources {@link MutablePropertySources} * @param map Default Dubbo Properties */ private void addOrReplace(MutablePropertySources propertySources, Map<String, Object> map) { MapPropertySource target = null; if (propertySources.contains(PROPERTY_SOURCE_NAME)) { PropertySource<?> source = propertySources.get(PROPERTY_SOURCE_NAME); if (source instanceof MapPropertySource) { target = (MapPropertySource) source; for (String key : map.keySet()) { if (!target.containsProperty(key)) { target.getSource().put(key, map.get(key)); } } } } if (target == null) { target = new MapPropertySource(PROPERTY_SOURCE_NAME, map); } if (!propertySources.contains(PROPERTY_SOURCE_NAME)) { propertySources.addLast(target); } } }
private static void addOrReplace(MutablePropertySources propertySources, Map<String, Object> map) { MapPropertySource target = null; if (propertySources.contains(PROPERTY_SOURCE_NAME)) { PropertySource<?> source = propertySources.get(PROPERTY_SOURCE_NAME); if (source instanceof MapPropertySource) { target = (MapPropertySource) source; for (String key : map.keySet()) { if (!target.containsProperty(key)) { target.getSource().put(key, map.get(key)); } } } } if (target == null) { target = new MapPropertySource(PROPERTY_SOURCE_NAME, map); } if (!propertySources.contains(PROPERTY_SOURCE_NAME)) { propertySources.addLast(target); } }
private void addOrReplace(MutablePropertySources propertySources, Map<String, Object> map) { MapPropertySource target = null; if (propertySources.contains(PROPERTY_SOURCE_NAME)) { PropertySource<?> source = propertySources.get(PROPERTY_SOURCE_NAME); if (source instanceof MapPropertySource) { target = (MapPropertySource) source; for (String key : map.keySet()) { if (!target.containsProperty(key)) { target.getSource().put(key, map.get(key)); } } } } if (target == null) { target = new MapPropertySource(PROPERTY_SOURCE_NAME, map); } if (!propertySources.contains(PROPERTY_SOURCE_NAME)) { propertySources.addLast(target); } }
/** * Determines if two property sources are different. */ protected boolean changed(MapPropertySource mp1, MapPropertySource mp2) { if (mp1 == mp2) return false; if (mp1 == null && mp2 != null || mp1 != null && mp2 == null) return true; Map<String, Object> s1 = mp1.getSource(); Map<String, Object> s2 = mp2.getSource(); return s1 == null ? s2 != null : !s1.equals(s2); }
/** * get All properties */ public Map<String, Object> getAllProperties() { if (properties == null || properties.isEmpty()) { synchronized (SpringEnvironmentProperties.class) { if (properties == null || properties.isEmpty()) { Map<String, Object> map = new HashMap(); for (Iterator it = ((AbstractEnvironment) env).getPropertySources().iterator(); it.hasNext(); ) { PropertySource propertySource = (PropertySource) it.next(); if (propertySource instanceof MapPropertySource) { map.putAll(((MapPropertySource) propertySource).getSource()); } } //decrypt Map<String, Object> decryptedMap = new HashMap(); for (String k : map.keySet()) { decryptedMap.put(k, env.getProperty(k)); } properties = decryptedMap; } } } return properties; }
public EncryptableMapPropertySourceWrapper(MapPropertySource delegate, EncryptablePropertyResolver resolver, EncryptablePropertyFilter filter) { super(delegate.getName(), delegate.getSource()); encryptableDelegate = new CachingDelegateEncryptablePropertySource<>(delegate, resolver, filter); }
private void mergeDefaultProperties(MutablePropertySources environment, MutablePropertySources bootstrap) { String name = DEFAULT_PROPERTIES; if (bootstrap.contains(name)) { PropertySource<?> source = bootstrap.get(name); if (!environment.contains(name)) { environment.addLast(source); } else { PropertySource<?> target = environment.get(name); if (target instanceof MapPropertySource) { Map<String, Object> targetMap = ((MapPropertySource) target) .getSource(); if (target != source) { if (source instanceof MapPropertySource) { Map<String, Object> map = ((MapPropertySource) source) .getSource(); for (String key : map.keySet()) { if (!target.containsProperty(key)) { targetMap.put(key, map.get(key)); } } } } } } } mergeAdditionalPropertySources(environment, bootstrap); }
/** * Determines if two property sources are different. */ protected boolean changed(MapPropertySource mp1, MapPropertySource mp2) { if (mp1 == mp2) return false; if (mp1 == null && mp2 != null || mp1 != null && mp2 == null) return true; Map<String, Object> s1 = mp1.getSource(); Map<String, Object> s2 = mp2.getSource(); return s1 == null ? s2 != null : !s1.equals(s2); }
/** * Determines if two property sources are different. */ protected boolean changed(MapPropertySource mp1, MapPropertySource mp2) { if (mp1 == mp2) return false; if (mp1 == null && mp2 != null || mp1 != null && mp2 == null) return true; Map<String, Object> s1 = mp1.getSource(); Map<String, Object> s2 = mp2.getSource(); return s1 == null ? s2 != null : !s1.equals(s2); }
@Override public Set<DescriptorScope> getDescriptors() { final ImmutableSet.Builder<DescriptorScope> builder = ImmutableSet.builder(); builder.add(new HostNameScopeDescriptor()); for (final PropertySource<?> propertySource : env.getPropertySources()) { if (propertySource instanceof MapPropertySource) { final Map<String, Object> source = ((MapPropertySource) propertySource).getSource(); for (Map.Entry entry : source.entrySet()) { builder.add(new StaticDescriptorScope(entry.getKey().toString(), entry.getValue())); } } } return builder.build(); } }
/** * config log settings */ private void assemblyLogSetting(ConfigurableEnvironment environment) { StreamSupport.stream(environment.getPropertySources().spliterator(), false) .filter(propertySource -> propertySource instanceof EnumerablePropertySource) .map(propertySource -> Arrays .asList(((MapPropertySource) propertySource).getPropertyNames())) .flatMap(Collection::stream).filter(LogEnvUtils::filterAllLogConfig) .forEach((key) -> HIGH_PRIORITY_CONFIG.getSource().put(key, environment.getProperty(key))); }
/** * config required properties * @param environment */ private void assemblyRequireProperties(ConfigurableEnvironment environment) { if (StringUtils.hasText(environment.getProperty(SofaBootInfraConstants.APP_NAME_KEY))) { HIGH_PRIORITY_CONFIG.getSource().put(SofaBootInfraConstants.APP_NAME_KEY, environment.getProperty(SofaBootInfraConstants.APP_NAME_KEY)); } }
public EncryptableMapPropertySourceWrapper(MapPropertySource delegate, EncryptablePropertyResolver resolver, EncryptablePropertyFilter filter) { super(delegate.getName(), delegate.getSource()); encryptableDelegate = new CachingDelegateEncryptablePropertySource<>(delegate, resolver, filter); }
private void registerPort(RunningStubs runStubs) { MutablePropertySources propertySources = this.environment.getPropertySources(); if (!propertySources.contains(STUBRUNNER_PREFIX)) { propertySources.addFirst(new MapPropertySource(STUBRUNNER_PREFIX, new HashMap<String, Object>())); } Map<String, Object> source = ((MapPropertySource) propertySources .get(STUBRUNNER_PREFIX)).getSource(); for (Map.Entry<StubConfiguration, Integer> entry : runStubs.validNamesAndPorts() .entrySet()) { source.put(STUBRUNNER_PREFIX + "." + entry.getKey().getArtifactId() + ".port", entry.getValue()); // there are projects where artifact id is the same, what differs is the group // id source.put(STUBRUNNER_PREFIX + "." + entry.getKey().getGroupId() + "." + entry.getKey().getArtifactId() + ".port", entry.getValue()); } }
private void addDefaultProperty(ConfigurableEnvironment environment, String name, String value) { MutablePropertySources sources = environment.getPropertySources(); Map<String, Object> map = null; if (sources.contains("defaultProperties")) { PropertySource<?> source = sources.get("defaultProperties"); if (source instanceof MapPropertySource) { map = ((MapPropertySource) source).getSource(); } } else { map = new LinkedHashMap<>(); sources.addLast(new MapPropertySource("defaultProperties", map)); } if (map != null) { map.put(name, value); } } }