import org.sonar.api.ExtensionPoint;
import org.sonar.api.ce.ComputeEngineSide;
+import org.sonar.api.config.Configuration;
import org.sonar.ce.task.projectanalysis.analysis.Branch;
/**
Branch getBranch();
+ Configuration getConfiguration();
}
- class PreMeasuresComputationCheckException extends Exception {
+ class PreMeasuresComputationCheckException extends RuntimeException {
public PreMeasuresComputationCheckException(String message) {
super(message);
}
*/
package org.sonar.ce.task.projectanalysis.measure;
+import org.sonar.api.config.Configuration;
import org.sonar.api.utils.System2;
import org.sonar.ce.task.log.CeTaskMessages;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.ce.task.projectanalysis.analysis.Branch;
+import org.sonar.ce.task.projectanalysis.component.ConfigurationRepository;
import org.sonar.ce.task.step.ComputationStep;
import org.sonar.db.dismissmessage.MessageType;
private final AnalysisMetadataHolder analysisMetadataHolder;
private final PreMeasuresComputationCheck[] extensions;
private final CeTaskMessages ceTaskMessages;
+ private final ConfigurationRepository configurationRepository;
- public PreMeasuresComputationChecksStep(AnalysisMetadataHolder analysisMetadataHolder, CeTaskMessages ceTaskMessages, PreMeasuresComputationCheck... extensions) {
+ public PreMeasuresComputationChecksStep(
+ AnalysisMetadataHolder analysisMetadataHolder, CeTaskMessages ceTaskMessages,
+ ConfigurationRepository configurationRepository, PreMeasuresComputationCheck... extensions) {
this.analysisMetadataHolder = analysisMetadataHolder;
this.ceTaskMessages = ceTaskMessages;
+ this.configurationRepository = configurationRepository;
this.extensions = extensions;
}
return analysisMetadataHolder.getBranch();
}
+ @Override
+ public Configuration getConfiguration() {
+ return configurationRepository.getConfiguration();
+ }
+
}
}
*/
package org.sonar.ce.task.projectanalysis.measure;
+import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.sonar.ce.task.log.CeTaskMessages;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
import org.sonar.ce.task.projectanalysis.analysis.Branch;
+import org.sonar.ce.task.projectanalysis.component.ConfigurationRepository;
import org.sonar.ce.task.projectanalysis.measure.PreMeasuresComputationCheck.Context;
import org.sonar.ce.task.step.TestComputationStepContext;
import org.sonar.db.component.BranchType;
public AnalysisMetadataHolderRule analysisMetadataHolder = mock();
public CeTaskMessages ceTaskMessages = mock();
+ public ConfigurationRepository configurationRepository = mock();
+
+ @Before
+ public void setup() {
+
+ }
@Test
public void execute_extensions() throws PreMeasuresComputationCheckException {
private PreMeasuresComputationChecksStep newStep(PreMeasuresComputationCheck... preMeasuresComputationChecks) {
if (preMeasuresComputationChecks.length == 0) {
- return new PreMeasuresComputationChecksStep(analysisMetadataHolder, ceTaskMessages);
+ return new PreMeasuresComputationChecksStep(analysisMetadataHolder, ceTaskMessages, configurationRepository);
}
- return new PreMeasuresComputationChecksStep(analysisMetadataHolder, ceTaskMessages, preMeasuresComputationChecks);
+ return new PreMeasuresComputationChecksStep(analysisMetadataHolder, ceTaskMessages, configurationRepository, preMeasuresComputationChecks);
}
private void mockBranch(String branchName) {
insertProperty("global.two", "two", null, null, null, null, null);
List<PropertyDto> properties = underTest.selectGlobalProperties(db.getSession());
- assertThat(properties.size())
- .isEqualTo(2);
+ assertThat(properties)
+ .hasSize(2);
assertThat(findByKey(properties, "global.one"))
.extracting(PropertyDto::getKey, PropertyDto::getEntityUuid, PropertyDto::getUserUuid, PropertyDto::getValue)
assertThat(property)
.extracting(PropertyDto::getKey, PropertyDto::getEntityUuid, PropertyDto::getUserUuid, PropertyDto::getValue)
.containsExactly("project.one", "uuid10", null, "one");
+
+ assertThat(underTest.selectProjectProperty("uuid10", "project.one"))
+ .isPresent()
+ .contains(property);
}
@Test
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
return getMapper(dbSession).selectByKey(new PropertyDto().setKey(propertyKey).setEntityUuid(projectUuid));
}
+ public Optional<PropertyDto> selectProjectProperty(String projectUuid, String propertyKey) {
+ try (DbSession session = mybatis.openSession(false)) {
+ return Optional.ofNullable(selectProjectProperty(session, projectUuid, propertyKey));
+ }
+ }
+
public List<PropertyDto> selectByQuery(PropertyQuery query, DbSession session) {
return getMapper(session).selectByQuery(query);
}