]> source.dussan.org Git - sonarqube.git/commitdiff
Removed ServerStartException to remove dependency cycle between packages
authorJulien Lancelot <julien.lancelot@gmail.com>
Wed, 20 Feb 2013 08:01:02 +0000 (09:01 +0100)
committerJulien Lancelot <julien.lancelot@gmail.com>
Wed, 20 Feb 2013 08:01:02 +0000 (09:01 +0100)
14 files changed:
sonar-server/src/main/java/org/sonar/server/database/EmbeddedDatabase.java
sonar-server/src/main/java/org/sonar/server/platform/DefaultServerFileSystem.java
sonar-server/src/main/java/org/sonar/server/platform/Platform.java
sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java
sonar-server/src/main/java/org/sonar/server/platform/ServerStartException.java [deleted file]
sonar-server/src/main/java/org/sonar/server/plugins/InstalledPluginReferentialFactory.java
sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java
sonar-server/src/main/java/org/sonar/server/plugins/PluginReferentialMetadataConverter.java
sonar-server/src/main/java/org/sonar/server/startup/RegisterMetrics.java
sonar-server/src/test/java/org/sonar/server/platform/DefaultServerFileSystemTest.java
sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java
sonar-server/src/test/java/org/sonar/server/plugins/InstalledPluginReferentialFactoryTest.java [new file with mode: 0644]
sonar-server/src/test/java/org/sonar/server/plugins/PluginDeployerTest.java
sonar-server/src/test/java/org/sonar/server/plugins/PluginReferentialMetadataConverterTest.java [new file with mode: 0644]

index 75fa1e40fb5ba719d62190e956e761bf8ef45a1d..98e292d83113f33d27f1898012a2159ff8ead860 100644 (file)
@@ -19,9 +19,8 @@
  */
 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;
@@ -29,7 +28,6 @@ import org.sonar.api.CoreProperties;
 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;
@@ -37,7 +35,6 @@ import java.sql.SQLException;
 
 public class EmbeddedDatabase {
   private static final Logger LOG = LoggerFactory.getLogger(EmbeddedDatabase.class);
-
   private final Settings settings;
   private Server server;
 
@@ -45,6 +42,20 @@ public class EmbeddedDatabase {
     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()) {
@@ -94,18 +105,4 @@ public class EmbeddedDatabase {
     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");
-  }
 }
index 53d17dc6960e7f48f8911289e5ebf8ad6f13ab8e..93aa23fa21f70a58a103d41f36fda00201068f87 100644 (file)
@@ -71,11 +71,11 @@ public class DefaultServerFileSystem implements ServerFileSystem {
   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 {
@@ -86,7 +86,7 @@ public class DefaultServerFileSystem implements ServerFileSystem {
       }
 
     } 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();
@@ -95,7 +95,7 @@ public class DefaultServerFileSystem implements ServerFileSystem {
       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);
     }
   }
 
@@ -132,10 +132,10 @@ public class DefaultServerFileSystem implements ServerFileSystem {
     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);
   }
index d7cf11cc662f63aca547c0d89b3c4d6c8d733bfb..6ac06599096f0ef0126b33d8fef1660ead1e9810 100644 (file)
@@ -46,7 +46,14 @@ import org.sonar.core.measure.MeasureFilterExecutor;
 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;
@@ -70,12 +77,37 @@ import org.sonar.server.database.EmbeddedDatabaseFactory;
 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;
 
@@ -151,7 +183,6 @@ public final class Platform {
       rootContainer.addSingleton(daoClass);
     }
     rootContainer.addSingleton(PluginDeployer.class);
-    rootContainer.addSingleton(PluginReferentialMetadataConverter.class);
     rootContainer.addSingleton(InstalledPluginReferentialFactory.class);
     rootContainer.addSingleton(DefaultServerPluginRepository.class);
 
index fc01c7a72791af03bad32c83ad6e3a856290deef..3efc441bb17921404bcde065915c125be15ea6e6 100644 (file)
@@ -66,13 +66,13 @@ public final class ServerImpl extends Server {
       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);
     }
   }
 
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/ServerStartException.java b/sonar-server/src/main/java/org/sonar/server/platform/ServerStartException.java
deleted file mode 100644 (file)
index afe4f09..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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);
-  }
-}
index 44e76877a136ac111a6ce1c87b36c5a7fc1f8858..88d7d72e6a355821a0d5014ab4a33b62fe209db5 100644 (file)
@@ -21,25 +21,22 @@ package org.sonar.server.plugins;
 
 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);
     }
   }
 
