use of org.sonar.process.MessageException in project sonarqube by SonarSource.
the class JdbcSettings method driverPath.
String driverPath(File homeDir, Provider provider) {
String dirPath = provider.path;
File dir = new File(homeDir, dirPath);
if (!dir.exists()) {
throw new MessageException("Directory does not exist: " + dirPath);
}
List<File> files = new ArrayList<>(FileUtils.listFiles(dir, new String[] { "jar" }, false));
if (files.isEmpty()) {
throw new MessageException("Directory does not contain JDBC driver: " + dirPath);
}
if (files.size() > 1) {
throw new MessageException("Directory must contain only one JAR file: " + dirPath);
}
return files.get(0).getAbsolutePath();
}
use of org.sonar.process.MessageException in project sonarqube by SonarSource.
the class LogbackHelper method createRollingPolicy.
public RollingPolicy createRollingPolicy(Context ctx, Props props, String filenamePrefix) {
String rollingPolicy = props.value(LOG_ROLLING_POLICY.getKey(), "time:yyyy-MM-dd");
int maxFiles = props.valueAsInt(LOG_MAX_FILES.getKey(), 7);
File logsDir = props.nonNullValueAsFile(PATH_LOGS.getKey());
if (rollingPolicy.startsWith("time:")) {
return new TimeRollingPolicy(ctx, filenamePrefix, logsDir, maxFiles, StringUtils.substringAfter(rollingPolicy, "time:"));
} else if (rollingPolicy.startsWith("size:")) {
return new SizeRollingPolicy(ctx, filenamePrefix, logsDir, maxFiles, StringUtils.substringAfter(rollingPolicy, "size:"));
} else if ("none".equals(rollingPolicy)) {
return new NoRollingPolicy(ctx, filenamePrefix, logsDir, maxFiles);
} else {
throw new MessageException(format("Unsupported value for property %s: %s", LOG_ROLLING_POLICY.getKey(), rollingPolicy));
}
}
use of org.sonar.process.MessageException in project sonarqube by SonarSource.
the class LogbackHelperTest method createRollingPolicy_fail_if_unknown_policy.
@Test
public void createRollingPolicy_fail_if_unknown_policy() {
props.set("sonar.log.rollingPolicy", "unknown:foo");
try {
LoggerContext ctx = underTest.getRootContext();
underTest.createRollingPolicy(ctx, props, "sonar");
fail();
} catch (MessageException e) {
assertThat(e).hasMessage("Unsupported value for property sonar.log.rollingPolicy: unknown:foo");
}
}
use of org.sonar.process.MessageException in project sonarqube by SonarSource.
the class JdbcSettings method resolveProviderAndEnforceNonnullJdbcUrl.
Provider resolveProviderAndEnforceNonnullJdbcUrl(Props props) {
String url = props.value(JDBC_URL.getKey());
Integer embeddedDatabasePort = props.valueAsInt(JDBC_EMBEDDED_PORT.getKey());
if (embeddedDatabasePort != null) {
String correctUrl = buildH2JdbcUrl(embeddedDatabasePort);
warnIfUrlIsSet(embeddedDatabasePort, url, correctUrl);
props.set(JDBC_URL.getKey(), correctUrl);
return Provider.H2;
}
if (isEmpty(url)) {
props.set(JDBC_URL.getKey(), buildH2JdbcUrl(JDBC_EMBEDDED_PORT_DEFAULT_VALUE));
props.set(JDBC_EMBEDDED_PORT.getKey(), String.valueOf(JDBC_EMBEDDED_PORT_DEFAULT_VALUE));
return Provider.H2;
}
Pattern pattern = Pattern.compile("jdbc:(\\w+):.+");
Matcher matcher = pattern.matcher(url);
if (!matcher.find()) {
throw new MessageException(format("Bad format of JDBC URL: %s", url));
}
String key = matcher.group(1);
try {
return Provider.valueOf(StringUtils.upperCase(key));
} catch (IllegalArgumentException e) {
throw new MessageException(format("Unsupported JDBC driver provider: %s", key));
}
}
use of org.sonar.process.MessageException in project sonarqube by SonarSource.
the class JvmOptionsTest method addFromMandatoryProperty_throws_IAE_if_option_starts_with_prefix_of_mandatory_option_but_has_different_value.
@Test
public void addFromMandatoryProperty_throws_IAE_if_option_starts_with_prefix_of_mandatory_option_but_has_different_value() {
String[] optionOverrides = { randomPrefix, randomPrefix + randomValue.substring(1), randomPrefix + randomValue.substring(1), randomPrefix + randomValue.substring(2), randomPrefix + randomValue.substring(3), randomPrefix + randomValue.substring(3) + randomAlphanumeric(1), randomPrefix + randomValue.substring(3) + randomAlphanumeric(2), randomPrefix + randomValue.substring(3) + randomAlphanumeric(3), randomPrefix + randomValue + randomAlphanumeric(1) };
JvmOptions underTest = new JvmOptions(ImmutableMap.of(randomPrefix, randomValue));
for (String optionOverride : optionOverrides) {
try {
properties.put(randomPropertyName, optionOverride);
underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName);
fail("an MessageException should have been thrown");
} catch (MessageException e) {
assertThat(e.getMessage()).isEqualTo("a JVM option can't overwrite mandatory JVM options. " + "The following JVM options defined by property '" + randomPropertyName + "' are invalid: " + optionOverride + " overwrites " + randomPrefix + randomValue);
}
}
}
Aggregations