@CheckForNull public PropertyDefinition get(String key) { return definitions.get(validKey(key)); }
protected static Map<String, String> unmodifiableMapWithTrimmedValues(PropertyDefinitions definitions, Map<String, String> props) { Map<String, String> map = new HashMap<>(props.size()); props.forEach((k, v) -> { String validKey = definitions.validKey(k); map.put(validKey, trim(v)); }); return Collections.unmodifiableMap(map); }
/** * The value that overrides the default value. It * may be encrypted with a secret key. Use {@link #getString(String)} to get * the effective and decrypted value. * * @since 6.1 */ public Optional<String> getRawString(String key) { return get(definitions.validKey(requireNonNull(key))); }
public String getSubCategory(String key) { return subcategories.get(validKey(key)).toString(); }
public String getCategory(String key) { return categories.get(validKey(key)).toString(); }
public Settings appendProperty(String key, @Nullable String value) { Optional<String> existingValue = getRawString(definitions.validKey(key)); String newValue; if (!existingValue.isPresent()) { newValue = trim(value); } else { newValue = existingValue.get() + "," + trim(value); } return setProperty(key, newValue); }
/** * Change a property value in a restricted scope only, depending on execution context. New value * is <b>never</b> persisted. New value is ephemeral and kept in memory only: * <ul> * <li>during current analysis in the case of scanner stack</li> * <li>during processing of current HTTP request in the case of web server stack</li> * <li>during execution of current task in the case of Compute Engine stack</li> * </ul> * * Property is temporarily removed if the parameter {@code value} is {@code null} */ public Settings setProperty(String key, @Nullable String value) { String validKey = definitions.validKey(key); if (value == null) { removeProperty(validKey); } else { set(validKey, trim(value)); } return this; }
/** * Value is split by comma and trimmed. Never returns null. * <br> * Examples : * <ul> * <li>"one,two,three " -> ["one", "two", "three"]</li> * <li>" one, two, three " -> ["one", "two", "three"]</li> * <li>"one, , three" -> ["one", "", "three"]</li> * </ul> */ public String[] getStringArray(String key) { String effectiveKey = definitions.validKey(key); Optional<PropertyDefinition> def = getDefinition(effectiveKey); if ((def.isPresent()) && (def.get().multiValues())) { String value = getString(key); if (value == null) { return ArrayUtils.EMPTY_STRING_ARRAY; } List<String> values = new ArrayList<>(); for (String v : Splitter.on(",").trimResults().split(value)) { values.add(v.replace("%2C", ",")); } return values.toArray(new String[values.size()]); } return getStringArrayBySeparator(key, ","); }
/** * The effective value of the specified property. Can return * {@code null} if the property is not set and has no * defined default value. * <p> * If the property is encrypted with a secret key, * then the returned value is decrypted. * </p> * * @throws IllegalStateException if value is encrypted but fails to be decrypted. */ @CheckForNull public String getString(String key) { String effectiveKey = definitions.validKey(key); Optional<String> value = getRawString(effectiveKey); if (!value.isPresent()) { // default values cannot be encrypted, so return value as-is. return getDefaultValue(effectiveKey); } if (encryption.isEncrypted(value.get())) { try { return encryption.decrypt(value.get()); } catch (Exception e) { throw new IllegalStateException("Fail to decrypt the property " + effectiveKey + ". Please check your secret key.", e); } } return value.get(); }
@Override public String[] getStringArray(String key) { String effectiveKey = definitions.validKey(key); PropertyDefinition def = definitions.get(effectiveKey); if (def != null && !def.multiValues() && def.fields().isEmpty()) { LOG.warn( "Property '{}' is not declared as multi-values/property set but was read using 'getStringArray' method. The SonarQube plugin declaring this property should be updated.", key); } Optional<String> value = getInternal(effectiveKey); if (value.isPresent()) { return parseAsCsv(effectiveKey, value.get()); } return ArrayUtils.EMPTY_STRING_ARRAY; }
@Override public Optional<String> get(String key) { String effectiveKey = definitions.validKey(key); PropertyDefinition def = definitions.get(effectiveKey); if (def != null && (def.multiValues() || !def.fields().isEmpty())) { LOG.warn("Access to the multi-values/property set property '{}' should be made using 'getStringArray' method. The SonarQube plugin using this property should be updated.", key); } return getInternal(effectiveKey); }
@Test public void validKey_throws_NPE_if_key_is_null() { PropertyDefinitions underTest = new PropertyDefinitions(); expectedException.expect(NullPointerException.class); expectedException.expectMessage("key can't be null"); underTest.validKey(null); }
protected static Map<String, String> unmodifiableMapWithTrimmedValues(PropertyDefinitions definitions, Map<String, String> props) { Map<String, String> map = new HashMap<>(props.size()); props.forEach((k, v) -> { String validKey = definitions.validKey(k); map.put(validKey, trim(v)); }); return Collections.unmodifiableMap(map); }
public Settings appendProperty(String key, String value) { String newValue = properties.get(definitions.validKey(key)); if (StringUtils.isEmpty(newValue)) { newValue = StringUtils.trim(value); } else { newValue += "," + StringUtils.trim(value); } return setProperty(key, newValue); }
public String getCategory(String key) { return categories.get(validKey(key)).toString(); }
/** * The value that overrides the default value. It * may be encrypted with a secret key. Use {@link #getString(String)} to get * the effective and decrypted value. * * @since 6.1 */ public Optional<String> getRawString(String key) { return get(definitions.validKey(requireNonNull(key))); }
public Settings setProperty(String key, @Nullable String value) { String validKey = definitions.validKey(key); if (value == null) { properties.remove(validKey); doOnRemoveProperty(validKey); } else { properties.put(validKey, StringUtils.trim(value)); doOnSetProperty(validKey, value); } return this; }
/** * Does not decrypt value. */ protected String getClearString(String key) { doOnGetProperties(key); String validKey = definitions.validKey(key); String value = properties.get(validKey); if (value == null) { value = getDefaultValue(validKey); } return value; }
public Settings appendProperty(String key, @Nullable String value) { Optional<String> existingValue = getRawString(definitions.validKey(key)); String newValue; if (!existingValue.isPresent()) { newValue = trim(value); } else { newValue = existingValue.get() + "," + trim(value); } return setProperty(key, newValue); }
@Override public Optional<String> get(String key) { String effectiveKey = definitions.validKey(key); PropertyDefinition def = definitions.get(effectiveKey); if (def != null && (def.multiValues() || !def.fields().isEmpty())) { LOG.warn("Access to the multi-values/property set property '{}' should be made using 'getStringArray' method. The SonarQube plugin using this property should be updated.", key); } return getInternal(effectiveKey); }