public boolean hasDefaultValue(String key) { return StringUtils.isNotEmpty(getDefaultValue(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(); }
@Test public void default_values_should_be_loaded_from_definitions() { Settings settings = new MapSettings(definitions); assertThat(settings.getDefaultValue("hello")).isEqualTo("world"); }
@Test public void test_get_default_value() { Settings settings = new MapSettings(definitions); assertThat(settings.getDefaultValue("unknown")).isNull(); }
@Test public void shouldCreateByIntrospectingComponent() { Settings settings = new MapSettings(); settings.getDefinitions().addComponent(MyComponent.class); // property definition has been loaded, ie for default value assertThat(settings.getDefaultValue("foo")).isEqualTo("bar"); }
public boolean hasDefaultValue(String key) { return StringUtils.isNotEmpty(getDefaultValue(key)); }
public boolean hasDefaultValue(String key) { return StringUtils.isNotEmpty(getDefaultValue(key)); }
/** * 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; }
/** * The public URL is optionally configured on server. If not, then the regular URL is returned. * See https://jira.sonarsource.com/browse/SONAR-4239 */ private String publicUrl() { String baseUrl = settings.getString(CoreProperties.SERVER_BASE_URL); if (baseUrl.equals(settings.getDefaultValue(CoreProperties.SERVER_BASE_URL))) { // crap workaround for https://jira.sonarsource.com/browse/SONAR-7109 // If server base URL was not configured in Sonar server then is is better to take URL configured on batch side baseUrl = wsClient.baseUrl(); } return baseUrl.replaceAll("(/)+$", ""); } }
@VisibleForTesting void logSuccess(Logger logger) { if (analysisMode.isPreview() || analysisMode.isMediumTest()) { logger.info("ANALYSIS SUCCESSFUL"); } else { String baseUrl = settings.getString(CoreProperties.SERVER_BASE_URL); if (baseUrl.equals(settings.getDefaultValue(CoreProperties.SERVER_BASE_URL))) { // If server base URL was not configured in Sonar server then is is better to take URL configured on batch side baseUrl = serverClient.getURL(); } if (!baseUrl.endsWith("/")) { baseUrl += "/"; } String url = baseUrl + "dashboard/index/" + project.getKey(); logger.info("ANALYSIS SUCCESSFUL, you can browse {}", url); logger.info("Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report."); } } }
/** * 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(); }