001/* 002 * SonarQube, open source software quality management tool. 003 * Copyright (C) 2008-2014 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * SonarQube is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * SonarQube is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020package org.sonar.xoo.rule; 021 022import org.sonar.api.batch.fs.FilePredicates; 023import org.sonar.api.batch.fs.InputFile; 024import org.sonar.api.batch.fs.InputFile.Type; 025import org.sonar.api.batch.rule.CheckFactory; 026import org.sonar.api.batch.rule.Checks; 027import org.sonar.api.batch.sensor.Sensor; 028import org.sonar.api.batch.sensor.SensorContext; 029import org.sonar.api.batch.sensor.SensorDescriptor; 030import org.sonar.xoo.Xoo; 031import org.sonar.xoo.checks.Check; 032 033public class ChecksSensor implements Sensor { 034 035 private final CheckFactory checkFactory; 036 037 public ChecksSensor(CheckFactory checkFactory) { 038 this.checkFactory = checkFactory; 039 } 040 041 @Override 042 public void describe(SensorDescriptor descriptor) { 043 descriptor 044 .name("ChecksSensor") 045 .onlyOnLanguage(Xoo.KEY) 046 .createIssuesForRuleRepositories(XooRulesDefinition.XOO_REPOSITORY) 047 .onlyOnFileType(InputFile.Type.MAIN); 048 } 049 050 @Override 051 public void execute(SensorContext context) { 052 Checks<Check> checks = checkFactory.create(XooRulesDefinition.XOO_REPOSITORY); 053 checks.addAnnotatedChecks(Check.ALL); 054 FilePredicates p = context.fileSystem().predicates(); 055 for (InputFile file : context.fileSystem().inputFiles(p.and(p.hasLanguages(Xoo.KEY), p.hasType(Type.MAIN)))) { 056 for (Check check : checks.all()) { 057 check.execute(context, file, checks.ruleKey(check)); 058 } 059 } 060 } 061 062}