From c5f3ff40749fb8eeb1d953571420b62f04d2aee5 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Mon, 7 Jul 2014 13:09:36 +0200 Subject: [PATCH] SONAR-5007 fix removal of param value --- .../server/qualityprofile/RuleActivator.java | 16 +++++----- .../java/org/sonar/server/search/ESNode.java | 30 ++++++++----------- .../RuleActivatorMediumTest.java | 6 ++-- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java index 9c6e935c196..2fb2b565d6d 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java @@ -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; } } diff --git a/sonar-server/src/main/java/org/sonar/server/search/ESNode.java b/sonar-server/src/main/java/org/sonar/server/search/ESNode.java index 0bf101085f8..f568a09c97e 100644 --- a/sonar-server/src/main/java/org/sonar/server/search/ESNode.java +++ b/sonar-server/src/main/java/org/sonar/server/search/ESNode.java @@ -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"); diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java index 5d55a161de7..cf4cd585bff 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java @@ -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 -- 2.39.5