Search in sources :

Example 1 with RulesBuilder

use of org.sonar.api.batch.rule.internal.RulesBuilder in project sonarqube by SonarSource.

the class RulesProvider method load.

private static Rules load(RulesLoader ref) {
    Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
    List<Rule> loadedRules = ref.load();
    RulesBuilder builder = new RulesBuilder();
    for (Rule r : loadedRules) {
        NewRule newRule = builder.add(RuleKey.of(r.getRepository(), r.getKey()));
        newRule.setName(r.getName());
        newRule.setInternalKey(r.getInternalKey());
    }
    profiler.stopInfo();
    return builder.build();
}
Also used : Profiler(org.sonar.api.utils.log.Profiler) NewRule(org.sonar.api.batch.rule.internal.NewRule) Rule(org.sonarqube.ws.Rules.ListResponse.Rule) RulesBuilder(org.sonar.api.batch.rule.internal.RulesBuilder) NewRule(org.sonar.api.batch.rule.internal.NewRule)

Example 2 with RulesBuilder

use of org.sonar.api.batch.rule.internal.RulesBuilder in project sonarqube by SonarSource.

the class JSONReportTest method before.

@Before
public void before() throws Exception {
    moduleHierarchy = mock(InputModuleHierarchy.class);
    userRepository = mock(UserRepositoryLoader.class);
    File projectBaseDir = temp.newFolder();
    fs = new DefaultFileSystem(projectBaseDir.toPath());
    SIMPLE_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+02:00"));
    when(server.getVersion()).thenReturn("3.6");
    InputComponentStore inputComponentStore = new InputComponentStore(new PathResolver());
    DefaultComponentTree inputComponentTree = new DefaultComponentTree();
    DefaultInputModule rootModule = new DefaultInputModule(ProjectDefinition.create().setBaseDir(projectBaseDir).setKey("struts"), 1);
    inputComponentStore.put(rootModule);
    DefaultInputModule moduleA = new DefaultInputModule("struts-core");
    inputComponentTree.index(moduleA, rootModule);
    DefaultInputModule moduleB = new DefaultInputModule("struts-ui");
    inputComponentTree.index(moduleB, rootModule);
    DefaultInputDir inputDir = new DefaultInputDir("struts", "src/main/java/org/apache/struts", TestInputFileBuilder.nextBatchId()).setModuleBaseDir(projectBaseDir.toPath());
    DefaultInputFile inputFile = new TestInputFileBuilder("struts", "src/main/java/org/apache/struts/Action.java").setModuleBaseDir(projectBaseDir.toPath()).build();
    inputFile.setStatus(InputFile.Status.CHANGED);
    inputFile.setPublish(true);
    inputComponentStore.put(inputFile);
    inputComponentStore.put(inputDir);
    inputComponentTree.index(inputDir, rootModule);
    inputComponentTree.index(inputFile, inputDir);
    when(moduleHierarchy.children(rootModule)).thenReturn(Arrays.asList(moduleA, moduleB));
    when(moduleHierarchy.parent(moduleA)).thenReturn(rootModule);
    when(moduleHierarchy.parent(moduleB)).thenReturn(rootModule);
    when(moduleHierarchy.relativePath(moduleA)).thenReturn("core");
    when(moduleHierarchy.relativePath(moduleB)).thenReturn("ui");
    RulesBuilder builder = new RulesBuilder();
    builder.add(RuleKey.of("squid", "AvoidCycles")).setName("Avoid Cycles");
    rules = builder.build();
    jsonReport = new JSONReport(moduleHierarchy, settings, fs, server, rules, issueCache, rootModule, inputComponentStore, userRepository, inputComponentTree);
}
Also used : PathResolver(org.sonar.api.scan.filesystem.PathResolver) RulesBuilder(org.sonar.api.batch.rule.internal.RulesBuilder) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputModuleHierarchy(org.sonar.api.batch.fs.internal.InputModuleHierarchy) UserRepositoryLoader(org.sonar.scanner.repository.user.UserRepositoryLoader) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) InputComponentStore(org.sonar.scanner.scan.filesystem.InputComponentStore) DefaultComponentTree(org.sonar.scanner.scan.DefaultComponentTree) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) DefaultInputDir(org.sonar.api.batch.fs.internal.DefaultInputDir) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Before(org.junit.Before)

