use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class CheckFactoryTest method fail_if_missing_field.
@Test
public void fail_if_missing_field() {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("The field 'unknown' does not exist or is not annotated with @RuleProperty in the class org.sonar.api.batch.rule.CheckWithStringProperty");
RuleKey ruleKey = RuleKey.of("squid", "org.sonar.api.batch.rule.CheckWithStringProperty");
builder.create(ruleKey).setParam("unknown", "foo").activate();
CheckFactory checkFactory = new CheckFactory(builder.build());
checkFactory.create("squid").addAnnotatedChecks(CheckWithStringProperty.class);
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class CheckFactoryTest method use_template_rule_key.
@Test
public void use_template_rule_key() {
RuleKey ruleKey = RuleKey.of("squid", "S0001_123");
builder.create(ruleKey).setTemplateRuleKey("S0001").activate();
CheckFactory checkFactory = new CheckFactory(builder.build());
Checks checks = checkFactory.create("squid").addAnnotatedChecks(CheckWithKey.class);
Object check = checks.of(ruleKey);
assertThat(check).isInstanceOf(CheckWithKey.class);
assertThat(checks.of(ruleKey)).isSameAs(check);
assertThat(checks.ruleKey(check)).isEqualTo(ruleKey);
assertThat(checks.all()).containsOnly(check);
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class CheckFactoryTest method param_as_inherited_field.
/**
* SONAR-3164
*/
@Test
public void param_as_inherited_field() {
RuleKey ruleKey = RuleKey.of("squid", "org.sonar.api.batch.rule.CheckWithPrimitiveProperties");
builder.create(ruleKey).setParam("max", "300").activate();
CheckFactory checkFactory = new CheckFactory(builder.build());
Checks checks = checkFactory.create("squid").addAnnotatedChecks(CheckWithPrimitiveProperties.class);
Object check = checks.of(ruleKey);
assertThat(check).isInstanceOf(CheckWithPrimitiveProperties.class);
assertThat(((CheckWithPrimitiveProperties) check).getMax()).isEqualTo(300);
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class DefaultActiveRulesLoader method readPage.
private static List<LoadedActiveRule> readPage(SearchResponse response) {
List<LoadedActiveRule> loadedRules = new LinkedList<>();
List<Rule> rulesList = response.getRulesList();
Map<String, ActiveList> actives = response.getActives().getActives();
for (Rule r : rulesList) {
ActiveList activeList = actives.get(r.getKey());
Active active = activeList.getActiveList(0);
LoadedActiveRule loadedRule = new LoadedActiveRule();
loadedRule.setRuleKey(RuleKey.parse(r.getKey()));
loadedRule.setName(r.getName());
loadedRule.setSeverity(active.getSeverity());
loadedRule.setCreatedAt(dateToLong(parseDateTime(active.getCreatedAt())));
loadedRule.setLanguage(r.getLang());
loadedRule.setInternalKey(r.getInternalKey());
if (r.hasTemplateKey()) {
RuleKey templateRuleKey = RuleKey.parse(r.getTemplateKey());
loadedRule.setTemplateRuleKey(templateRuleKey.rule());
}
Map<String, String> params = new HashMap<>();
for (Rules.Rule.Param param : r.getParams().getParamsList()) {
params.put(param.getKey(), param.getDefaultValue());
}
// overrides defaultValue if the key is the same
for (Param param : active.getParamsList()) {
params.put(param.getKey(), param.getValue());
}
loadedRule.setParams(params);
loadedRules.add(loadedRule);
}
return loadedRules;
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class JSONReport method writeJson.
@VisibleForTesting
void writeJson(Writer writer) {
try (JsonWriter json = JsonWriter.of(writer)) {
json.beginObject();
json.prop("version", server.getVersion());
Set<RuleKey> ruleKeys = new LinkedHashSet<>();
Set<String> userLogins = new LinkedHashSet<>();
writeJsonIssues(json, ruleKeys, userLogins);
writeJsonComponents(json);
writeJsonRules(json, ruleKeys);
writeUsers(json, userLogins);
json.endObject();
} catch (IOException e) {
throw new IllegalStateException("Unable to write JSON report", e);
}
}
Aggregations