From: Julien Lancelot Date: Fri, 25 Aug 2017 08:36:56 +0000 (+0200) Subject: SONAR-9616 Use AnalysisMetadataHolder when loading settings in CE X-Git-Tag: 6.6-RC1~380^2~47 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=58dd97f09938a63a5f78dd7d099aa42fc50d21fa;p=sonarqube.git SONAR-9616 Use AnalysisMetadataHolder when loading settings in CE --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepositoryImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepositoryImpl.java index cbc8df1bb9e..044f53eb7bb 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepositoryImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepositoryImpl.java @@ -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; - 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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepositoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepositoryTest.java index 26fe4fddfdc..7a71722af5a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepositoryTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepositoryTest.java @@ -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();