|
| 1 | +/** |
| 2 | + * backelite-sonar-swift-plugin - Enables analysis of Swift projects into SonarQube. |
| 3 | + * Copyright © 2015 Backelite (${email}) |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU Lesser General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU Lesser General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Lesser General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | +package org.sonar.plugins.swift.lang; |
| 19 | + |
| 20 | +import org.sonar.api.batch.BatchSide; |
| 21 | +import org.sonar.api.batch.fs.FilePredicate; |
| 22 | +import org.sonar.api.batch.fs.FilePredicates; |
| 23 | +import org.sonar.api.batch.fs.FileSystem; |
| 24 | +import org.sonar.api.batch.fs.InputFile; |
| 25 | +import org.sonar.plugins.swift.lang.core.Swift; |
| 26 | + |
| 27 | +import javax.annotation.CheckForNull; |
| 28 | +import java.io.File; |
| 29 | +import java.util.ArrayList; |
| 30 | +import java.util.List; |
| 31 | + |
| 32 | + |
| 33 | +@BatchSide |
| 34 | +public class SwiftFileSystem { |
| 35 | + |
| 36 | + private final FileSystem fileSystem; |
| 37 | + private final FilePredicates predicates; |
| 38 | + private final FilePredicate isSwiftLanguage; |
| 39 | + private final FilePredicate isMainTypeFile; |
| 40 | + |
| 41 | + public SwiftFileSystem(FileSystem fileSystem) { |
| 42 | + this.fileSystem = fileSystem; |
| 43 | + this.predicates = fileSystem.predicates(); |
| 44 | + this.isSwiftLanguage = predicates.hasLanguage(Swift.KEY); |
| 45 | + this.isMainTypeFile = predicates.hasType(InputFile.Type.MAIN); |
| 46 | + } |
| 47 | + |
| 48 | + public boolean hasSwiftFiles() { |
| 49 | + return fileSystem.hasFiles(isSwiftLanguage); |
| 50 | + } |
| 51 | + |
| 52 | + public List<File> sourceFiles() { |
| 53 | + Iterable<File> files = fileSystem.files(predicates.and(isSwiftLanguage, isMainTypeFile)); |
| 54 | + List<File> list = new ArrayList<>(); |
| 55 | + files.iterator().forEachRemaining(list::add); |
| 56 | + return list; |
| 57 | + } |
| 58 | + |
| 59 | + public List<InputFile> swiftInputFiles() { |
| 60 | + Iterable<InputFile> inputFiles = fileSystem.inputFiles(isSwiftLanguage); |
| 61 | + List<InputFile> list = new ArrayList<>(); |
| 62 | + inputFiles.iterator().forEachRemaining(list::add); |
| 63 | + return list; |
| 64 | + } |
| 65 | + |
| 66 | + public List<InputFile> sourceInputFiles() { |
| 67 | + Iterable<InputFile> inputFiles = fileSystem.inputFiles(predicates.and(isSwiftLanguage, isMainTypeFile)); |
| 68 | + List<InputFile> list = new ArrayList<>(); |
| 69 | + inputFiles.iterator().forEachRemaining(list::add); |
| 70 | + return list; |
| 71 | + } |
| 72 | + |
| 73 | + @CheckForNull |
| 74 | + public InputFile sourceInputFileFromRelativePath(String relativePath) { |
| 75 | + return fileSystem.inputFile(predicates.and(predicates.matchesPathPattern("**/" + relativePath), isSwiftLanguage, isMainTypeFile)); |
| 76 | + } |
| 77 | + |
| 78 | + public File baseDir() { |
| 79 | + return fileSystem.baseDir(); |
| 80 | + } |
| 81 | +} |
0 commit comments