aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-11-16 11:45:04 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-11-24 09:23:58 +0100
commit8143f375f15c83cbca11e1723aeca6f609299ca7 (patch)
tree69d2b2c41059b9a965a58697253039ada0f02629
parent013c10ada9d0e4328872914bb21749439cd7ae7f (diff)
downloadsonarqube-8143f375f15c83cbca11e1723aeca6f609299ca7.tar.gz
sonarqube-8143f375f15c83cbca11e1723aeca6f609299ca7.zip
SONAR-10065 persist properties sonar.pullRequest.* from analysis report
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistAnalysisPropertiesStep.java8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistAnalysisPropertiesStepTest.java48
2 files changed, 43 insertions, 13 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistAnalysisPropertiesStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistAnalysisPropertiesStep.java
index c85504e3755..0347875b1a3 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistAnalysisPropertiesStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistAnalysisPropertiesStep.java
@@ -31,11 +31,12 @@ import org.sonar.server.computation.task.step.ComputationStep;
/**
* Persist analysis properties
- * Only properties starting with "sonar.analysis" will be persisted in database
+ * Only properties starting with "sonar.analysis" or "sonar.pullrequest" will be persisted in database
*/
public class PersistAnalysisPropertiesStep implements ComputationStep {
private static final String SONAR_ANALYSIS = "sonar.analysis.";
+ private static final String SONAR_PULL_REQUEST = "sonar.pullrequest.";
private final DbClient dbClient;
private final AnalysisMetadataHolder analysisMetadataHolder;
@@ -55,10 +56,11 @@ public class PersistAnalysisPropertiesStep implements ComputationStep {
final List<AnalysisPropertyDto> analysisPropertyDtos = new ArrayList<>();
reportReader.readContextProperties().forEachRemaining(
contextProperty -> {
- if (contextProperty.getKey().startsWith(SONAR_ANALYSIS)) {
+ String propertyKey = contextProperty.getKey();
+ if (propertyKey.startsWith(SONAR_ANALYSIS) || propertyKey.startsWith(SONAR_PULL_REQUEST)) {
analysisPropertyDtos.add(new AnalysisPropertyDto()
.setUuid(uuidFactory.create())
- .setKey(contextProperty.getKey())
+ .setKey(propertyKey)
.setValue(contextProperty.getValue())
.setSnapshotUuid(analysisMetadataHolder.getUuid()));
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistAnalysisPropertiesStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistAnalysisPropertiesStepTest.java
index 26069ea64a8..5793ede23d0 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistAnalysisPropertiesStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/PersistAnalysisPropertiesStepTest.java
@@ -20,9 +20,9 @@
package org.sonar.server.computation.task.projectanalysis.step;
+import com.google.common.collect.ImmutableList;
import java.util.Arrays;
import java.util.List;
-import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.System2;
@@ -44,45 +44,73 @@ public class PersistAnalysisPropertiesStepTest {
private static final String SNAPSHOT_UUID = randomAlphanumeric(40);
private static final String SMALL_VALUE1 = randomAlphanumeric(50);
private static final String SMALL_VALUE2 = randomAlphanumeric(50);
+ private static final String SMALL_VALUE3 = randomAlphanumeric(50);
private static final String BIG_VALUE = randomAlphanumeric(5000);
+ private static final String VALUE_PREFIX_FOR_PR_PROPERTIES = "pr_";
private static final List<ScannerReport.ContextProperty> PROPERTIES = Arrays.asList(
newContextProperty("key1", "value1"),
newContextProperty("key2", "value1"),
newContextProperty("sonar.analysis", SMALL_VALUE1),
- newContextProperty("sonar.analysis.branch", SMALL_VALUE1),
+ newContextProperty("sonar.analysis.branch", SMALL_VALUE2),
newContextProperty("sonar.analysis.empty_string", ""),
newContextProperty("sonar.analysis.big_value", BIG_VALUE),
- newContextProperty("sonar.analysis.", SMALL_VALUE2));
+ newContextProperty("sonar.analysis.", SMALL_VALUE3),
+ newContextProperty("sonar.pullrequest", VALUE_PREFIX_FOR_PR_PROPERTIES + SMALL_VALUE1),
+ newContextProperty("sonar.pullrequest.branch", VALUE_PREFIX_FOR_PR_PROPERTIES + SMALL_VALUE2),
+ newContextProperty("sonar.pullrequest.empty_string", ""),
+ newContextProperty("sonar.pullrequest.big_value", VALUE_PREFIX_FOR_PR_PROPERTIES + BIG_VALUE),
+ newContextProperty("sonar.pullrequest.", VALUE_PREFIX_FOR_PR_PROPERTIES + SMALL_VALUE3));
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
private BatchReportReader batchReportReader = mock(BatchReportReader.class);
private AnalysisMetadataHolder analysisMetadataHolder = mock(AnalysisMetadataHolder.class);
- private PersistAnalysisPropertiesStep underTest = new PersistAnalysisPropertiesStep(dbTester.getDbClient(), analysisMetadataHolder, batchReportReader, UuidFactoryFast.getInstance());
+ private PersistAnalysisPropertiesStep underTest = new PersistAnalysisPropertiesStep(dbTester.getDbClient(), analysisMetadataHolder, batchReportReader,
+ UuidFactoryFast.getInstance());
@Test
- public void persist_should_store_only_sonarDotAnalysis_properties() {
+ public void persist_should_stores_sonarDotAnalysisDot_and_sonarDotPullRequestDot_properties() {
when(batchReportReader.readContextProperties()).thenReturn(CloseableIterator.from(PROPERTIES.iterator()));
when(analysisMetadataHolder.getUuid()).thenReturn(SNAPSHOT_UUID);
+
underTest.execute();
- assertThat(dbTester.countRowsOfTable("analysis_properties")).isEqualTo(4);
+ assertThat(dbTester.countRowsOfTable("analysis_properties")).isEqualTo(8);
List<AnalysisPropertyDto> propertyDtos = dbTester.getDbClient()
.analysisPropertiesDao().selectBySnapshotUuid(dbTester.getSession(), SNAPSHOT_UUID);
assertThat(propertyDtos)
.extracting(AnalysisPropertyDto::getSnapshotUuid, AnalysisPropertyDto::getKey, AnalysisPropertyDto::getValue)
.containsExactlyInAnyOrder(
- tuple(SNAPSHOT_UUID, "sonar.analysis.branch", SMALL_VALUE1),
+ tuple(SNAPSHOT_UUID, "sonar.analysis.branch", SMALL_VALUE2),
tuple(SNAPSHOT_UUID, "sonar.analysis.empty_string", ""),
tuple(SNAPSHOT_UUID, "sonar.analysis.big_value", BIG_VALUE),
- tuple(SNAPSHOT_UUID, "sonar.analysis.", SMALL_VALUE2)
- );
+ tuple(SNAPSHOT_UUID, "sonar.analysis.", SMALL_VALUE3),
+ tuple(SNAPSHOT_UUID, "sonar.pullrequest.branch", VALUE_PREFIX_FOR_PR_PROPERTIES + SMALL_VALUE2),
+ tuple(SNAPSHOT_UUID, "sonar.pullrequest.empty_string", ""),
+ tuple(SNAPSHOT_UUID, "sonar.pullrequest.big_value", VALUE_PREFIX_FOR_PR_PROPERTIES + BIG_VALUE),
+ tuple(SNAPSHOT_UUID, "sonar.pullrequest.", VALUE_PREFIX_FOR_PR_PROPERTIES + SMALL_VALUE3));
+ }
+
+ @Test
+ public void persist_filtering_of_properties_is_case_sensitive() {
+ when(batchReportReader.readContextProperties()).thenReturn(CloseableIterator.from(ImmutableList.of(
+ newContextProperty("sonar.ANALYSIS.foo", "foo"),
+ newContextProperty("sonar.anaLysis.bar", "bar"),
+ newContextProperty("sonar.anaLYSIS.doo", "doh"),
+ newContextProperty("sonar.PULLREQUEST.foo", "foo"),
+ newContextProperty("sonar.pullRequest.bar", "bar"),
+ newContextProperty("sonar.pullREQUEST.doo", "doh")).iterator()));
+ when(analysisMetadataHolder.getUuid()).thenReturn(SNAPSHOT_UUID);
+
+ underTest.execute();
+
+ assertThat(dbTester.countRowsOfTable("analysis_properties")).isEqualTo(0);
}
@Test
- public void persist_should_not_store_anything_if_there_is_no_sonarDotAnalysis_properties() {
+ public void persist_should_not_store_anything_if_there_is_no_context_properties() {
when(batchReportReader.readContextProperties()).thenReturn(CloseableIterator.emptyCloseableIterator());
when(analysisMetadataHolder.getUuid()).thenReturn(SNAPSHOT_UUID);