Example 3 with RulesBuilder

use of org.sonar.api.batch.rule.internal.RulesBuilder in project sonarqube by SonarSource.

the class RulesProvider method provide.

@Bean("Rules")
public Rules provide(RulesLoader ref) {
    Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
    List<Rule> loadedRules = ref.load();
    RulesBuilder builder = new RulesBuilder();
    for (Rule r : loadedRules) {
        NewRule newRule = builder.add(RuleKey.of(r.getRepository(), r.getKey()));
        newRule.setName(r.getName());
        newRule.setInternalKey(r.getInternalKey());
    }
    profiler.stopInfo();
    return builder.build();
}
Also used : Profiler(org.sonar.api.utils.log.Profiler) NewRule(org.sonar.api.batch.rule.internal.NewRule) Rule(org.sonarqube.ws.Rules.ListResponse.Rule) RulesBuilder(org.sonar.api.batch.rule.internal.RulesBuilder) NewRule(org.sonar.api.batch.rule.internal.NewRule) Bean(org.springframework.context.annotation.Bean)

Example 4 with RulesBuilder

use of org.sonar.api.batch.rule.internal.RulesBuilder in project sonarqube by SonarSource.

the class RuleFinderCompatibilityTest method prepare.

@Before
public void prepare() {
    RulesBuilder builder = new RulesBuilder();
    builder.add(RuleKey.of("repo1", "rule1"));
    builder.add(RuleKey.of("repo1", "rule2")).setInternalKey("rule2_internal");
    builder.add(RuleKey.of("repo2", "rule1"));
    rules = builder.build();
    ruleFinder = new RuleFinderCompatibility(rules);
}
Also used : RuleFinderCompatibility(org.sonar.scanner.rule.RuleFinderCompatibility) RulesBuilder(org.sonar.api.batch.rule.internal.RulesBuilder) Before(org.junit.Before)

Example 5 with RulesBuilder

use of org.sonar.api.batch.rule.internal.RulesBuilder in project sonarlint-core by SonarSource.

the class SonarQubeRulesProvider method provide.

public Rules provide(Sonarlint.Rules storageRules) {
    if (rules == null) {
        RulesBuilder builder = new RulesBuilder();
        for (Map.Entry<String, Sonarlint.Rules.Rule> entry : storageRules.getRulesByKeyMap().entrySet()) {
            Sonarlint.Rules.Rule r = entry.getValue();
            NewRule newRule = builder.add(RuleKey.of(r.getRepo(), r.getKey())).setName(r.getName()).setInternalKey(r.getInternalKey()).setSeverity(r.getSeverity()).setDescription(r.getHtmlDesc());
            if (StringUtils.isNotEmpty(r.getType())) {
                newRule.setType(r.getType());
            }
        }
        rules = builder.build();
    }
    return rules;
}
Also used : Sonarlint(org.sonarsource.sonarlint.core.proto.Sonarlint) NewRule(org.sonar.api.batch.rule.internal.NewRule) Map(java.util.Map) Rules(org.sonar.api.batch.rule.Rules) RulesBuilder(org.sonar.api.batch.rule.internal.RulesBuilder) NewRule(org.sonar.api.batch.rule.internal.NewRule)

Aggregations

RulesBuilder (org.sonar.api.batch.rule.internal.RulesBuilder)5 NewRule (org.sonar.api.batch.rule.internal.NewRule)3 Before (org.junit.Before)2 Profiler (org.sonar.api.utils.log.Profiler)2 Rule (org.sonarqube.ws.Rules.ListResponse.Rule)2 File (java.io.File)1 Map (java.util.Map)1 InputFile (org.sonar.api.batch.fs.InputFile)1 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)1 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)1 InputModuleHierarchy (org.sonar.api.batch.fs.internal.InputModuleHierarchy)1 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)1 Rules (org.sonar.api.batch.rule.Rules)1 PathResolver (org.sonar.api.scan.filesystem.PathResolver)1 UserRepositoryLoader (org.sonar.scanner.repository.user.UserRepositoryLoader)1 RuleFinderCompatibility (org.sonar.scanner.rule.RuleFinderCompatibility)1 DefaultComponentTree (org.sonar.scanner.scan.DefaultComponentTree)1 InputComponentStore (org.sonar.scanner.scan.filesystem.InputComponentStore)1