Skip to content

Commit

Permalink
fix CustomCxxRulesDefinition, remove language
Browse files Browse the repository at this point in the history
- language is a leftover from having two plugins: one C, one C++
  • Loading branch information
guwirth committed Mar 5, 2024
1 parent 194b37a commit 6f76253
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.sonar.plugins.cxx;

import java.util.Arrays;
import org.sonar.api.resources.Language;
import org.sonar.api.scanner.ScannerSide;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.cxx.squidbridge.annotations.AnnotationBasedRulesDefinition;
Expand All @@ -34,23 +33,16 @@ public abstract class CustomCxxRulesDefinition implements RulesDefinition {

@Override
public void define(RulesDefinition.Context context) {
var repo = context.createRepository(repositoryKey(), getLanguage().getKey())
var repo = context.createRepository(repositoryKey(), CxxLanguage.KEY)
.setName(repositoryName());

// Load metadata from check classes' annotations
new AnnotationBasedRulesDefinition(repo, getLanguage().getKey()).addRuleClasses(false,
Arrays.asList(checkClasses()));
new AnnotationBasedRulesDefinition(repo, CxxLanguage.KEY).addRuleClasses(false,
Arrays.asList(checkClasses()));

repo.done();
}

/**
* Name of the custom rule repository.
*
* @return
*/
public abstract Language getLanguage();

/**
* Name of the custom rule repository.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@
import com.sonar.cxx.sslr.api.Grammar;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.resources.Language;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.check.Rule;
import org.sonar.check.RuleProperty;
import org.sonar.cxx.tag.Tag;
import org.sonar.cxx.squidbridge.checks.SquidCheck;
import org.sonar.cxx.tag.Tag;

class CustomCxxRulesDefinitionTest {

private static final Language LANGUAGE = new CxxLanguage(new MapSettings().asConfig());
private static final String REPOSITORY_NAME = "Custom Rule Repository";
private static final String REPOSITORY_KEY = "CustomRuleRepository";

Expand All @@ -47,7 +44,6 @@ void test() {
RulesDefinition.Repository repository = context.repository(REPOSITORY_KEY);

assertThat(repository.name()).isEqualTo(REPOSITORY_NAME);
assertThat(repository.language()).isEqualTo(LANGUAGE.getKey());
assertThat(repository.rules()).hasSize(1);

RulesDefinition.Rule alertUseRule = repository.rule(RULE_KEY);
Expand Down Expand Up @@ -80,10 +76,6 @@ public Class[] checkClasses() {
return new Class[]{MyCustomRule.class};
}

@Override
public Language getLanguage() {
return LANGUAGE;
}
}

@Rule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import org.sonar.api.batch.rule.CheckFactory;
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
import org.sonar.api.batch.rule.internal.NewActiveRule;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.resources.Language;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.check.Rule;
Expand Down Expand Up @@ -131,8 +129,6 @@ public static class MyCustomRule extends SquidCheck<Grammar> {

public static class MyCustomPlSqlRulesDefinition extends CustomCxxRulesDefinition {

private static final Language LANGUAGE = new CxxLanguage(new MapSettings().asConfig());

@Override
public String repositoryName() {
return "Custom Rule Repository";
Expand All @@ -149,10 +145,6 @@ public Class[] checkClasses() {
return new Class[]{MyCustomRule.class};
}

@Override
public Language getLanguage() {
return LANGUAGE;
}
}

}

0 comments on commit 6f76253

Please sign in to comment.