private PropertyMap readClasspathDefaults() { PropertyMap newProperties = new PropertyMap(); newProperties.readAllPropertiesFileFromClassPath(DEFAULT_PROPERTIES_FILENAME); if (newProperties.getSize() != 0) { newProperties = new PropertyMap(newProperties); } for (String name : PROPERTIES_FILES_NAME) { newProperties.readAllPropertiesFileFromClassPath(name); } return newProperties; }
/** Sets the value for a property registering it by a unknown source.*/ public void add(@Nonnull String key, @Nullable String value) { add(key, value, PropertySource.UNKNOWN); }
/** Verifies if there is a register of value for the key. This register may set a null value to key. */ public boolean containsKey(@Nonnull String key) { return entries.containsKey(key) || (parent != null && parent.containsKey(key)); }
/** * Generates a new map with the equivalent values of this map and it's parent (if the parent exists). The new map * won't have a parent map. */ @Nonnull public PropertyMap consolidateAndFrozen() { PropertyMap map2 = new PropertyMap(); copyEntries(map2.entries); map2.frozen(); return map2; }
/** * Look for all the properties file with the specific name into the classpath and call * {@link #readProperties(URL)}. */ public void readAllPropertiesFileFromClassPath(@Nonnull String resourceName) { List<URL> resources = findResources(resourceName); resources.forEach(url -> readProperties(url)); }
@VisibleForTesting public void setProperty(@Nonnull String key, @Nonnull String value) { if (getProperties().isFrozen()) { propertyMap = new PropertyMap(getProperties()); } propertyMap.add(key, value); }
private PropertyMap readPropertiesFilesOverrides(PropertyMap newProperties) { File confDir = findConfDir(); if (confDir == null) { return newProperties; } PropertyMap props = new PropertyMap(newProperties); for (String name : PROPERTIES_FILES_NAME) { props.readProperties(new File(confDir, name)); } return props; }
public static Object saveState() { SingularPropertiesImpl impl = SingularPropertiesImpl.get(); State state = new State(); state.propertiesBackup = impl.propertyMap; state.systemBackup.put(SYSTEM_PROPERTY_SINGULAR_SERVER_HOME, System.getProperty(SYSTEM_PROPERTY_SINGULAR_SERVER_HOME)); impl.propertyMap = new PropertyMap(impl.getProperties().consolidateAndFrozen()); return state; } }
/** * Prints the content of map of properties to the specific output identifying the source of each property. */ public void debugContent(@Nonnull Appendable out) { Multimap<PropertySource<?>, PropertyEntry> entriesBySource = LinkedHashMultimap.create(); loadEntries(entriesBySource); try { String lineSeparator = System.getProperty("line.separator"); for (PropertySource<?> source : entriesBySource.keySet()) { out.append('#').append(lineSeparator); out.append("#source '").append(source.getDescription()).append("'"); out.append(lineSeparator); debugContent(entriesBySource.get(source), out, lineSeparator); } } catch (IOException e) { throw new SingularPropertyException("Error writing to output", e); } }
/** * Prints the content of map of properties to the system output identifying the source of each property. */ public void debugContent() { debugContent(System.out); }
/** Looks for the property associated to the key in the current map and into the parent map if necessary. */ @Nullable public PropertyEntry getEntry(@Nonnull String key) { PropertyEntry entry = entries.get(key); if (entry == null && parent != null) { return parent.getEntry(key); } return entry; }
private void copyEntries(LinkedHashMap<String, PropertyEntry> newMap) { if (parent != null) { parent.copyEntries(newMap); } newMap.putAll(entries); }
/** * Limpa as propriedades da memoria e força recarga a partir da memória e classPath. */ public synchronized void reload() { LOGGER.info("Carregando configurações do Singular"); PropertyMap newProperties = readClasspathDefaults(); newProperties = readPropertiesFilesOverrides(newProperties); propertyMap = newProperties.consolidateAndFrozen(); }
/** * Copia as propriedades do arquivo para as properties internas. As propriedades previamente existentes serão * sobrepostas. Esse método é utilizado para testes unitários com difererentes contextos. */ @VisibleForTesting public synchronized void reloadAndOverrideWith(URL propertiesURL) { reload(); PropertyMap p = new PropertyMap(getProperties()); p.readProperties(propertiesURL); propertyMap = p; }
/** * Prints the content of map of properties to the system output identifying the source of each property. */ @Override public void debugContent() { getProperties().debugContent(); }
/** Looks for the value of the key in the current map and into the parent map if necessary. */ @Nullable public String getValue(@Nonnull String key) { PropertyEntry entry = getEntry(key); return entry == null ? null : entry.getValue(); }
/** * Prints the content of map of properties to the specific output identifying the source of each property. */ @Override public void debugContent(@Nonnull Appendable out) { getProperties().debugContent(out); }
@Nullable private String getInternal(@Nonnull String key) { //se contém a chave ainda que esta seja com valor nulo PropertyEntry entry = getProperties().getEntry(key); if (entry != null) { return entry.getValue(); } return StringUtils.trimToNull(System.getProperties().getProperty(key)); }
private void readProperties(@Nonnull Properties properties, @Nonnull PropertySource source) { for (Map.Entry<Object, Object> entry : properties.entrySet()) { add((String) entry.getKey(), (String) entry.getValue(), source); } } /** Sets the value for a property registering it by a unknown source.*/