aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2016-03-24 15:53:36 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2016-03-30 11:42:16 +0200
commit10955ec396a053d596a40ac3fdf7ca73dd911327 (patch)
treec390cd08b8b44656206306c94213204baeec737c /sonar-scanner-engine
parent946a448c08ccc10ad1c0af778ae5d9f179655ef8 (diff)
downloadsonarqube-10955ec396a053d596a40ac3fdf7ca73dd911327.tar.gz
sonarqube-10955ec396a053d596a40ac3fdf7ca73dd911327.zip
SONAR-7458 Expose SQ Version in SensorContext
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java4
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java6
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java12
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/sensor/DefaultSensorContextTest.java7
4 files changed, 22 insertions, 7 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
index ea6e967da42..dcc80d2fff5 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
@@ -22,6 +22,7 @@ package org.sonar.batch.bootstrap;
import java.util.List;
import java.util.Map;
import org.sonar.api.Plugin;
+import org.sonar.api.internal.SonarQubeVersionFactory;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.UriReader;
import org.sonar.batch.cache.GlobalPersistentCacheProvider;
@@ -39,7 +40,6 @@ import org.sonar.core.platform.PluginClassloaderFactory;
import org.sonar.core.platform.PluginInfo;
import org.sonar.core.platform.PluginLoader;
import org.sonar.core.platform.PluginRepository;
-import org.sonar.core.platform.SonarQubeVersionProvider;
import org.sonar.core.util.DefaultHttpDownloader;
import org.sonar.core.util.UuidFactoryImpl;
@@ -90,7 +90,7 @@ public class GlobalContainer extends ComponentContainer {
BatchPluginPredicate.class,
ExtensionInstaller.class,
- new SonarQubeVersionProvider(),
+ SonarQubeVersionFactory.create(System2.INSTANCE),
CachesManager.class,
GlobalSettings.class,
new BatchWsClientProvider(),
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java
index 33a56f3e5ee..91a61dfa3d3 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java
@@ -23,6 +23,7 @@ import java.io.Serializable;
import java.util.Collection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.sonar.api.SonarQubeVersion;
import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.SonarIndex;
@@ -55,9 +56,8 @@ public class DeprecatedSensorContext extends DefaultSensorContext implements Sen
private final CoverageExclusions coverageFilter;
public DeprecatedSensorContext(InputModule module, SonarIndex index, Project project, Settings settings, FileSystem fs, ActiveRules activeRules,
- AnalysisMode analysisMode, CoverageExclusions coverageFilter,
- SensorStorage sensorStorage) {
- super(module, settings, fs, activeRules, analysisMode, sensorStorage);
+ AnalysisMode analysisMode, CoverageExclusions coverageFilter, SensorStorage sensorStorage, SonarQubeVersion sqVersion) {
+ super(module, settings, fs, activeRules, analysisMode, sensorStorage, sqVersion);
this.index = index;
this.project = project;
this.coverageFilter = coverageFilter;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java
index e0a61eb9117..48dde9fd12d 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java
@@ -20,6 +20,7 @@
package org.sonar.batch.sensor;
import java.io.Serializable;
+import org.sonar.api.SonarQubeVersion;
import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputModule;
@@ -37,6 +38,7 @@ import org.sonar.api.batch.sensor.issue.internal.DefaultIssue;
import org.sonar.api.batch.sensor.measure.NewMeasure;
import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
import org.sonar.api.config.Settings;
+import org.sonar.api.utils.Version;
import org.sonar.batch.sensor.noop.NoOpNewCpdTokens;
import org.sonar.batch.sensor.noop.NoOpNewHighlighting;
@@ -51,14 +53,17 @@ public class DefaultSensorContext implements SensorContext {
private final SensorStorage sensorStorage;
private final AnalysisMode analysisMode;
private final InputModule module;
+ private final SonarQubeVersion sqVersion;
- public DefaultSensorContext(InputModule module, Settings settings, FileSystem fs, ActiveRules activeRules, AnalysisMode analysisMode, SensorStorage sensorStorage) {
+ public DefaultSensorContext(InputModule module, Settings settings, FileSystem fs, ActiveRules activeRules, AnalysisMode analysisMode, SensorStorage sensorStorage,
+ SonarQubeVersion sqVersion) {
this.module = module;
this.settings = settings;
this.fs = fs;
this.activeRules = activeRules;
this.analysisMode = analysisMode;
this.sensorStorage = sensorStorage;
+ this.sqVersion = sqVersion;
}
@Override
@@ -82,6 +87,11 @@ public class DefaultSensorContext implements SensorContext {
}
@Override
+ public Version getSonarQubeVersion() {
+ return sqVersion.get();
+ }
+
+ @Override
public <G extends Serializable> NewMeasure<G> newMeasure() {
return new DefaultMeasure<>(sensorStorage);
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/sensor/DefaultSensorContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/sensor/DefaultSensorContextTest.java
index ba40858840d..913a5fa67bc 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/sensor/DefaultSensorContextTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/sensor/DefaultSensorContextTest.java
@@ -24,6 +24,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
+import org.sonar.api.SonarQubeVersion;
import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.fs.InputModule;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
@@ -33,6 +34,7 @@ import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
import org.sonar.api.batch.sensor.internal.SensorStorage;
import org.sonar.api.config.Settings;
import org.sonar.api.measures.CoreMetrics;
+import org.sonar.api.utils.Version;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -52,6 +54,7 @@ public class DefaultSensorContextTest {
private Settings settings;
private SensorStorage sensorStorage;
private AnalysisMode analysisMode;
+ private SonarQubeVersion sqVersion;
@Before
public void prepare() throws Exception {
@@ -63,7 +66,8 @@ public class DefaultSensorContextTest {
settings = new Settings();
sensorStorage = mock(SensorStorage.class);
analysisMode = mock(AnalysisMode.class);
- adaptor = new DefaultSensorContext(mock(InputModule.class), settings, fs, activeRules, analysisMode, sensorStorage);
+ sqVersion = new SonarQubeVersion(Version.parse("5.5"));
+ adaptor = new DefaultSensorContext(mock(InputModule.class), settings, fs, activeRules, analysisMode, sensorStorage, sqVersion);
}
@Test
@@ -71,6 +75,7 @@ public class DefaultSensorContextTest {
assertThat(adaptor.activeRules()).isEqualTo(activeRules);
assertThat(adaptor.fileSystem()).isEqualTo(fs);
assertThat(adaptor.settings()).isEqualTo(settings);
+ assertThat(adaptor.getSonarQubeVersion()).isEqualTo(Version.parse("5.5"));
assertThat(adaptor.newIssue()).isNotNull();
assertThat(adaptor.newMeasure()).isNotNull();