use of org.sonar.api.config.Configuration in project sonarqube by SonarSource.
the class DefaultConfigurationTest method accessingPropertySetPropertiesShouldBeConsistentWithDeclaration.
@Test
public void accessingPropertySetPropertiesShouldBeConsistentWithDeclaration() {
Configuration config = new DefaultConfiguration(new PropertyDefinitions(System2.INSTANCE, Arrays.asList(PropertyDefinition.builder("props").fields(PropertyFieldDefinition.build("foo1").name("Foo1").build(), PropertyFieldDefinition.build("foo2").name("Foo2").build()).build())), new Encryption(null), ImmutableMap.of("props", "1,2", "props.1.foo1", "a", "props.1.foo2", "b")) {
};
assertThat(config.get("props")).hasValue("1,2");
assertThat(logTester.logs(LoggerLevel.WARN)).contains("Access to the multi-values/property set property 'props' should be made using 'getStringArray' method. The SonarQube plugin using this property should be updated.");
logTester.clear();
assertThat(config.getStringArray("props")).containsExactly("1", "2");
assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty();
}
use of org.sonar.api.config.Configuration in project sonarqube by SonarSource.
the class DefaultConfigurationTest method getDefaultValues.
@Test
public void getDefaultValues() {
Configuration config = new DefaultConfiguration(new PropertyDefinitions(System2.INSTANCE, Arrays.asList(PropertyDefinition.builder("single").multiValues(false).defaultValue("default").build(), PropertyDefinition.builder("multiA").multiValues(true).defaultValue("foo,bar").build())), new Encryption(null), ImmutableMap.of()) {
};
assertThat(config.get("multiA")).hasValue("foo,bar");
assertThat(config.getStringArray("multiA")).containsExactly("foo", "bar");
assertThat(config.get("single")).hasValue("default");
assertThat(config.getStringArray("single")).containsExactly("default");
}
use of org.sonar.api.config.Configuration in project sonarqube by SonarSource.
the class CoreExtensionsInstallerTest method install_provides_Configuration_from_container_when_getBootConfiguration_is_called.
@Test
public void install_provides_Configuration_from_container_when_getBootConfiguration_is_called() {
CoreExtension coreExtension1 = newCoreExtension();
CoreExtension coreExtension2 = newCoreExtension();
when(coreExtensionRepository.loadedCoreExtensions()).thenReturn(Stream.of(coreExtension1, coreExtension2));
Configuration configuration = new MapSettings().asConfig();
ExtensionContainer container = mock(ExtensionContainer.class);
when(container.getComponentByType(Configuration.class)).thenReturn(configuration);
underTest.install(container, noExtensionFilter(), noAdditionalSideFilter());
verify(coreExtension1).load(contextCaptor.capture());
verify(coreExtension2).load(contextCaptor.capture());
assertThat(contextCaptor.getAllValues()).extracting(CoreExtension.Context::getBootConfiguration).containsOnly(configuration);
}
use of org.sonar.api.config.Configuration in project sonar-java by SonarSource.
the class JavaSquidSensorTest method createSonarComponentsMock.
private static SonarComponents createSonarComponentsMock(SensorContextTester contextTester) {
Configuration settings = new MapSettings().asConfig();
DefaultFileSystem fs = contextTester.fileSystem();
JavaTestClasspath javaTestClasspath = new JavaTestClasspath(settings, fs);
JavaClasspath javaClasspath = new JavaClasspath(settings, fs);
FileLinesContext fileLinesContext = mock(FileLinesContext.class);
FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class);
when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(fileLinesContext);
SonarComponents sonarComponents = spy(new SonarComponents(fileLinesContextFactory, fs, javaClasspath, javaTestClasspath, checkFactory));
sonarComponents.setSensorContext(contextTester);
BadMethodNameCheck check = new BadMethodNameCheck();
when(sonarComponents.checkClasses()).thenReturn(new JavaCheck[] { check });
return sonarComponents;
}
use of org.sonar.api.config.Configuration in project sonarqube by SonarSource.
the class LiveMeasureComputerImpl method refreshComponentsOnSameProject.
private Optional<QGChangeEvent> refreshComponentsOnSameProject(DbSession dbSession, List<ComponentDto> touchedComponents) {
// load all the components to be refreshed, including their ancestors
List<ComponentDto> components = loadTreeOfComponents(dbSession, touchedComponents);
ComponentDto branchComponent = findBranchComponent(components);
BranchDto branch = loadBranch(dbSession, branchComponent);
ProjectDto project = loadProject(dbSession, branch.getProjectUuid());
Optional<SnapshotDto> lastAnalysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, branchComponent.uuid());
if (!lastAnalysis.isPresent()) {
return Optional.empty();
}
QualityGate qualityGate = qGateComputer.loadQualityGate(dbSession, project, branch);
Collection<String> metricKeys = getKeysOfAllInvolvedMetrics(qualityGate);
List<MetricDto> metrics = dbClient.metricDao().selectByKeys(dbSession, metricKeys);
Map<String, MetricDto> metricsPerId = metrics.stream().collect(uniqueIndex(MetricDto::getUuid));
List<String> componentUuids = components.stream().map(ComponentDto::uuid).collect(toArrayList(components.size()));
List<LiveMeasureDto> dbMeasures = dbClient.liveMeasureDao().selectByComponentUuidsAndMetricUuids(dbSession, componentUuids, metricsPerId.keySet());
// previous status must be load now as MeasureMatrix mutate the LiveMeasureDto which are passed to it
Metric.Level previousStatus = loadPreviousStatus(metrics, dbMeasures);
Configuration config = projectConfigurationLoader.loadProjectConfiguration(dbSession, branchComponent);
DebtRatingGrid debtRatingGrid = new DebtRatingGrid(config);
MeasureMatrix matrix = new MeasureMatrix(components, metricsPerId.values(), dbMeasures);
FormulaContextImpl context = new FormulaContextImpl(matrix, debtRatingGrid);
long beginningOfLeak = getBeginningOfLeakPeriod(lastAnalysis, branch);
components.forEach(c -> {
IssueCounter issueCounter = new IssueCounter(dbClient.issueDao().selectIssueGroupsByBaseComponent(dbSession, c, beginningOfLeak));
for (IssueMetricFormula formula : formulaFactory.getFormulas()) {
// use formulas when the leak period is defined, it's a PR, or the formula is not about the leak period
if (shouldUseLeakFormulas(lastAnalysis.get(), branch) || !formula.isOnLeak()) {
context.change(c, formula);
try {
formula.compute(context, issueCounter);
} catch (RuntimeException e) {
throw new IllegalStateException("Fail to compute " + formula.getMetric().getKey() + " on " + context.getComponent().getDbKey(), e);
}
}
}
});
EvaluatedQualityGate evaluatedQualityGate = qGateComputer.refreshGateStatus(branchComponent, qualityGate, matrix, config);
// persist the measures that have been created or updated
matrix.getChanged().sorted(LiveMeasureComparator.INSTANCE).forEach(m -> dbClient.liveMeasureDao().insertOrUpdate(dbSession, m));
projectIndexer.commitAndIndexComponents(dbSession, singleton(branchComponent), ProjectIndexer.Cause.MEASURE_CHANGE);
return Optional.of(new QGChangeEvent(project, branch, lastAnalysis.get(), config, previousStatus, () -> Optional.of(evaluatedQualityGate)));
}
Aggregations