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),
} 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))));
}
@CheckForNull
- String firstNonEmpty(String... strings) {
+ String firstNonNull(String... strings) {
for (String s : strings) {
- if (StringUtils.isNotEmpty(s)) {
+ if (s!=null) {
return s;
}
}
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;
.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));
}
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)
.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");
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