use of org.sonar.api.batch.rule.internal.NewActiveRule in project sonarlint-core by SonarSource.
the class StandaloneActiveRulesProvider method registerProfile.
private static void registerProfile(ActiveRulesBuilder builder, String language, Map.Entry<String, Collection<RulesProfile>> entry) {
for (RulesProfile rp : entry.getValue()) {
for (ActiveRule ar : rp.getActiveRules()) {
NewActiveRule newAr = builder.create(RuleKey.of(ar.getRepositoryKey(), ar.getRuleKey())).setLanguage(language).setName(ar.getRule().getName()).setSeverity(ar.getSeverity().name()).setInternalKey(ar.getConfigKey());
for (ActiveRuleParam param : ar.getActiveRuleParams()) {
newAr.setParam(param.getKey(), param.getValue());
}
newAr.activate();
}
}
}
use of org.sonar.api.batch.rule.internal.NewActiveRule in project sonarlint-core by SonarSource.
the class SonarQubeActiveRulesProvider method createNewActiveRule.
private static void createNewActiveRule(ActiveRulesBuilder builder, ActiveRule activeRule, Sonarlint.Rules storageRules, String language, Rules rules) {
RuleKey ruleKey = RuleKey.of(activeRule.getRepo(), activeRule.getKey());
Rule rule = rules.find(ruleKey);
Sonarlint.Rules.Rule storageRule;
try {
storageRule = storageRules.getRulesByKeyOrThrow(ruleKey.toString());
} catch (IllegalArgumentException e) {
throw new MessageException("Unknown active rule in the quality profile of the project. Please update the SonarQube server binding.");
}
NewActiveRule newActiveRule = builder.create(ruleKey).setLanguage(language).setName(rule.name()).setInternalKey(rule.internalKey()).setSeverity(activeRule.getSeverity());
if (!StringUtils.isEmpty(storageRule.getTemplateKey())) {
RuleKey templateRuleKey = RuleKey.parse(storageRule.getTemplateKey());
newActiveRule.setTemplateRuleKey(templateRuleKey.rule());
}
for (Map.Entry<String, String> param : activeRule.getParamsMap().entrySet()) {
newActiveRule.setParam(param.getKey(), param.getValue());
}
newActiveRule.activate();
}
use of org.sonar.api.batch.rule.internal.NewActiveRule in project sonar-web by SonarSource.
the class WebSensorTest method setUp.
@Before
public void setUp() throws Exception {
WebRulesDefinition rulesDefinition = new WebRulesDefinition();
RulesDefinition.Context context = new RulesDefinition.Context();
rulesDefinition.define(context);
RulesDefinition.Repository repository = context.repository(WebRulesDefinition.REPOSITORY_KEY);
List<NewActiveRule> ar = new ArrayList<>();
for (RulesDefinition.Rule rule : repository.rules()) {
ar.add(new ActiveRulesBuilder().create(RuleKey.of(WebRulesDefinition.REPOSITORY_KEY, rule.key())));
}
ActiveRules activeRules = new DefaultActiveRules(ar);
CheckFactory checkFactory = new CheckFactory(activeRules);
FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class);
when(fileLinesContextFactory.createFor(Mockito.any(InputFile.class))).thenReturn(mock(FileLinesContext.class));
sensor = new WebSensor(new NoSonarFilter(), fileLinesContextFactory, checkFactory);
tester = SensorContextTester.create(TEST_DIR);
}
use of org.sonar.api.batch.rule.internal.NewActiveRule in project sonarqube by SonarSource.
the class ActiveRulesProvider method transform.
private static ActiveRules transform(Collection<LoadedActiveRule> loadedRules) {
ActiveRulesBuilder builder = new ActiveRulesBuilder();
for (LoadedActiveRule activeRule : loadedRules) {
NewActiveRule newActiveRule = builder.create(activeRule.getRuleKey());
newActiveRule.setName(activeRule.getName());
newActiveRule.setSeverity(activeRule.getSeverity());
newActiveRule.setCreatedAt(activeRule.getCreatedAt());
newActiveRule.setLanguage(activeRule.getLanguage());
newActiveRule.setInternalKey(activeRule.getInternalKey());
newActiveRule.setTemplateRuleKey(activeRule.getTemplateRuleKey());
// load parameters
if (activeRule.getParams() != null) {
for (Map.Entry<String, String> params : activeRule.getParams().entrySet()) {
newActiveRule.setParam(params.getKey(), params.getValue());
}
}
newActiveRule.activate();
}
return builder.build();
}
use of org.sonar.api.batch.rule.internal.NewActiveRule in project sonarqube by SonarSource.
the class ActiveRulesPublisherTest method write.
@Test
public void write() throws Exception {
File outputDir = temp.newFolder();
ScannerReportWriter writer = new ScannerReportWriter(outputDir);
NewActiveRule ar = new ActiveRulesBuilder().create(RuleKey.of("java", "S001")).setSeverity("BLOCKER").setParam("p1", "v1");
ActiveRules activeRules = new DefaultActiveRules(Arrays.asList(ar));
ActiveRulesPublisher underTest = new ActiveRulesPublisher(activeRules);
underTest.publish(writer);
ScannerReportReader reader = new ScannerReportReader(outputDir);
try (CloseableIterator<ScannerReport.ActiveRule> readIt = reader.readActiveRules()) {
ScannerReport.ActiveRule reportAr = readIt.next();
assertThat(reportAr.getRuleRepository()).isEqualTo("java");
assertThat(reportAr.getRuleKey()).isEqualTo("S001");
assertThat(reportAr.getSeverity()).isEqualTo(Constants.Severity.BLOCKER);
assertThat(reportAr.getParamsByKey()).hasSize(1);
assertThat(reportAr.getParamsByKey().entrySet().iterator().next().getKey()).isEqualTo("p1");
assertThat(reportAr.getParamsByKey().entrySet().iterator().next().getValue()).isEqualTo("v1");
assertThat(readIt.hasNext()).isFalse();
}
}
Aggregations