org.sonar.api.config.Configuration.getStringArray()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(13.8k)|赞(0)|评价(0)|浏览(139)

本文整理了Java中org.sonar.api.config.Configuration.getStringArray()方法的一些代码示例,展示了Configuration.getStringArray()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.getStringArray()方法的具体详情如下:
包路径:org.sonar.api.config.Configuration
类名称:Configuration
方法名:getStringArray

Configuration.getStringArray介绍

[英]Used to read multi-valued properties.

See PropertyDefinition.Builder#multiValues(boolean)Multi-valued properties coming from scanner are parsed as CSV lines (ie comma separator and optional double quotes to escape values). Non quoted values are trimmed and empty fields are ignored.
Examples :

  • "one,two,three " -> ["one", "two", "three"]
  • " one, two, three " -> ["one", "two", "three"]
  • "one, three" -> ["one", "three"]
  • "one,"", three" -> ["one", "", "three"]
  • "one, " " , three" -> ["one", " ", "three"]
  • "one,"two,three"," four "" -> ["one", "two,three", " four "]
    [中]用于读取多值属性。
    请参阅PropertyDefinition。生成器#来自扫描仪的多值(布尔)多值属性被解析为CSV行(即逗号分隔符和可选的双引号以转义值)。不带引号的值将被修剪,空字段将被忽略。
    示例:
    *“一、二、三”>[“一”、“二”、“三”]
    *“一、二、三”>[“一”、“二”、“三”]
    *“一,三”>[“一”,“三”]
    *“一”、“三”>[“一”、“三”]
    *“一”、“三”>[“一”、“三”]
    *“一”,“二,三”,“四”->[一”,“二,三”,“四]

代码示例

代码示例来源:origin: SonarSource/sonarqube

private String[] exclusions(String globalExclusionsProperty, String exclusionsProperty) {
  String[] globalExclusions = config.getStringArray(globalExclusionsProperty);
  String[] exclusions = config.getStringArray(exclusionsProperty);
  return Stream.concat(Arrays.stream(globalExclusions), Arrays.stream(exclusions))
   .map(StringUtils::trim)
   .toArray(String[]::new);
 }
}

代码示例来源:origin: SonarSource/sonarqube

private Set<String> loadReportPaths() {
 return Arrays.stream(config.getStringArray(REPORT_PATHS_PROPERTY_KEY)).collect(Collectors.toSet());
}

代码示例来源:origin: SonarSource/sonarqube

private String[] inclusions(String propertyKey) {
 return Arrays.stream(config.getStringArray(propertyKey))
  .map(StringUtils::trim)
  .filter(s -> !"**/*".equals(s))
  .filter(s -> !"file:**/*".equals(s))
  .toArray(String[]::new);
}

代码示例来源:origin: SonarSource/sonarqube

@Override
 public String[] getStringArray(String key) {
  return config.getConfiguration().getStringArray(key);
 }
};

代码示例来源:origin: SonarSource/sonarqube

public DebtRatingGrid(Configuration config) {
 try {
  String[] grades = config.getStringArray(RATING_GRID);
  gridValues = new double[4];
  for (int i = 0; i < 4; i++) {
   gridValues[i] = Double.parseDouble(grades[i]);
  }
  this.ratingBounds = buildRatingBounds(gridValues);
 } catch (Exception e) {
  throw new IllegalArgumentException("The rating grid is incorrect. Expected something similar to '"
   + RATING_GRID_DEF_VALUES + "' and got '" + config.get(RATING_GRID).orElse("") + "'", e);
 }
}

代码示例来源:origin: SonarSource/sonarqube