@@ -48,7 +45,7 @@ public class InstalledPluginReferentialFactory implements ServerComponent {
   }
 
   private void init() {
-    installedPluginReferential = pluginReferentialMetadataConverter.getInstalledPluginReferential(pluginRepository.getMetadata());
+    installedPluginReferential = PluginReferentialMetadataConverter.getInstalledPluginReferential(pluginRepository.getMetadata());
   }
 
 }
index f8aed096ab96f8d1c9c3a46ed7d9959cc462f302..66fd02d0fcb0c16cf422d2c8452bf79af6ede5c0 100644 (file)
@@ -35,7 +35,6 @@ import org.sonar.api.utils.TimeProfiler;
 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;
@@ -52,17 +51,15 @@ public class PluginDeployer implements ServerComponent {
   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() {
@@ -105,7 +102,7 @@ public class PluginDeployer implements ServerComponent {
     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());
     }
 
@@ -231,6 +228,6 @@ public class PluginDeployer implements ServerComponent {
   }
 
   private PluginReferential getPluginReferential() {
-    return pluginReferentialMetadataConverter.getInstalledPluginReferential(getMetadata());
+    return PluginReferentialMetadataConverter.getInstalledPluginReferential(getMetadata());
   }
 }
index ceccc02d24df2283dec44a3f1146b868ee7713e0..4e2373de6ebe06432e4a00c6741bd54a19998f3f 100644 (file)
@@ -19,7 +19,6 @@
  */
 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;
@@ -30,14 +29,18 @@ import java.util.List;
 
 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()) {
@@ -47,7 +50,7 @@ public class PluginReferentialMetadataConverter implements ServerComponent {
     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());
index 91a9b9fb09aaec3b8b027d61ea83c8066d416c6a..e8a56196f70c8d7cedfda11fe70ac08423b31b9c 100644 (file)
@@ -29,9 +29,9 @@ import org.sonar.api.profiles.Alert;
 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;
 
@@ -70,11 +70,11 @@ public class RegisterMetrics {
     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);
     }
index 8c67db52fc4dcbd9a8fa77bd5ebbbbc23ac4efc9..0517eed62e492cd26fe8da5e953ea4aa9ab83c4e 100644 (file)
@@ -45,7 +45,7 @@ public class DefaultServerFileSystemTest {
     assertNotNull(driver);
   }
 
-  @Test(expected = ServerStartException.class)
+  @Test(expected = IllegalStateException.class)
   public void failIfJdbcDriverNotFound() {
     Database database = mock(Database.class);
 
@@ -89,7 +89,7 @@ public class DefaultServerFileSystemTest {
     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();
index ced9e9d6925fa3f3598943570fec034f1c2672d7..e4f22e22ed782fc79e48a9b73f249fe8e84f0c0f 100644 (file)
@@ -68,7 +68,7 @@ public class ServerImplTest {
 
   @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");
@@ -77,7 +77,7 @@ public class ServerImplTest {
 
   @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");
@@ -86,7 +86,7 @@ public class ServerImplTest {
 
   @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");
diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/InstalledPluginReferentialFactoryTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/InstalledPluginReferentialFactoryTest.java
new file mode 100644 (file)
index 0000000..b4f2ade
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * 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();
+  }
+}
index 6b62130f06f5201c00afc0b2b4b95b0708a96350..f7e55612dde2cb01ea6ff5d5f74dd8a3126d9ecf 100644 (file)
@@ -28,7 +28,6 @@ import org.sonar.api.platform.PluginMetadata;
 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;
@@ -39,6 +38,10 @@ import static org.mockito.Mockito.when;
 
 public class PluginDeployerTest {
 
+  @Rule
+  public TestName name = new TestName();
+  @Rule
+  public ExpectedException exception = ExpectedException.none();
   private PluginInstaller extractor;
   private DefaultServerFileSystem fileSystem;
   private File homeDir;
@@ -47,12 +50,6 @@ public class PluginDeployerTest {
   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");
@@ -60,8 +57,7 @@ public class PluginDeployerTest {
     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
@@ -118,7 +114,7 @@ public class PluginDeployerTest {
     deployer.start();
   }
 
-  @Test(expected = ServerStartException.class)
+  @Test(expected = IllegalStateException.class)
   public void failIfTwoPluginsWithSameKey() {
     deployer.start();
   }
diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/PluginReferentialMetadataConverterTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/PluginReferentialMetadataConverterTest.java
new file mode 100644 (file)
index 0000000..5e64559
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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);
+  }
+}