use of org.sonar.api.utils.SonarException in project sonarqube by SonarSource.
the class NotificationQueueDto method toNotificationQueueDto.
public static NotificationQueueDto toNotificationQueueDto(Notification notification) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(notification);
objectOutputStream.close();
return new NotificationQueueDto().setData(byteArrayOutputStream.toByteArray());
} catch (IOException e) {
throw new SonarException("Unable to write notification", e);
} finally {
IOUtils.closeQuietly(byteArrayOutputStream);
}
}
use of org.sonar.api.utils.SonarException in project sonarqube by SonarSource.
the class EmbeddedDatabase method startServer.
private void startServer(File dbHome) {
String url = getRequiredSetting(PROP_URL);
String port = getRequiredSetting(PROP_EMBEDDED_PORT);
String user = getSetting(PROP_USER, PROP_USER_DEFAULT_VALUE);
String password = getSetting(PROP_PASSWORD, PROP_PASSWORD_DEFAULT_VALUE);
try {
if (url.contains("/mem:")) {
server = Server.createTcpServer("-tcpPort", port, "-tcpAllowOthers", "-baseDir", dbHome.getAbsolutePath());
} else {
createDatabase(dbHome, user, password);
server = Server.createTcpServer("-tcpPort", port, "-tcpAllowOthers", "-ifExists", "-baseDir", dbHome.getAbsolutePath());
}
LOG.info("Starting embedded database on port " + server.getPort() + " with url " + url);
server.start();
LOG.info("Embedded database started. Data stored in: " + dbHome.getAbsolutePath());
} catch (Exception e) {
throw new SonarException("Unable to start database", e);
}
}
use of org.sonar.api.utils.SonarException in project sonarqube by SonarSource.
the class SecurityRealmFactoryTest method should_fail.
@Test
public void should_fail() {
SecurityRealm realm = spy(new AlwaysFailsRealm());
settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
try {
new SecurityRealmFactory(settings, new SecurityRealm[] { realm }).start();
fail();
} catch (SonarException e) {
assertThat(e.getCause()).isInstanceOf(IllegalStateException.class);
assertThat(e.getMessage()).contains("Security realm fails to start");
}
}
use of org.sonar.api.utils.SonarException in project sonarqube by SonarSource.
the class XMLProfileSerializer method write.
public void write(RulesProfile profile, Writer writer) {
try {
appendHeader(profile, writer);
appendRules(profile, writer);
appendFooter(writer);
} catch (IOException e) {
throw new SonarException("Fail to export the profile " + profile, e);
}
}
use of org.sonar.api.utils.SonarException in project sonarqube by SonarSource.
the class PluginDownloader method download.
public void download(String pluginKey, Version version) {
Optional<UpdateCenter> updateCenter = updateCenterMatrixFactory.getUpdateCenter(true);
if (updateCenter.isPresent()) {
List<Release> installablePlugins = updateCenter.get().findInstallablePlugins(pluginKey, version);
checkRequest(!installablePlugins.isEmpty(), "Error while downloading plugin '%s' with version '%s'. No compatible plugin found.", pluginKey, version.getName());
for (Release release : installablePlugins) {
try {
downloadRelease(release);
} catch (Exception e) {
String message = String.format("Fail to download the plugin (%s, version %s) from %s (error is : %s)", release.getArtifact().getKey(), release.getVersion().getName(), release.getDownloadUrl(), e.getMessage());
LOG.debug(message, e);
throw new SonarException(message, e);
}
}
}
}
Aggregations