org.sonar.api.batch.fs.FilePredicate Java Examples
The following examples show how to use
org.sonar.api.batch.fs.FilePredicate.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClojureSensor.java From sonar-clojure with MIT License | 6 votes |
@Override public void execute(SensorContext context) { LOG.info("Running ClojureSensor"); FilePredicates predicates = context.fileSystem().predicates(); FilePredicate clojure = predicates.hasLanguage(Clojure.KEY); FilePredicate main = predicates.hasType(InputFile.Type.MAIN); //TODO This is inaccurate. We need to properly count the lines of code, excluding spaces, comments, etc. //TODO This is here to make sure analysis data will show up in the Sonar UI. Iterable<InputFile> sources = context.fileSystem().inputFiles(predicates.and(clojure, main)); for (InputFile source : sources) { LOG.info(source.toString()); context.<Integer>newMeasure().withValue(source.lines()).forMetric(NCLOC).on(source).save(); } }
Example #2
Source File: CloverageMetricParser.java From sonar-clojure with MIT License | 5 votes |
private static Optional<FileAnalysis> findFileBySources(SensorContext context, String filename) { FileSystem fs = context.fileSystem(); FilePredicate pattern = fs.predicates().matchesPathPattern("**/" + filename); InputFile potentialFile = fs.inputFile(pattern); if (potentialFile != null) { LOG.debug("Found file"); FileAnalysis foundSource = new FileAnalysis(); foundSource.setInputFile(potentialFile); return Optional.of(foundSource); } return Optional.empty(); }
Example #3
Source File: EmbeddedCssAnalyzerSensor.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 5 votes |
private FilePredicate mainFilePredicate(FileSystem fileSystem) { String[] suffixes = getSettings().getStringArray(Plugin.EMBEDDED_CSS_FILE_SUFFIXES_KEY); if (suffixes == null || suffixes.length == 0) { suffixes = StringUtils.split(Plugin.CSS_FILE_SUFFIXES_DEFAULT_VALUE, ","); } List<FilePredicate> filePredicates = new ArrayList<>(); for (String suffix : suffixes) { filePredicates.add(fileSystem.predicates().matchesPathPattern("**/*." + suffix)); } return fileSystem.predicates().or(filePredicates); }
Example #4
Source File: CheckstyleAuditListenerTest.java From sonar-checkstyle with GNU Lesser General Public License v3.0 | 5 votes |
@Before public void before() { fileSystem = mock(FileSystem.class); context = mock(SensorContext.class); inputFile = mock(InputFile.class); ruleFinder = mock(ActiveRules.class); final FilePredicates predicates = mock(FilePredicates.class); final FilePredicate filePredicate = mock(FilePredicate.class); when(fileSystem.inputFile(any(FilePredicate.class))).thenReturn(inputFile); when(fileSystem.predicates()).thenReturn(predicates); when(predicates.hasAbsolutePath(anyString())).thenReturn(filePredicate); }
Example #5
Source File: HtlSensor.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
@Override public void execute(SensorContext context) { FilePredicate htlFilePredicate = HtlFilePredicateProvider.createFilePredicate(configuration, context); Iterable<InputFile> inputFiles = context.fileSystem().inputFiles(htlFilePredicate); Collection<File> files = StreamSupport.stream(inputFiles.spliterator(), false) .map(InputFile::uri) .map(File::new) .collect(Collectors.toList()); ProgressReport progressReport = new ProgressReport("Report about progress of HTL analyzer", TimeUnit.SECONDS.toMillis(10)); progressReport.start(files); analyseFiles(context, inputFiles, progressReport); }
Example #6
Source File: HtlFilePredicateProvider.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
public static FilePredicate createFilePredicate(Configuration configuration, SensorContext sensorContext) { FilePredicates predicates = sensorContext.fileSystem().predicates(); List<FilePredicate> fileExtensions = getFileExtensionsPredicates(predicates, configuration); List<FilePredicate> relativePaths = getPathsPredicate(predicates, configuration); return predicates.and( predicates.hasType(InputFile.Type.MAIN), predicates.or( predicates.hasLanguages(Htl.KEY), predicates.or(fileExtensions) ), predicates.or(relativePaths) ); }
Example #7
Source File: HtlFilePredicateProvider.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
private static List<FilePredicate> getFileExtensionsPredicates(FilePredicates predicates, Configuration configuration) { return Stream.of(configuration.getStringArray(Constants.FILE_EXTENSIONS_PROP_KEY)) .filter(Objects::nonNull) .map(extension -> StringUtils.removeStart(extension, ".")) .map(predicates::hasExtension) .collect(Collectors.toList()); }
Example #8
Source File: HtlFilePredicateProvider.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
private static List<FilePredicate> getPathsPredicate(FilePredicates predicates, Configuration configuration) { return Stream.of(configuration.getStringArray(Constants.HTL_FILES_RELATIVE_PATHS_KEY)) .filter(StringUtils::isNotEmpty) .map(path -> StringUtils.wrapIfMissing(path, "**")) .map(predicates::matchesPathPattern) .collect(Collectors.toList()); }
Example #9
Source File: CssAnalyzerSensor.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 4 votes |
private FilePredicate mainFilePredicate(FileSystem fileSystem) { return fileSystem.predicates() .and( fileSystem.predicates().hasType(InputFile.Type.MAIN), fileSystem.predicates().hasLanguage(CssLanguage.KEY)); }
Example #10
Source File: LessAnalyzerSensor.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 4 votes |
private FilePredicate mainFilePredicate(FileSystem fileSystem) { return fileSystem.predicates() .and( fileSystem.predicates().hasType(InputFile.Type.MAIN), fileSystem.predicates().hasLanguage(LessLanguage.KEY)); }
Example #11
Source File: ScssAnalyzerSensor.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 4 votes |
private FilePredicate mainFilePredicate(FileSystem fileSystem) { return fileSystem.predicates() .and( fileSystem.predicates().hasType(Type.MAIN), fileSystem.predicates().hasLanguage(ScssLanguage.KEY)); }
Example #12
Source File: TsqlIssue.java From sonar-tsql-plugin with GNU General Public License v3.0 | 4 votes |
public FilePredicate getPredicate() { return new AbsolutePathCaseInsensitivePredicate(this.getFilePath()); }