/** * @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); } }
@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); }
public static MessageException ofL10n(String l10nKey, Object... l10nParams) { return new MessageException(null, l10nKey, l10nParams); }
@Override public String toString() { return getMessage(); }
@Test public void fail_if_conflicting_language_suffix() throws Exception { LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml"))); LanguageDetection detection = new LanguageDetection(settings.asConfig(), languages); try { detectLanguage(detection, "abc.xhtml"); fail(); } catch (MessageException e) { assertThat(e.getMessage()) .contains("Language of file 'abc.xhtml' can not be decided as the file matches patterns of both ") .contains("sonar.lang.patterns.web : **/*.xhtml") .contains("sonar.lang.patterns.xml : **/*.xhtml"); } }
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)); }
@Test public void fail_if_conflicting_filepattern() throws Exception { LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("abap", "abap"), new MockLanguage("cobol", "cobol"))); settings.setProperty("sonar.lang.patterns.abap", "*.abap,*.txt"); settings.setProperty("sonar.lang.patterns.cobol", "*.cobol,*.txt"); LanguageDetection detection = new LanguageDetection(settings.asConfig(), languages); assertThat(detectLanguage(detection, "abc.abap")).isEqualTo("abap"); assertThat(detectLanguage(detection, "abc.cobol")).isEqualTo("cobol"); try { detectLanguage(detection, "abc.txt"); fail(); } catch (MessageException e) { assertThat(e.getMessage()) .contains("Language of file 'abc.txt' can not be decided as the file matches patterns of both ") .contains("sonar.lang.patterns.abap : *.abap,*.txt") .contains("sonar.lang.patterns.cobol : *.cobol,*.txt"); } }
public static MessageException of(String message, Throwable cause) { return new MessageException(message, cause); }
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)); } } }
@Override public String toString() { return getMessage(); }
public static MessageException of(String message) { return new MessageException(message); }
protected static void setProjectBaseDir(File baseDir, Map<String, String> childProps, String moduleId) { if (!baseDir.isDirectory()) { throw MessageException.of("The base directory of the module '" + moduleId + "' does not exist: " + baseDir.getAbsolutePath()); } childProps.put(PROPERTY_PROJECT_BASEDIR, baseDir.getAbsolutePath()); }
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); } }
public void parse(File reportFile, SensorContext context) { try (InputStream inputStream = new FileInputStream(reportFile)) { parse(inputStream, context); } catch (Exception e) { throw MessageException.of("Error during parsing of the generic coverage report '" + reportFile + "'. Look at SonarQube documentation to know the expected XML format.", e); } }
public void parse(File reportFile, SensorContext context) { try (InputStream inputStream = new FileInputStream(reportFile)) { parse(inputStream, context); } catch (Exception e) { throw MessageException.of( "Error during parsing of generic test execution report '" + reportFile + "'. Look at the SonarQube documentation to know the expected XML format.", e); } }
static String getContextPath(Props props) { String context = props.value(PROPERTY_CONTEXT, ""); if ("/".equals(context)) { context = ""; } else if (!"".equals(context) && context != null && !context.startsWith("/")) { throw MessageException.of(format("Value of '%s' must start with a forward slash: '%s'", PROPERTY_CONTEXT, context)); } return context; }
@VisibleForTesting protected static void checkMandatoryProperties(Map<String, String> props, String[] mandatoryProps) { StringBuilder missing = new StringBuilder(); for (String mandatoryProperty : mandatoryProps) { if (!props.containsKey(mandatoryProperty)) { if (missing.length() > 0) { missing.append(", "); } missing.append(mandatoryProperty); } } String moduleKey = StringUtils.defaultIfBlank(props.get(MODULE_KEY_PROPERTY), props.get(CoreProperties.PROJECT_KEY_PROPERTY)); if (missing.length() != 0) { throw MessageException.of("You must define the following mandatory properties for '" + (moduleKey == null ? "Unknown" : moduleKey) + "': " + missing); } }
@VisibleForTesting protected static void checkExistenceOfPaths(String moduleRef, File baseDir, String[] paths, String propName) { for (String path : paths) { File sourceFolder = resolvePath(baseDir, path); if (!sourceFolder.exists()) { LOG.error(MessageFormat.format(INVALID_VALUE_OF_X_FOR_Y, propName, moduleRef)); throw MessageException.of("The folder '" + path + "' does not exist for '" + moduleRef + "' (base directory = " + baseDir.getAbsolutePath() + ")"); } } }