aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2016-07-21 12:05:01 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2016-07-21 12:05:01 +0200
commit06b01c8bf835a4e93066b789afefa8f82474aae9 (patch)
tree0cd4c214e5b403be677d8641593f28847ebab2ff
parent4598acad6328b240831f3ad1f00c7c07d124c07b (diff)
downloadsonarqube-06b01c8bf835a4e93066b789afefa8f82474aae9.tar.gz
sonarqube-06b01c8bf835a4e93066b789afefa8f82474aae9.zip
Update Xoo plugin to test Settings default values
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/Xoo.java15
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java9
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java4
3 files changed, 21 insertions, 7 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/Xoo.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/Xoo.java
index ab9a6547de3..0f4c272b1ba 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/Xoo.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/Xoo.java
@@ -19,17 +19,22 @@
*/
package org.sonar.xoo;
+import java.util.Arrays;
+import org.sonar.api.config.Settings;
import org.sonar.api.resources.Language;
public class Xoo implements Language {
public static final String KEY = "xoo";
public static final String NAME = "Xoo";
- public static final String FILE_SUFFIX = ".xoo";
+ public static final String FILE_SUFFIXES_KEY = "sonar.xoo.file.suffixes";
+ public static final String DEFAULT_FILE_SUFFIXES = ".xoo";
- private static final String[] XOO_SUFFIXES = {
- FILE_SUFFIX
- };
+ private final Settings settings;
+
+ public Xoo(Settings settings) {
+ this.settings = settings;
+ }
@Override
public String getKey() {
@@ -43,6 +48,6 @@ public class Xoo implements Language {
@Override
public String[] getFileSuffixes() {
- return XOO_SUFFIXES;
+ return Arrays.stream(settings.getStringArray(FILE_SUFFIXES_KEY)).filter(s -> s != null && !s.trim().isEmpty()).toArray(String[]::new);
}
}
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 9b443628856..7cc594aa958 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
@@ -21,6 +21,8 @@ package org.sonar.xoo;
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.xoo.coverage.ItCoverageSensor;
import org.sonar.xoo.coverage.OverallCoverageSensor;
import org.sonar.xoo.coverage.UtCoverageSensor;
@@ -73,6 +75,13 @@ public class XooPlugin implements Plugin {
@Override
public void define(Context context) {
context.addExtensions(
+ PropertyDefinition.builder(Xoo.FILE_SUFFIXES_KEY)
+ .defaultValue(Xoo.DEFAULT_FILE_SUFFIXES)
+ .name("File suffixes")
+ .description("Comma-separated list of suffixes for files to analyze. To not filter, leave the list empty.")
+ .subCategory("General")
+ .onQualifiers(Qualifiers.PROJECT)
+ .build(),
Xoo.class,
Xoo2.class,
XooRulesDefinition.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 6a0507af8d1..3d72a69bd42 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
@@ -35,10 +35,10 @@ public class XooPluginTest {
public void provide_extensions_for_5_5() {
Plugin.Context context = new Plugin.Context(new SonarRuntime(Version.parse("5.5"), SonarProduct.SONARQUBE, SonarQubeSide.SCANNER));
new XooPlugin().define(context);
- assertThat(context.getExtensions()).hasSize(43).contains(CpdTokenizerSensor.class);
+ assertThat(context.getExtensions()).hasSize(44).contains(CpdTokenizerSensor.class);
context = new Plugin.Context(new SonarRuntime(Version.parse("5.4"), SonarProduct.SONARLINT, null));
new XooPlugin().define(context);
- assertThat(context.getExtensions()).hasSize(40).doesNotContain(CpdTokenizerSensor.class);
+ assertThat(context.getExtensions()).hasSize(41).doesNotContain(CpdTokenizerSensor.class);
}
}