aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-xoo-plugin
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-07-27 17:48:35 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-07-27 18:23:48 +0200
commit85bfbe28689b4276a04eeeed91b205ab76e81d06 (patch)
tree87805c76ff4f940d3bfc694dcd59d0f0da78a2eb /plugins/sonar-xoo-plugin
parent79a6209eaccbc7c92631fcb14752bd149f030b28 (diff)
downloadsonarqube-85bfbe28689b4276a04eeeed91b205ab76e81d06.tar.gz
sonarqube-85bfbe28689b4276a04eeeed91b205ab76e81d06.zip
Improve org.sonar.api.SonarRuntime
* javadoc was not up-to-date * SensorContext has a single method #runtime() instead of #getRuntimeApiVersion() and #getRuntimeProduct() * deprecated SonarQubeVersion does not extend SonarRuntime * SonarRuntime becomes an interface. Implementation is org.sonar.api.internal.SonarRuntimeImpl for unit tests.
Diffstat (limited to 'plugins/sonar-xoo-plugin')
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java7
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java17
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java4
3 files changed, 16 insertions, 12 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java
index 7cc594aa958..06925832258 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java
@@ -23,6 +23,7 @@ import org.sonar.api.Plugin;
import org.sonar.api.SonarProduct;
import org.sonar.api.config.PropertyDefinition;
import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.utils.Version;
import org.sonar.xoo.coverage.ItCoverageSensor;
import org.sonar.xoo.coverage.OverallCoverageSensor;
import org.sonar.xoo.coverage.UtCoverageSensor;
@@ -65,8 +66,6 @@ import org.sonar.xoo.scm.XooScmProvider;
import org.sonar.xoo.test.CoveragePerTestSensor;
import org.sonar.xoo.test.TestExecutionSensor;
-import static org.sonar.api.SonarRuntime.V5_5;
-
/**
* Plugin entry-point, as declared in pom.xml.
*/
@@ -140,12 +139,12 @@ public class XooPlugin implements Plugin {
XooProjectBuilder.class,
XooPostJob.class);
- if (context.getRuntimeProduct() != SonarProduct.SONARLINT) {
+ if (context.getRuntime().getProduct() != SonarProduct.SONARLINT) {
context.addExtensions(MeasureSensor.class,
DeprecatedResourceApiSensor.class);
}
- if (context.getSonarQubeVersion().isGreaterThanOrEqual(V5_5)) {
+ if (context.getRuntime().getApiVersion().isGreaterThanOrEqual(Version.create(5, 5))) {
context.addExtension(CpdTokenizerSensor.class);
}
}
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java
index 3d72a69bd42..03d8f037c4b 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java
@@ -21,9 +21,9 @@ package org.sonar.xoo;
import org.junit.Test;
import org.sonar.api.Plugin;
-import org.sonar.api.SonarProduct;
import org.sonar.api.SonarQubeSide;
import org.sonar.api.SonarRuntime;
+import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.utils.Version;
import org.sonar.xoo.lang.CpdTokenizerSensor;
@@ -32,13 +32,18 @@ import static org.assertj.core.api.Assertions.assertThat;
public class XooPluginTest {
@Test
- public void provide_extensions_for_5_5() {
- Plugin.Context context = new Plugin.Context(new SonarRuntime(Version.parse("5.5"), SonarProduct.SONARQUBE, SonarQubeSide.SCANNER));
+ public void provide_extensions_for_5_4() {
+ SonarRuntime runtime = SonarRuntimeImpl.forSonarLint(Version.parse("5.4"));
+ Plugin.Context context = new Plugin.Context(runtime);
new XooPlugin().define(context);
- assertThat(context.getExtensions()).hasSize(44).contains(CpdTokenizerSensor.class);
+ assertThat(context.getExtensions()).hasSize(41).doesNotContain(CpdTokenizerSensor.class);
+ }
- context = new Plugin.Context(new SonarRuntime(Version.parse("5.4"), SonarProduct.SONARLINT, null));
+ @Test
+ public void provide_extensions_for_5_5() {
+ SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("5.5"), SonarQubeSide.SCANNER);
+ Plugin.Context context = new Plugin.Context(runtime);
new XooPlugin().define(context);
- assertThat(context.getExtensions()).hasSize(41).doesNotContain(CpdTokenizerSensor.class);
+ assertThat(context.getExtensions()).hasSize(44).contains(CpdTokenizerSensor.class);
}
}
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java
index e709e31831f..263eb23f625 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java
@@ -23,13 +23,13 @@ import java.io.IOException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.sonar.api.SonarProduct;
import org.sonar.api.SonarQubeSide;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.rule.Severity;
import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
import org.sonar.api.batch.sensor.internal.SensorContextTester;
import org.sonar.api.batch.sensor.issue.Issue;
+import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.utils.Version;
import org.sonar.xoo.Xoo;
@@ -106,7 +106,7 @@ public class OneIssuePerLineSensorTest {
SensorContextTester context = SensorContextTester.create(temp.newFolder());
context.fileSystem().add(inputFile);
context.settings().setProperty(OneIssuePerLineSensor.EFFORT_TO_FIX_PROPERTY, "1.2");
- context.setRuntime(Version.parse("5.4"), SonarProduct.SONARQUBE, SonarQubeSide.SCANNER);
+ context.setRuntime(SonarRuntimeImpl.forSonarQube(Version.parse("5.4"), SonarQubeSide.SCANNER));
sensor.execute(context);