*/
package org.sonar.server.database;
-import org.h2.Driver;
-
import org.apache.commons.lang.StringUtils;
+import org.h2.Driver;
import org.h2.tools.Server;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.config.Settings;
import org.sonar.api.database.DatabaseProperties;
import org.sonar.api.utils.SonarException;
-import org.sonar.server.platform.ServerStartException;
import java.io.File;
import java.sql.DriverManager;
public class EmbeddedDatabase {
private static final Logger LOG = LoggerFactory.getLogger(EmbeddedDatabase.class);
-
private final Settings settings;
private Server server;
this.settings = settings;
}
+ private static File getDataDirectory(Settings settings) {
+ String dirName = settings.getString(DatabaseProperties.PROP_EMBEDDED_DATA_DIR);
+ if (!StringUtils.isBlank(dirName)) {
+ return new File(dirName);
+ }
+
+ File sonarHome = new File(settings.getString(CoreProperties.SONAR_HOME));
+ if (sonarHome.isDirectory() && sonarHome.exists()) {
+ return new File(sonarHome, "data");
+ }
+
+ throw new IllegalStateException("Sonar home directory does not exist");
+ }
+
public void start() {
File dbHome = getDataDirectory(settings);
if (dbHome.exists() && !dbHome.isDirectory()) {
DriverManager.registerDriver(new Driver());
DriverManager.getConnection(url).close();
}
-
- private static File getDataDirectory(Settings settings) {
- String dirName = settings.getString(DatabaseProperties.PROP_EMBEDDED_DATA_DIR);
- if (!StringUtils.isBlank(dirName)) {
- return new File(dirName);
- }
-
- File sonarHome = new File(settings.getString(CoreProperties.SONAR_HOME));
- if (sonarHome.isDirectory() && sonarHome.exists()) {
- return new File(sonarHome, "data");
- }
-
- throw new ServerStartException("Sonar home directory does not exist");
- }
}
public void start() {
LOGGER.info("Sonar home: " + homeDir.getAbsolutePath());
if (!homeDir.isDirectory() || !homeDir.exists()) {
- throw new ServerStartException("Sonar home directory does not exist");
+ throw new IllegalStateException("Sonar home directory does not exist");
}
if (deployDir == null) {
- throw new ServerStartException("The target directory to deploy libraries is not set");
+ throw new IllegalStateException("The target directory to deploy libraries is not set");
}
try {
}
} catch (IOException e) {
- throw new ServerStartException("The following directory can not be created: " + deployDir.getAbsolutePath(), e);
+ throw new IllegalStateException("The following directory can not be created: " + deployDir.getAbsolutePath(), e);
}
File deprecated = getDeprecatedPluginsDir();
FileUtils.cleanDirectory(deprecated);
} catch (IOException e) {
- throw new ServerStartException("The following directory can not be created: " + deprecated.getAbsolutePath(), e);
+ throw new IllegalStateException("The following directory can not be created: " + deprecated.getAbsolutePath(), e);
}
}
File dir = new File(getHomeDir(), "/extensions/jdbc-driver/" + dialect + "/");
List<File> jars = getFiles(dir, "jar");
if (jars.isEmpty()) {
- throw new ServerStartException("No JDBC driver found in " + dir.getAbsolutePath());
+ throw new IllegalStateException("No JDBC driver found in " + dir.getAbsolutePath());
}
if (jars.size() > 1) {
- throw new ServerStartException("The directory " + dir.getAbsolutePath() + " accepts only a single JAR file");
+ throw new IllegalStateException("The directory " + dir.getAbsolutePath() + " accepts only a single JAR file");
}
return jars.get(0);
}
import org.sonar.core.measure.MeasureFilterFactory;
import org.sonar.core.metric.DefaultMetricFinder;
import org.sonar.core.notification.DefaultNotificationManager;
-import org.sonar.core.persistence.*;
+import org.sonar.core.persistence.DaoUtils;
+import org.sonar.core.persistence.DatabaseMigrator;
+import org.sonar.core.persistence.DatabaseVersion;
+import org.sonar.core.persistence.DefaultDatabase;
+import org.sonar.core.persistence.DryRunDatabaseFactory;
+import org.sonar.core.persistence.MyBatis;
+import org.sonar.core.persistence.SemaphoreUpdater;
+import org.sonar.core.persistence.SemaphoresImpl;
import org.sonar.core.qualitymodel.DefaultModelFinder;
import org.sonar.core.resource.DefaultResourcePermissions;
import org.sonar.core.rule.DefaultRuleFinder;
import org.sonar.server.notifications.NotificationCenter;
import org.sonar.server.notifications.NotificationService;
import org.sonar.server.notifications.reviews.ReviewsNotificationManager;
-import org.sonar.server.plugins.*;
+import org.sonar.server.plugins.ApplicationDeployer;
+import org.sonar.server.plugins.DefaultServerPluginRepository;
+import org.sonar.server.plugins.InstalledPluginReferentialFactory;
+import org.sonar.server.plugins.PluginDeployer;
+import org.sonar.server.plugins.PluginDownloader;
+import org.sonar.server.plugins.ServerExtensionInstaller;
+import org.sonar.server.plugins.UpdateCenterClient;
+import org.sonar.server.plugins.UpdateCenterMatrixFactory;
import org.sonar.server.qualitymodel.DefaultModelManager;
import org.sonar.server.rules.ProfilesConsole;
import org.sonar.server.rules.RulesConsole;
-import org.sonar.server.startup.*;
-import org.sonar.server.ui.*;
+import org.sonar.server.startup.DeleteDeprecatedMeasures;
+import org.sonar.server.startup.GenerateBootstrapIndex;
+import org.sonar.server.startup.GeneratePluginIndex;
+import org.sonar.server.startup.GwtPublisher;
+import org.sonar.server.startup.JdbcDriverDeployer;
+import org.sonar.server.startup.LogServerId;
+import org.sonar.server.startup.RegisterMetrics;
+import org.sonar.server.startup.RegisterNewDashboards;
+import org.sonar.server.startup.RegisterNewMeasureFilters;
+import org.sonar.server.startup.RegisterNewProfiles;
+import org.sonar.server.startup.RegisterQualityModels;
+import org.sonar.server.startup.RegisterRules;
+import org.sonar.server.startup.RegisterServletFilters;
+import org.sonar.server.startup.RenameDeprecatedPropertyKeys;
+import org.sonar.server.startup.ServerMetadataPersister;
+import org.sonar.server.ui.CodeColorizers;
+import org.sonar.server.ui.JRubyI18n;
+import org.sonar.server.ui.PageDecorations;
+import org.sonar.server.ui.SecurityRealmFactory;
+import org.sonar.server.ui.Views;
import javax.servlet.ServletContext;
rootContainer.addSingleton(daoClass);
}
rootContainer.addSingleton(PluginDeployer.class);
- rootContainer.addSingleton(PluginReferentialMetadataConverter.class);
rootContainer.addSingleton(InstalledPluginReferentialFactory.class);
rootContainer.addSingleton(DefaultServerPluginRepository.class);
implementationBuild = read(buildProperties).getProperty("Implementation-Build");
if (StringUtils.isBlank(version)) {
- throw new ServerStartException("Unknown Sonar version");
+ throw new IllegalStateException("Unknown Sonar version");
}
LOG.info("Sonar {}", Joiner.on(" / ").skipNulls().join("Server", version, implementationBuild));
} catch (IOException e) {
- throw new ServerStartException("Can not load metadata", e);
+ throw new IllegalStateException("Can not load metadata", e);
}
}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.server.platform;
-
-public class ServerStartException extends RuntimeException {
-
- public ServerStartException(String s) {
- super(s);
- }
-
- public ServerStartException(String s, Throwable throwable) {
- super(s, throwable);
- }
-}
import org.sonar.api.ServerComponent;
import org.sonar.api.platform.PluginRepository;
-import org.sonar.server.platform.ServerStartException;
import org.sonar.updatecenter.common.PluginReferential;
public class InstalledPluginReferentialFactory implements ServerComponent {
- private final PluginReferentialMetadataConverter pluginReferentialMetadataConverter;
private final PluginRepository pluginRepository;
private PluginReferential installedPluginReferential;
- public InstalledPluginReferentialFactory(PluginRepository pluginRepository, PluginReferentialMetadataConverter pluginReferentialMetadataConverter) {
+ public InstalledPluginReferentialFactory(PluginRepository pluginRepository) {
this.pluginRepository = pluginRepository;
- this.pluginReferentialMetadataConverter = pluginReferentialMetadataConverter;
}
public void start() {
try {
init();
} catch (Exception e) {
- throw new ServerStartException("Unable to load installed plugins", e);
+ throw new IllegalStateException("Unable to load installed plugins", e);
}
}
}
private void init() {
- installedPluginReferential = pluginReferentialMetadataConverter.getInstalledPluginReferential(pluginRepository.getMetadata());
+ installedPluginReferential = PluginReferentialMetadataConverter.getInstalledPluginReferential(pluginRepository.getMetadata());
}
}
import org.sonar.core.plugins.DefaultPluginMetadata;
import org.sonar.core.plugins.PluginInstaller;
import org.sonar.server.platform.DefaultServerFileSystem;
-import org.sonar.server.platform.ServerStartException;
import org.sonar.updatecenter.common.PluginReferential;
import java.io.File;
private final DefaultServerFileSystem fileSystem;
private final PluginInstaller installer;
private final Map<String, PluginMetadata> pluginByKeys = Maps.newHashMap();
- private final PluginReferentialMetadataConverter pluginReferentialMetadataConverter;
- public PluginDeployer(Server server, DefaultServerFileSystem fileSystem, PluginReferentialMetadataConverter pluginReferentialMetadataConverter) {
- this(server, fileSystem, new PluginInstaller(), pluginReferentialMetadataConverter);
+ public PluginDeployer(Server server, DefaultServerFileSystem fileSystem) {
+ this(server, fileSystem, new PluginInstaller());
}
- PluginDeployer(Server server, DefaultServerFileSystem fileSystem, PluginInstaller installer, PluginReferentialMetadataConverter pluginReferentialMetadataConverter) {
+ PluginDeployer(Server server, DefaultServerFileSystem fileSystem, PluginInstaller installer) {
this.server = server;
this.fileSystem = fileSystem;
this.installer = installer;
- this.pluginReferentialMetadataConverter = pluginReferentialMetadataConverter;
}
public void start() {
PluginMetadata existing = pluginByKeys.put(metadata.getKey(), metadata);
if ((existing != null) && !canDelete) {
- throw new ServerStartException("Found two plugins with the same key '" + metadata.getKey() + "': " + metadata.getFile().getName() + " and "
+ throw new IllegalStateException("Found two plugins with the same key '" + metadata.getKey() + "': " + metadata.getFile().getName() + " and "
+ existing.getFile().getName());
}
}
private PluginReferential getPluginReferential() {
- return pluginReferentialMetadataConverter.getInstalledPluginReferential(getMetadata());
+ return PluginReferentialMetadataConverter.getInstalledPluginReferential(getMetadata());
}
}
*/
package org.sonar.server.plugins;
-import org.sonar.api.ServerComponent;
import org.sonar.api.platform.PluginMetadata;
import org.sonar.updatecenter.common.PluginManifest;
import org.sonar.updatecenter.common.PluginReferential;
import static com.google.common.collect.Lists.newArrayList;
-public class PluginReferentialMetadataConverter implements ServerComponent {
+public class PluginReferentialMetadataConverter {
- public PluginReferential getInstalledPluginReferential(Collection<PluginMetadata> metadata) {
+ private PluginReferentialMetadataConverter() {
+ // Only static call
+ }
+
+ public static PluginReferential getInstalledPluginReferential(Collection<PluginMetadata> metadata) {
List<PluginManifest> pluginManifestList = getPluginManifestList(metadata);
return PluginReferentialManifestConverter.fromPluginManifests(pluginManifestList);
}
- private List<PluginManifest> getPluginManifestList(Collection<PluginMetadata> metadata) {
+ private static List<PluginManifest> getPluginManifestList(Collection<PluginMetadata> metadata) {
List<PluginManifest> pluginManifestList = newArrayList();
for (PluginMetadata plugin : metadata) {
if (!plugin.isCore()) {
return pluginManifestList;
}
- private PluginManifest toPluginManifest(PluginMetadata metadata) {
+ private static PluginManifest toPluginManifest(PluginMetadata metadata) {
PluginManifest pluginManifest = new PluginManifest();
pluginManifest.setKey(metadata.getKey());
pluginManifest.setName(metadata.getName());
import org.sonar.api.utils.Logs;
import org.sonar.api.utils.TimeProfiler;
import org.sonar.jpa.dao.MeasuresDao;
-import org.sonar.server.platform.ServerStartException;
import javax.persistence.Query;
+
import java.util.List;
import java.util.Map;
for (Metric metric : metrics.getMetrics()) {
String metricKey = metric.getKey();
if (CoreMetrics.getMetrics().contains(metric)) {
- throw new ServerStartException("The following metric is already defined in sonar: " + metricKey);
+ throw new IllegalStateException("The following metric is already defined in sonar: " + metricKey);
}
Metrics anotherRepository = metricsByRepository.get(metricKey);
if (anotherRepository != null) {
- throw new ServerStartException("The metric '" + metricKey + "' is already defined in the extension: " + anotherRepository);
+ throw new IllegalStateException("The metric '" + metricKey + "' is already defined in the extension: " + anotherRepository);
}
metricsByRepository.put(metricKey, metrics);
}
assertNotNull(driver);
}
- @Test(expected = ServerStartException.class)
+ @Test(expected = IllegalStateException.class)
public void failIfJdbcDriverNotFound() {
Database database = mock(Database.class);
assertEquals(0, jars.size());
}
- @Test(expected = ServerStartException.class)
+ @Test(expected = IllegalStateException.class)
public void shouldFailIfHomeDirectoryNotExists() {
DefaultServerFileSystem fs = new DefaultServerFileSystem(null, new File("/notexists"), null);
fs.start();
@Test
public void testFileWithNoVersion() {
- exception.expect(ServerStartException.class);
+ exception.expect(IllegalStateException.class);
exception.expectMessage("Unknown Sonar version");
ServerImpl server = new ServerImpl(new Settings(), "", "/org/sonar/server/platform/ServerImplTest/pom-without-version.properties");
@Test
public void testFileWithEmptyVersionParameter() {
- exception.expect(ServerStartException.class);
+ exception.expect(IllegalStateException.class);
exception.expectMessage("Unknown Sonar version");
ServerImpl server = new ServerImpl(new Settings(), "", "/org/sonar/server/platform/ServerImplTest/pom-with-empty-version.properties");
@Test
public void shouldFailIfFileNotFound() {
- exception.expect(ServerStartException.class);
+ exception.expect(IllegalStateException.class);
exception.expectMessage("Unknown Sonar version");
ServerImpl server = new ServerImpl(new Settings(), "", "/org/sonar/server/platform/ServerImplTest/unknown-file.properties");
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.server.plugins;
+
+import org.junit.Test;
+import org.sonar.api.platform.PluginMetadata;
+import org.sonar.api.platform.PluginRepository;
+import org.sonar.core.plugins.DefaultPluginMetadata;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class InstalledPluginReferentialFactoryTest {
+
+ @Test
+ public void should_create_plugin_referential() {
+ PluginMetadata metadata = mock(DefaultPluginMetadata.class);
+ when(metadata.getKey()).thenReturn("foo");
+ when(metadata.getRequiredPlugins()).thenReturn(new String[]{});
+ PluginRepository pluginRepository = mock(PluginRepository.class);
+ when(pluginRepository.getMetadata()).thenReturn(newArrayList(metadata));
+ InstalledPluginReferentialFactory installedPluginReferentialFactory = new InstalledPluginReferentialFactory(pluginRepository);
+
+ assertThat(installedPluginReferentialFactory.getInstalledPluginReferential()).isNull();
+ installedPluginReferentialFactory.start();
+ assertThat(installedPluginReferentialFactory.getInstalledPluginReferential()).isNotNull();
+ assertThat(installedPluginReferentialFactory.getInstalledPluginReferential().getPlugins()).hasSize(1);
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void should_encapsulate_exception() {
+ PluginRepository pluginRepository = mock(PluginRepository.class);
+ when(pluginRepository.getMetadata()).thenThrow(new IllegalArgumentException());
+ InstalledPluginReferentialFactory installedPluginReferentialFactory = new InstalledPluginReferentialFactory(pluginRepository);
+ installedPluginReferentialFactory.start();
+ }
+}
import org.sonar.api.platform.Server;
import org.sonar.core.plugins.PluginInstaller;
import org.sonar.server.platform.DefaultServerFileSystem;
-import org.sonar.server.platform.ServerStartException;
import org.sonar.test.TestUtils;
import java.io.File;
public class PluginDeployerTest {
+ @Rule
+ public TestName name = new TestName();
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
private PluginInstaller extractor;
private DefaultServerFileSystem fileSystem;
private File homeDir;
private Server server = mock(Server.class);
private UpdateCenterMatrixFactory updateCenterMatrixFactory;
- @Rule
- public TestName name = new TestName();
-
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
@Before
public void start() {
when(server.getVersion()).thenReturn("3.1");
deployDir = TestUtils.getTestTempDir(PluginDeployerTest.class, name.getMethodName() + "/deploy");
fileSystem = new DefaultServerFileSystem(null, homeDir, deployDir);
extractor = new PluginInstaller();
- // TODO
- deployer = new PluginDeployer(server, fileSystem, extractor, null);
+ deployer = new PluginDeployer(server, fileSystem, extractor);
}
@Test
deployer.start();
}
- @Test(expected = ServerStartException.class)
+ @Test(expected = IllegalStateException.class)
public void failIfTwoPluginsWithSameKey() {
deployer.start();
}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.server.plugins;
+
+import org.junit.Test;
+import org.sonar.api.platform.PluginMetadata;
+import org.sonar.core.plugins.DefaultPluginMetadata;
+import org.sonar.updatecenter.common.PluginReferential;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class PluginReferentialMetadataConverterTest {
+
+ @Test
+ public void should_convert_metadata_to_plugin_referential() {
+ PluginMetadata metadata = mock(DefaultPluginMetadata.class);
+ when(metadata.getKey()).thenReturn("foo");
+ when(metadata.getRequiredPlugins()).thenReturn(new String []{});
+
+ PluginReferential pluginReferential = PluginReferentialMetadataConverter.getInstalledPluginReferential(newArrayList(metadata));
+ assertThat(pluginReferential).isNotNull();
+ assertThat(pluginReferential.getPlugins()).hasSize(1);
+ assertThat(pluginReferential.getPlugins().get(0).getKey()).isEqualTo("foo");
+ }
+
+ @Test
+ public void should_not_add_core_plugin() {
+ PluginMetadata metadata = mock(DefaultPluginMetadata.class);
+ when(metadata.getKey()).thenReturn("foo");
+ when(metadata.getRequiredPlugins()).thenReturn(new String []{});
+ when(metadata.isCore()).thenReturn(true);
+
+ PluginReferential pluginReferential = PluginReferentialMetadataConverter.getInstalledPluginReferential(newArrayList(metadata));
+ assertThat(pluginReferential).isNotNull();
+ assertThat(pluginReferential.getPlugins()).hasSize(0);
+ }
+}