@Override public boolean shouldExecuteOnProject(Project project) { boolean hasLangFiles = !fs.mainFiles(language).isEmpty() || !fs.testFiles(language).isEmpty(); if (hasLangFiles) { checkFactory = AnnotationCheckFactory.create(qProfile, DefaultCommonRulesRepository.keyForLanguage(language), CommonRulesConstants.CLASSES); activeChecks = checkFactory.getChecks(); } return !activeChecks.isEmpty(); }
@Override @SuppressWarnings("unchecked") public void analyse(Project project, SensorContext context) { this.project = project; this.context = context; Collection<SquidAstVisitor<CSharpGrammar>> squidChecks = annotationCheckFactory.getChecks(); List<SquidAstVisitor<CSharpGrammar>> visitors = Lists.newArrayList(squidChecks); // TODO: remove the following line & class once SSLR Squid bridge computes NCLOC_DATA_KEY & COMMENT_LINES_DATA_KEY visitors.add(new CSharpFileLinesVisitor(project, fileLinesContextFactory)); scanner = CSharpAstScanner.create(createParserConfiguration(project), (SquidAstVisitor<CSharpGrammar>[]) visitors.toArray(new SquidAstVisitor[visitors.size()])); scanner.scanFiles(getFilesToAnalyse(project)); Collection<SourceCode> squidSourceFiles = scanner.getIndex().search(new QueryByType(SourceFile.class)); saveMeasures(squidSourceFiles); }
public void analyse(Project project, SensorContext context) { this.project = project; this.context = context; Collection<SquidCheck> squidChecks = annotationCheckFactory.getChecks(); this.scanner = ObjectiveCAstScanner.create(createConfiguration(project), squidChecks.toArray(new SquidCheck[squidChecks.size()])); scanner.scanFiles(InputFileUtils.toFiles(project.getFileSystem().mainFiles(ObjectiveC.KEY))); Collection<SourceCode> squidSourceFiles = scanner.getIndex().search(new QueryByType(SourceFile.class)); save(squidSourceFiles); }
/** * Create PageScanner with Visitors. */ private HtmlAstScanner setupScanner() { HtmlAstScanner scanner = new HtmlAstScanner(ImmutableList.of(new PageCountLines(), new ComplexityVisitor(), new NoSonarScanner(noSonarFilter))); for (AbstractPageCheck check : (Collection<AbstractPageCheck>) annotationCheckFactory.getChecks()) { scanner.addVisitor(check); check.setRule(annotationCheckFactory.getActiveRule(check).getRule()); } return scanner; }
/** * Analyze the XML files. */ public void analyse(Project project, SensorContext sensorContext) { Collection<AbstractXmlCheck> checks = annotationCheckFactory.getChecks(); for (java.io.File file : fileSystem.files(FileQuery.onSource().onLanguage(Xml.KEY))) { try { File resource = File.fromIOFile(file, project); XmlSourceCode sourceCode = new XmlSourceCode(resource, file); // Do not execute any XML rule when an XML file is corrupted (SONARXML-13) if (sourceCode.parseSource(fileSystem)) { for (AbstractXmlCheck check : checks) { check.setRule(annotationCheckFactory.getActiveRule(check).getRule()); check.validate(sourceCode); } saveIssue(sourceCode); } } catch (Exception e) { LOG.error("Could not analyze the file " + file.getAbsolutePath(), e); } } }