]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 fix removal of param value
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 7 Jul 2014 11:09:36 +0000 (13:09 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 7 Jul 2014 11:09:58 +0000 (13:09 +0200)
sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java
sonar-server/src/main/java/org/sonar/server/search/ESNode.java
sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java

index 9c6e935c1968c575e5941cb46d02d897a96d656e..2fb2b565d6dccf07e63b59dd9ca35e07a39184b5 100644 (file)
@@ -164,25 +164,25 @@ public class RuleActivator implements ServerComponent {
   private void applySeverityAndParamToChange(RuleActivation request, RuleActivatorContext context, ActiveRuleChange change) {
     if (request.isReset()) {
       // load severity and params from parent profile, else from default values
-      change.setSeverity(firstNonEmpty(
+      change.setSeverity(firstNonNull(
         context.parentSeverity(), context.defaultSeverity()));
       for (RuleParamDto ruleParamDto : context.ruleParams()) {
         String paramKey = ruleParamDto.getName();
-        change.setParameter(paramKey, validateParam(ruleParamDto, firstNonEmpty(
+        change.setParameter(paramKey, validateParam(ruleParamDto, firstNonNull(
           context.parentParamValue(paramKey), context.defaultParamValue(paramKey))));
       }
 
     } else if (context.activeRule() != null) {
       // already activated -> load severity and parameters from request, else keep existing ones, else from parent,
       // else from default
-      change.setSeverity(firstNonEmpty(
+      change.setSeverity(firstNonNull(
         request.getSeverity(),
         context.currentSeverity(),
         context.parentSeverity(),
         context.defaultSeverity()));
       for (RuleParamDto ruleParamDto : context.ruleParams()) {
         String paramKey = ruleParamDto.getName();
-        change.setParameter(paramKey, validateParam(ruleParamDto, firstNonEmpty(
+        change.setParameter(paramKey, validateParam(ruleParamDto, firstNonNull(
           context.requestParamValue(request, paramKey),
           context.currentParamValue(paramKey),
           context.parentParamValue(paramKey),
@@ -191,13 +191,13 @@ public class RuleActivator implements ServerComponent {
 
     } else if (context.activeRule() == null) {
       // not activated -> load severity and parameters from request, else from parent, else from defaults
-      change.setSeverity(firstNonEmpty(
+      change.setSeverity(firstNonNull(
         request.getSeverity(),
         context.parentSeverity(),
         context.defaultSeverity()));
       for (RuleParamDto ruleParamDto : context.ruleParams()) {
         String paramKey = ruleParamDto.getName();
-        change.setParameter(paramKey, validateParam(ruleParamDto, firstNonEmpty(
+        change.setParameter(paramKey, validateParam(ruleParamDto, firstNonNull(
           context.requestParamValue(request, paramKey),
           context.parentParamValue(paramKey),
           context.defaultParamValue(paramKey))));
@@ -206,9 +206,9 @@ public class RuleActivator implements ServerComponent {
   }
 
   @CheckForNull
-  String firstNonEmpty(String... strings) {
+  String firstNonNull(String... strings) {
     for (String s : strings) {
-      if (StringUtils.isNotEmpty(s)) {
+      if (s!=null) {
         return s;
       }
     }
index 0bf101085f8cfad59934c17e7eabdbe79f7898a3..f568a09c97e02cc9aa11f3b27482ea1408249527 100644 (file)
@@ -23,7 +23,6 @@ package org.sonar.server.search;
 import com.google.common.annotations.VisibleForTesting;
 import org.apache.commons.io.FileUtils;
 import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
-import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse;
 import org.elasticsearch.client.Client;
 import org.elasticsearch.common.logging.ESLoggerFactory;
 import org.elasticsearch.common.logging.slf4j.Slf4jESLoggerFactory;
@@ -112,13 +111,11 @@ public class ESNode implements Startable {
       .node();
     node.start();
 
-
-    if (
-      node.client().admin().cluster().prepareHealth()
-        .setWaitForYellowStatus()
-        .setTimeout(healthTimeout)
-        .get()
-        .getStatus() == ClusterHealthStatus.RED) {
+    if (node.client().admin().cluster().prepareHealth()
+      .setWaitForYellowStatus()
+      .setTimeout(healthTimeout)
+      .get()
+      .getStatus() == ClusterHealthStatus.RED) {
       throw new IllegalStateException(
         String.format("Elasticsearch index is corrupt, please delete directory '%s/%s' and relaunch the SonarQube server.", fileSystem.getHomeDir().getAbsolutePath(), DATA_DIR));
     }
@@ -174,41 +171,40 @@ public class ESNode implements Startable {
     esSettings
       .put("index.mapper.dynamic", false)
 
-        // Sortable text analyzer
+      // Sortable text analyzer
       .put("index.analysis.analyzer.sortable.type", "custom")
       .put("index.analysis.analyzer.sortable.tokenizer", "keyword")
       .putArray("index.analysis.analyzer.sortable.filter", "trim", "lowercase", "truncate")
 
-        // Edge NGram index-analyzer
+      // Edge NGram index-analyzer
       .put("index.analysis.analyzer.index_grams.type", "custom")
       .put("index.analysis.analyzer.index_grams.tokenizer", "whitespace")
       .putArray("index.analysis.analyzer.index_grams.filter", "trim", "lowercase", "gram_filter")
 
-        // Edge NGram search-analyzer
+      // Edge NGram search-analyzer
       .put("index.analysis.analyzer.search_grams.type", "custom")
       .put("index.analysis.analyzer.search_grams.tokenizer", "whitespace")
       .putArray("index.analysis.analyzer.search_grams.filter", "trim", "lowercase")
 
-        // Word index-analyzer
+      // Word index-analyzer
       .put("index.analysis.analyzer.index_words.type", "custom")
       .put("index.analysis.analyzer.index_words.tokenizer", "standard")
       .putArray("index.analysis.analyzer.index_words.filter",
         "standard", "word_filter", "lowercase", "stop", "asciifolding", "porter_stem")
 
-        // Word search-analyzer
+      // Word search-analyzer
       .put("index.analysis.analyzer.search_words.type", "custom")
       .put("index.analysis.analyzer.search_words.tokenizer", "standard")
       .putArray("index.analysis.analyzer.search_words.filter",
         "standard", "lowercase", "stop", "asciifolding", "porter_stem")
 
-
-        // Edge NGram filter
+      // Edge NGram filter
       .put("index.analysis.filter.gram_filter.type", "edgeNGram")
       .put("index.analysis.filter.gram_filter.min_gram", 2)
       .put("index.analysis.filter.gram_filter.max_gram", 15)
       .putArray("index.analysis.filter.gram_filter.token_chars", "letter", "digit", "punctuation", "symbol")
 
-        // Word filter
+      // Word filter
       .put("index.analysis.filter.word_filter.type", "word_delimiter")
       .put("index.analysis.filter.word_filter.generate_word_parts", true)
       .put("index.analysis.filter.word_filter.catenate_words", true)
@@ -219,7 +215,7 @@ public class ESNode implements Startable {
       .put("index.analysis.filter.word_filter.split_on_numerics", true)
       .put("index.analysis.filter.word_filter.stem_english_possessive", true)
 
-        // Path Analyzer
+      // Path Analyzer
       .put("index.analysis.analyzer.path_analyzer.type", "custom")
       .put("index.analysis.analyzer.path_analyzer.tokenizer", "path_hierarchy");
 
index 5d55a161de7ed817ab464dee4af5339564ecf333..cf4cd585bff6bd8670f5a59b3b671b765fb483f2 100644 (file)
@@ -245,14 +245,16 @@ public class RuleActivatorMediumTest {
     RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
     activation.setSeverity(Severity.BLOCKER);
     activation.setParameter("max", "7");
+    activation.setParameter("min", "3");
     activate(activation, XOO_P1_KEY);
 
     // update without any severity or params = reset
     RuleActivation update = new RuleActivation(RuleTesting.XOO_X1).setReset(true);
     activate(update, XOO_P1_KEY);
-
     assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
-    verifyHasActiveRule(activeRuleKey, Severity.MINOR, null, ImmutableMap.of("max", "10"));
+    verifyHasActiveRule(activeRuleKey, Severity.MINOR, null,
+      // only default values
+      ImmutableMap.of("max", "10"));
   }
 
   @Test