private static Map<String, LanguageSpecificConfiguration> initLanguageSpecificConfigurationByLanguageKey(Configuration config) {
 ImmutableMap.Builder<String, LanguageSpecificConfiguration> builder = ImmutableMap.builder();
 String[] languageConfigIndexes = config.getStringArray(LANGUAGE_SPECIFIC_PARAMETERS);
 for (String languageConfigIndex : languageConfigIndexes) {
  String languagePropertyKey = LANGUAGE_SPECIFIC_PARAMETERS + "." + languageConfigIndex + "." + LANGUAGE_SPECIFIC_PARAMETERS_LANGUAGE_KEY;
  String languageKey = config.get(languagePropertyKey)
   .orElseThrow(() -> MessageException.of("Technical debt configuration is corrupted. At least one language specific parameter has no Language key. " +
    "Contact your administrator to update this configuration in the global administration section of SonarQube."));
  builder.put(languageKey, LanguageSpecificConfiguration.create(config, languageConfigIndex));
 }
 return builder.build();
}

代码示例来源:origin: SonarSource/sonarqube

@VisibleForTesting
protected final void initPatterns() {
 // Patterns Multicriteria
 multicriteriaPatterns = new ArrayList<>();
 for (String id : settings.getStringArray(getMulticriteriaConfigurationKey())) {
  String propPrefix = getMulticriteriaConfigurationKey() + "." + id + ".";
  String filePathPattern = settings.get(propPrefix + "resourceKey").orElse(null);
  if (StringUtils.isBlank(filePathPattern)) {
   throw MessageException.of("Issue exclusions are misconfigured. File pattern is mandatory for each entry of '" + getMulticriteriaConfigurationKey() + "'");
  }
  String ruleKeyPattern = settings.get(propPrefix + "ruleKey").orElse(null);
  if (StringUtils.isBlank(ruleKeyPattern)) {
   throw MessageException.of("Issue exclusions are misconfigured. Rule key pattern is mandatory for each entry of '" + getMulticriteriaConfigurationKey() + "'");
  }
  IssuePattern pattern = new IssuePattern(firstNonNull(filePathPattern, "*"), firstNonNull(ruleKeyPattern, "*"));
  multicriteriaPatterns.add(pattern);
 }
}

代码示例来源:origin: SonarSource/sonarqube

private final void loadFileContentPatterns() {
 // Patterns Block
 blockPatterns = new ArrayList<>();
 for (String id : getSettings().getStringArray(IssueExclusionProperties.PATTERNS_BLOCK_KEY)) {
  String propPrefix = IssueExclusionProperties.PATTERNS_BLOCK_KEY + "." + id + ".";
  String beginBlockRegexp = getSettings().get(propPrefix + IssueExclusionProperties.BEGIN_BLOCK_REGEXP).orElse(null);
  if (StringUtils.isBlank(beginBlockRegexp)) {
   throw MessageException.of("Issue exclusions are misconfigured. Start block regexp is mandatory for each entry of '" + IssueExclusionProperties.PATTERNS_BLOCK_KEY + "'");
  }
  String endBlockRegexp = getSettings().get(propPrefix + IssueExclusionProperties.END_BLOCK_REGEXP).orElse(null);
  // As per configuration help, missing second field means: from start regexp to EOF
  BlockIssuePattern pattern = new BlockIssuePattern(nullToEmpty(beginBlockRegexp), nullToEmpty(endBlockRegexp));
  blockPatterns.add(pattern);
 }
 blockPatterns = Collections.unmodifiableList(blockPatterns);
 // Patterns All File
 allFilePatterns = new ArrayList<>();
 for (String id : getSettings().getStringArray(IssueExclusionProperties.PATTERNS_ALLFILE_KEY)) {
  String propPrefix = IssueExclusionProperties.PATTERNS_ALLFILE_KEY + "." + id + ".";
  String allFileRegexp = getSettings().get(propPrefix + IssueExclusionProperties.FILE_REGEXP).orElse(null);
  if (StringUtils.isBlank(allFileRegexp)) {
   throw MessageException.of("Issue exclusions are misconfigured. Remove blank entries from '" + IssueExclusionProperties.PATTERNS_ALLFILE_KEY + "'");
  }
  allFilePatterns.add(nullToEmpty(allFileRegexp));
 }
 allFilePatterns = Collections.unmodifiableList(allFilePatterns);
}

