]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9616 Use AnalysisMetadataHolder when loading settings in CE
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 25 Aug 2017 08:36:56 +0000 (10:36 +0200)
committerJanos Gyerik <janos.gyerik@sonarsource.com>
Tue, 12 Sep 2017 09:34:53 +0000 (11:34 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepositoryImpl.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepositoryTest.java

index cbc8df1bb9e746a42252cef15256adca577568d7..044f53eb7bb602c3914758839f63cc93673645df 100644 (file)
@@ -22,8 +22,8 @@ package org.sonar.server.computation.task.projectanalysis.component;
 import com.google.common.base.Supplier;
 import com.google.common.base.Suppliers;
 import org.sonar.api.config.Configuration;
-import org.sonar.ce.queue.CeTask;
 import org.sonar.ce.settings.ProjectConfigurationFactory;
+import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
 
 /**
  * Repository of component settings implementation based on a memory cache.
@@ -32,11 +32,8 @@ public class ConfigurationRepositoryImpl implements ConfigurationRepository {
 
   private final Supplier<Configuration> configuration;
 
-  public ConfigurationRepositoryImpl(CeTask ceTask, ProjectConfigurationFactory f) {
-    // project key is loaded from task because
-    // analysisMetadataHolder.getProject() may be not set yet
-    // when the first ComputationSteps are executed.
-    this.configuration = Suppliers.memoize(() -> f.newProjectConfiguration(ceTask.getComponentKey()));
+  public ConfigurationRepositoryImpl(AnalysisMetadataHolder analysisMetadataHolder, ProjectConfigurationFactory f) {
+    this.configuration = Suppliers.memoize(() -> f.newProjectConfiguration(analysisMetadataHolder.getProject().getKey()));
   }
 
   @Override
index 26fe4fddfdc8bad7aba12a4b663a6190b09ea242..7a71722af5ac077a0c2ae5d77519ddd1e4e74c8f 100644 (file)
@@ -24,34 +24,27 @@ import org.junit.Test;
 import org.sonar.api.config.Configuration;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.System2;
-import org.sonar.ce.queue.CeTask;
 import org.sonar.ce.settings.ProjectConfigurationFactory;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
-import org.sonar.db.ce.CeTaskTypes;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.property.PropertyDto;
+import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
+import org.sonar.server.computation.task.projectanalysis.analysis.Project;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.PROJECT;
 
 public class ConfigurationRepositoryTest {
 
-  private static final Component ROOT = ReportComponent.builder(PROJECT, 1).setKey("ROOT").build();
-  private static final CeTask TASK = new CeTask.Builder()
-    .setOrganizationUuid("foo")
-    .setUuid("bar")
-    .setType(CeTaskTypes.REPORT)
-    .setComponentUuid(ROOT.getUuid())
-    .setComponentKey(ROOT.getKey())
-    .build();
+  private static Project PROJECT = new Project("UUID", "KEY", "NAME");
 
   @Rule
   public final DbTester db = DbTester.create(System2.INSTANCE);
 
   private DbClient dbClient = db.getDbClient();
   private MapSettings globalSettings = new MapSettings();
-  private ConfigurationRepository underTest = new ConfigurationRepositoryImpl(TASK, new ProjectConfigurationFactory(globalSettings, dbClient));
+  private AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule().setProject(PROJECT);
+  private ConfigurationRepository underTest = new ConfigurationRepositoryImpl(analysisMetadataHolder, new ProjectConfigurationFactory(globalSettings, dbClient));
 
   @Test
   public void get_project_settings_from_global_settings() {
@@ -64,7 +57,7 @@ public class ConfigurationRepositoryTest {
 
   @Test
   public void get_project_settings_from_db() {
-    ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey(ROOT.getKey()));
+    ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey(PROJECT.getKey()));
     insertProjectProperty(project, "key", "value");
 
     Configuration config = underTest.getConfiguration();
@@ -86,7 +79,7 @@ public class ConfigurationRepositoryTest {
   @Test
   public void project_settings_override_global_settings() {
     globalSettings.setProperty("key", "value1");
-    ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey(ROOT.getKey()));
+    ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey(PROJECT.getKey()));
     insertProjectProperty(project, "key", "value2");
 
     Configuration config = underTest.getConfiguration();
@@ -95,7 +88,7 @@ public class ConfigurationRepositoryTest {
 
   @Test
   public void project_settings_are_cached_to_avoid_db_access() {
-    ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey(ROOT.getKey()));
+    ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey(PROJECT.getKey()));
     insertProjectProperty(project, "key", "value");
 
     Configuration config = underTest.getConfiguration();