Search in sources :

Example 1 with SonarException

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);
    }
}
Also used : SonarException(org.sonar.api.utils.SonarException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

Example 2 with SonarException

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);
    }
}
Also used : SonarException(org.sonar.api.utils.SonarException) SonarException(org.sonar.api.utils.SonarException) SQLException(java.sql.SQLException)

Example 3 with SonarException

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");
    }
}
Also used : SecurityRealm(org.sonar.api.security.SecurityRealm) SonarException(org.sonar.api.utils.SonarException) Test(org.junit.Test)

Example 4 with SonarException

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);
    }
}
Also used : SonarException(org.sonar.api.utils.SonarException) IOException(java.io.IOException)

Example 5 with SonarException

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);
            }
        }
    }
}
Also used : UpdateCenter(org.sonar.updatecenter.common.UpdateCenter) SonarException(org.sonar.api.utils.SonarException) Release(org.sonar.updatecenter.common.Release) SonarException(org.sonar.api.utils.SonarException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Aggregations

SonarException (org.sonar.api.utils.SonarException)16 Test (org.junit.Test)6 IOException (java.io.IOException)4 URI (java.net.URI)4 SMInputCursor (org.codehaus.staxmate.in.SMInputCursor)3 Release (org.sonar.updatecenter.common.Release)3 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 MapSettings (org.sonar.api.config.MapSettings)2 Plugin (org.sonar.updatecenter.common.Plugin)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 NoRouteToHostException (java.net.NoRouteToHostException)1 SocketException (java.net.SocketException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1