代码示例来源:origin: SonarSource/sonarqube

public LanguageDetection(Configuration settings, LanguagesRepository languages) {
 Map<String, PathPattern[]> patternsByLanguageBuilder = new LinkedHashMap<>();
 for (Language language : languages.all()) {
  String[] filePatterns = settings.getStringArray(getFileLangPatternPropKey(language.key()));
  PathPattern[] pathPatterns = PathPattern.create(filePatterns);
  if (pathPatterns.length > 0) {

代码示例来源:origin: SonarSource/sonarqube

private void getStringArrayBehaviorIsTheSame(Configuration configuration, String key) {
 assertThat(configuration.getStringArray(key))
  .isEqualTo(settings.getStringArray(key));
}

代码示例来源:origin: SonarSource/sonarqube

private void getStringArrayBehaviorDiffers(Configuration configuration, String key, String[] configurationExpected, String[] settingsExpected) {
 String[] conf = configuration.getStringArray(key);
 String[] sett = settings.getStringArray(key);
 assertThat(conf).isEqualTo(configurationExpected);
 assertThat(sett).isEqualTo(settingsExpected);
 assertThat(conf).isNotEqualTo(sett);
}

代码示例来源:origin: SonarSource/sonarqube

private void getStringArrayBehaviorDiffers(Configuration configuration, String key, String[] expected) {
 assertThat(configuration.getStringArray(key))
  .isEqualTo(expected)
  .isNotEqualTo(settings.getStringArray(key));
}

代码示例来源:origin: SonarSource/sonarqube

private void getStringArrayBehaviorIsTheSame(Configuration configuration, String key, String[] expected) {
 assertThat(configuration.getStringArray(key))
  .isEqualTo(expected)
  .isEqualTo(settings.getStringArray(key));
}

代码示例来源:origin: SonarSource/sonarqube

public EsClient provide(Configuration config) {
 if (cache == null) {
  Settings.Builder esSettings = Settings.builder();
  // mandatory property defined by bootstrap process
  esSettings.put("cluster.name", config.get(CLUSTER_NAME.getKey()).get());
  boolean clusterEnabled = config.getBoolean(CLUSTER_ENABLED.getKey()).orElse(false);
  boolean searchNode = !clusterEnabled || SEARCH.equals(NodeType.parse(config.get(CLUSTER_NODE_TYPE.getKey()).orElse(null)));
  final TransportClient nativeClient = new MinimalTransportClient(esSettings.build());
  if (clusterEnabled && !searchNode) {
   esSettings.put("client.transport.sniff", true);
   Arrays.stream(config.getStringArray(CLUSTER_SEARCH_HOSTS.getKey()))
    .map(HostAndPort::fromString)
    .forEach(h -> addHostToClient(h, nativeClient));
   LOGGER.info("Connected to remote Elasticsearch: [{}]", displayedAddresses(nativeClient));
  } else {
   HostAndPort host = HostAndPort.fromParts(config.get(SEARCH_HOST.getKey()).get(), config.getInt(SEARCH_PORT.getKey()).get());
   addHostToClient(host, nativeClient);
   LOGGER.info("Connected to local Elasticsearch: [{}]", displayedAddresses(nativeClient));
  }
  cache = new EsClient(nativeClient);
 }
 return cache;
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void getDefaultValues() {
 Configuration config = new DefaultConfiguration(new PropertyDefinitions(Arrays.asList(
  PropertyDefinition.builder("single").multiValues(false).defaultValue("default").build(),
  PropertyDefinition.builder("multiA").multiValues(true).defaultValue("foo,bar").build())), new Encryption(null),
  ImmutableMap.of()) {
 };
 assertThat(config.get("multiA")).hasValue("foo,bar");
 assertThat(config.getStringArray("multiA")).containsExactly("foo", "bar");
 assertThat(config.get("single")).hasValue("default");
 assertThat(config.getStringArray("single")).containsExactly("default");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void accessingMultiValuedPropertiesShouldBeConsistentWithDeclaration() {
 Configuration config = new DefaultConfiguration(new PropertyDefinitions(Arrays.asList(
  PropertyDefinition.builder("single").multiValues(false).build(),
  PropertyDefinition.builder("multiA").multiValues(true).build())), new Encryption(null),
  ImmutableMap.of("single", "foo", "multiA", "a,b", "notDeclared", "c,d")) {
 };
 assertThat(config.get("multiA")).hasValue("a,b");
 assertThat(logTester.logs(LoggerLevel.WARN))
  .contains(
   "Access to the multi-values/property set property 'multiA' should be made using 'getStringArray' method. The SonarQube plugin using this property should be updated.");
 logTester.clear();
 assertThat(config.getStringArray("single")).containsExactly("foo");
 assertThat(logTester.logs(LoggerLevel.WARN))
  .contains(
   "Property 'single' is not declared as multi-values/property set but was read using 'getStringArray' method. The SonarQube plugin declaring this property should be updated.");
 logTester.clear();
 assertThat(config.get("notDeclared")).hasValue("c,d");
 assertThat(config.getStringArray("notDeclared")).containsExactly("c", "d");
 assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void accessingPropertySetPropertiesShouldBeConsistentWithDeclaration() {
 Configuration config = new DefaultConfiguration(new PropertyDefinitions(Arrays.asList(
  PropertyDefinition.builder("props").fields(PropertyFieldDefinition.build("foo1").name("Foo1").build(), PropertyFieldDefinition.build("foo2").name("Foo2").build()).build())),
  new Encryption(null),
  ImmutableMap.of("props", "1,2", "props.1.foo1", "a", "props.1.foo2", "b")) {
 };
 assertThat(config.get("props")).hasValue("1,2");
 assertThat(logTester.logs(LoggerLevel.WARN))
  .contains(
   "Access to the multi-values/property set property 'props' should be made using 'getStringArray' method. The SonarQube plugin using this property should be updated.");
 logTester.clear();
 assertThat(config.getStringArray("props")).containsExactly("1", "2");
 assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty();
}

代码示例来源:origin: org.sonarsource.flex/sonar-flex-plugin

/**
 * {@inheritDoc}
 */
@Override
public String[] getFileSuffixes() {
 String[] suffixes = filterEmptyStrings(config.getStringArray(FlexPlugin.FILE_SUFFIXES_KEY));
 if (suffixes.length == 0) {
  suffixes = StringUtils.split(DEFAULT_FILE_SUFFIXES, ",");
 }
 return suffixes;
}

代码示例来源:origin: SonarSource/SonarJS

@Override
public void execute(SensorContext context) {
 String[] reports = context.config().getStringArray(JavaScriptPlugin.LCOV_REPORT_PATHS);
 List<String> reportPaths = Lists.newArrayList(reports);
 if (!reportPaths.isEmpty()) {
  saveMeasureFromLCOVFile(context, reportPaths);
 }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-server

private static Map<String, LanguageSpecificConfiguration> initLanguageSpecificConfigurationByLanguageKey(Configuration config) {
 ImmutableMap.Builder<String, LanguageSpecificConfiguration> builder = ImmutableMap.builder();
 String[] languageConfigIndexes = config.getStringArray(LANGUAGE_SPECIFIC_PARAMETERS);
 for (String languageConfigIndex : languageConfigIndexes) {
  String languagePropertyKey = LANGUAGE_SPECIFIC_PARAMETERS + "." + languageConfigIndex + "." + LANGUAGE_SPECIFIC_PARAMETERS_LANGUAGE_KEY;
  String languageKey = config.get(languagePropertyKey)
   .orElseThrow(() -> MessageException.of("Technical debt configuration is corrupted. At least one language specific parameter has no Language key. " +
    "Contact your administrator to update this configuration in the global administration section of SonarQube."));
  builder.put(languageKey, LanguageSpecificConfiguration.create(config, languageConfigIndex));
 }
 return builder.build();
}

相关文章