@SuppressWarnings({"rawtypes", "unchecked"}) public void decorate(Resource resource, DecoratorContext context) { // assume that all checks relate to files, not directories nor modules if (ResourceUtils.isEntity(resource) && resource.getLanguage() != null && resource.getLanguage().getKey().equals(language)) { for (CommonCheck check : activeChecks) { check.checkResource(resource, context, checkFactory.getActiveRule(check).getRule()); } } }
/** * 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; }
private void saveViolations(SourceCode squidFile, File sonarFile) { Set<CheckMessage> messages = squidFile.getCheckMessages(); if (messages != null) { for (CheckMessage message : messages) { @SuppressWarnings("unchecked") Violation violation = Violation.create(annotationCheckFactory.getActiveRule(message.getChecker()), sonarFile); violation.setLineId(message.getLine()); violation.setMessage(message.getText(Locale.ENGLISH)); context.saveViolation(violation); } } }
private void saveViolations(File sonarFile, SourceFile squidFile) { Collection<CheckMessage> messages = squidFile.getCheckMessages(); if (messages != null) { for (CheckMessage message : messages) { Violation violation = Violation.create(annotationCheckFactory.getActiveRule(message.getChecker()), sonarFile) .setLineId(message.getLine()) .setMessage(message.getText(Locale.ENGLISH)); context.saveViolation(violation); } } }
/** * 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); } } }