/** * @since 6.6 */ public static LocalDate parseLocalDate(String s) { try { return LocalDate.parse(s); } catch (DateTimeParseException e) { throw MessageException.of("The date '" + s + "' does not respect format '" + DATE_FORMAT + "'", e); } }
private static MessageException parsingError(int value) { return MessageException.of(format( "Worker count '%s' is invalid. It must be an integer strictly greater than 0 and less or equal to 10", value)); }
private static void checkDriverVersion(DatabaseMetaData metaData) throws SQLException { String driverVersion = metaData.getDriverVersion(); String[] parts = StringUtils.split(driverVersion, "."); int intVersion = Integer.parseInt(parts[0]) * 100 + Integer.parseInt(parts[1]); if (intVersion < 1200) { throw MessageException.of(String.format( "Unsupported Oracle driver version: %s. Minimal supported version is 12.1.", driverVersion)); } } }
public DefaultBranchImpl(@Nullable String name) { this.isLegacyBranch = (name != null); this.branchName = (name == null) ? BranchDto.DEFAULT_MAIN_BRANCH_NAME : name; if (!ComponentKeys.isValidBranch(branchName)) { throw MessageException.of(format("\"%s\" is not a valid branch name. " + "Allowed characters are alphanumeric, '-', '_', '.' and '/'.", branchName)); } }
@Override public DebtRemediationFunction create(DebtRemediationFunction.Type type, @Nullable String gapMultiplier, @Nullable String baseEffort) { try { return new DefaultDebtRemediationFunction(type, gapMultiplier, baseEffort); } catch (Exception e) { throw MessageException.of(String.format("The rule '%s:%s' is invalid : %s ", this.repoKey, this.key, e.getMessage())); } }
/** * @param s string in format {@link #DATETIME_FORMAT} * @throws SonarException when string cannot be parsed * @since 6.6 */ public static OffsetDateTime parseOffsetDateTime(String s) { try { return OffsetDateTime.parse(s, DATETIME_FORMATTER); } catch (DateTimeParseException e) { throw MessageException.of("The date '" + s + "' does not respect format '" + DATETIME_FORMAT + "'", e); } }
private static void checkPeriodProperty(boolean test, String propertyValue, String testDescription, Object... args) { if (!test) { LOG.debug("Invalid code period '{}': {}", propertyValue, supplierToString(() -> format(testDescription, args))); throw MessageException.of(format("Invalid new code period. '%s' is not one of: " + "integer > 0, date before current analysis j, \"previous_version\", or version string that exists in the project' \n" + "Please contact a project administrator to correct this setting", propertyValue)); } }
public static Dialect find(String dialectId, String jdbcConnectionUrl) { Optional<Dialect> match = StringUtils.isNotBlank(dialectId) ? findById(dialectId) : findByJdbcUrl(jdbcConnectionUrl); return match.orElseThrow(() -> MessageException.of( "Unable to determine database dialect to use within sonar with dialect " + dialectId + " jdbc url " + jdbcConnectionUrl)); }
private static Map<String, LanguageSpecificConfiguration> initLanguageSpecificConfigurationByLanguageKey(Configuration config) { ImmutableMap.Builder<String, LanguageSpecificConfiguration> builder = ImmutableMap.builder(); String[] languageConfigIndexes = config.getStringArray(LANGUAGE_SPECIFIC_PARAMETERS); for (String languageConfigIndex : languageConfigIndexes) { String languagePropertyKey = LANGUAGE_SPECIFIC_PARAMETERS + "." + languageConfigIndex + "." + LANGUAGE_SPECIFIC_PARAMETERS_LANGUAGE_KEY; String languageKey = config.get(languagePropertyKey) .orElseThrow(() -> MessageException.of("Technical debt configuration is corrupted. At least one language specific parameter has no Language key. " + "Contact your administrator to update this configuration in the global administration section of SonarQube.")); builder.put(languageKey, LanguageSpecificConfiguration.create(config, languageConfigIndex)); } return builder.build(); }
private void checkIfAlreadyIndexed(DefaultInputFile inputFile) { if (componentStore.inputFile(inputFile.getProjectRelativePath()) != null) { throw MessageException.of("File " + inputFile + " can't be indexed twice. Please check that inclusion/exclusion patterns produce " + "disjoint sets for main and test files"); } }
@Override public void start() { if (server.isStandalone()) { return; } if (feature == null || !feature.isEnabled()) { throw MessageException.of( "Cluster mode can't be enabled. Please install the Data Center Edition. More details at https://redirect.sonarsource.com/editions/datacenter.html."); } }
private void expectUtf8(Connection connection) throws SQLException { // Oracle does not allow to override character set on tables. Only global charset is verified. String charset = getSqlExecutor().selectSingleString(connection, "select value from nls_database_parameters where parameter='NLS_CHARACTERSET'"); if (!containsIgnoreCase(charset, UTF8)) { throw MessageException.of(format("Oracle NLS_CHARACTERSET does not support UTF8: %s", charset)); } } }
Version checkDbVersion(DatabaseMetaData metaData, Version minSupported) throws SQLException { int major = metaData.getDatabaseMajorVersion(); int minor = metaData.getDatabaseMinorVersion(); Version version = Version.create(major, minor, 0); if (version.compareTo(minSupported) < 0) { throw MessageException.of(String.format( "Unsupported %s version: %s. Minimal supported version is %s.", getId(), version, minSupported)); } return version; } }
private void expectUtf8AsDefault(Connection connection) throws SQLException { Loggers.get(getClass()).info("Verify that database charset supports UTF8"); String collation = metadata.getDefaultCharset(connection); if (!containsIgnoreCase(collation, UTF8)) { throw MessageException.of(format("Database charset is %s. It must support UTF8.", collation)); } }
private void expectCaseSensitiveDefaultCollation(Connection connection) throws SQLException { LOGGER.info("Verify that database collation is case-sensitive and accent-sensitive"); String defaultCollation = metadata.getDefaultCollation(connection); if (!isCollationCorrect(defaultCollation)) { String fixedCollation = toCaseSensitive(defaultCollation); throw MessageException.of(format( "Database collation must be case-sensitive and accent-sensitive. It is %s but should be %s.", defaultCollation, fixedCollation)); } }
@VisibleForTesting protected static void checkUniquenessOfChildKey(ProjectDefinition childProject, ProjectDefinition parentProject) { for (ProjectDefinition definition : parentProject.getSubProjects()) { if (definition.getKey().equals(childProject.getKey())) { throw MessageException.of("Project '" + parentProject.getKey() + "' can't have 2 modules with the following key: " + childProject.getKey()); } } }
@Test public void should_create_exception() { String message = "the message"; MessageException exception = MessageException.of(message); assertThat(exception.getMessage()).isEqualTo(message); assertThat(exception).isInstanceOf(RuntimeException.class); }
@Test public void do_no_log_error_when_task_fails_with_MessageException() throws Exception { CeTask ceTask = createCeTask(submitter); when(queue.peek(anyString())).thenReturn(Optional.of(ceTask)); taskProcessorRepository.setProcessorForTask(CeTaskTypes.REPORT, taskProcessor); makeTaskProcessorFail(ceTask, MessageException.of("simulate MessageException thrown by TaskProcessor#process")); underTest.call(); List<String> logs = logTester.logs(LoggerLevel.INFO); assertThat(logs).hasSize(2); assertThat(logs.get(1)).contains(" | submitter=" + submitter.getLogin()); assertThat(logs.get(1)).contains(String.format(" | submitter=%s | status=FAILED | time=", submitter.getLogin())); assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty(); }
@Test public void failFastHttpErrorMessageException() { thrown.expect(MessageException.class); thrown.expectMessage("http error"); HttpException http = new HttpException("uri", 403, null); MessageException e = MessageException.of("http error", http); WsTestUtil.mockException(wsClient, e); loader.load(PROJECT_KEY, false, null); }