Search in sources :

Example 1 with NoSonarFilter

use of org.sonar.api.issue.NoSonarFilter 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);
}
Also used : FileLinesContext(org.sonar.api.measures.FileLinesContext) ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) NoSonarFilter(org.sonar.api.issue.NoSonarFilter) FileLinesContextFactory(org.sonar.api.measures.FileLinesContextFactory) ArrayList(java.util.ArrayList) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) RulesDefinition(org.sonar.api.server.rule.RulesDefinition) WebRulesDefinition(org.sonar.plugins.web.rules.WebRulesDefinition) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) ActiveRules(org.sonar.api.batch.rule.ActiveRules) CheckFactory(org.sonar.api.batch.rule.CheckFactory) WebRulesDefinition(org.sonar.plugins.web.rules.WebRulesDefinition) FileLinesContext(org.sonar.api.measures.FileLinesContext) Before(org.junit.Before)

Example 2 with NoSonarFilter

use of org.sonar.api.issue.NoSonarFilter in project sonar-web by SonarSource.

the class NoSonarScannerTest method scanNoSonar.

@Test
public void scanNoSonar() {
    List<Node> nodeList = new PageLexer().parse(new StringReader("<table>\n<!-- //NOSONAR --><td>\n</table>"));
    WebSourceCode webSourceCode = new WebSourceCode(new DefaultInputFile("key", "dummy.jsp"));
    NoSonarFilter noSonarFilter = spy(new NoSonarFilter());
    HtmlAstScanner pageScanner = new HtmlAstScanner(Collections.emptyList());
    pageScanner.addVisitor(new NoSonarScanner(noSonarFilter));
    pageScanner.scan(nodeList, webSourceCode, Charsets.UTF_8);
    verify(noSonarFilter, times(1)).noSonarInFile(any(InputFile.class), isOnlyIgnoringLine2());
}
Also used : PageLexer(org.sonar.plugins.web.lex.PageLexer) NoSonarFilter(org.sonar.api.issue.NoSonarFilter) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Node(org.sonar.plugins.web.node.Node) StringReader(java.io.StringReader) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Test(org.junit.Test)

Aggregations

InputFile (org.sonar.api.batch.fs.InputFile)2 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)2 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)2 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 Test (org.junit.Test)1 ActiveRules (org.sonar.api.batch.rule.ActiveRules)1 CheckFactory (org.sonar.api.batch.rule.CheckFactory)1 ActiveRulesBuilder (org.sonar.api.batch.rule.internal.ActiveRulesBuilder)1 DefaultActiveRules (org.sonar.api.batch.rule.internal.DefaultActiveRules)1 NewActiveRule (org.sonar.api.batch.rule.internal.NewActiveRule)1 FileLinesContext (org.sonar.api.measures.FileLinesContext)1 FileLinesContextFactory (org.sonar.api.measures.FileLinesContextFactory)1 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)1 PageLexer (org.sonar.plugins.web.lex.PageLexer)1 Node (org.sonar.plugins.web.node.Node)1 WebRulesDefinition (org.sonar.plugins.web.rules.WebRulesDefinition)1