Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented SwiftFileSystem to prepare new API refacto
- Loading branch information
Gilles Grousset
committed
Aug 18, 2017
1 parent
19d5e67
commit 0d7ed80
Showing
12 changed files
with
105 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
sonar-swift-plugin/src/main/java/org/sonar/plugins/swift/lang/SwiftFileSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* backelite-sonar-swift-plugin - Enables analysis of Swift projects into SonarQube. | ||
* Copyright © 2015 Backelite (${email}) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.sonar.plugins.swift.lang; | ||
|
||
import org.sonar.api.batch.BatchSide; | ||
import org.sonar.api.batch.fs.FilePredicate; | ||
import org.sonar.api.batch.fs.FilePredicates; | ||
import org.sonar.api.batch.fs.FileSystem; | ||
import org.sonar.api.batch.fs.InputFile; | ||
import org.sonar.plugins.swift.lang.core.Swift; | ||
|
||
import javax.annotation.CheckForNull; | ||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
||
@BatchSide | ||
public class SwiftFileSystem { | ||
|
||
private final FileSystem fileSystem; | ||
private final FilePredicates predicates; | ||
private final FilePredicate isSwiftLanguage; | ||
private final FilePredicate isMainTypeFile; | ||
|
||
public SwiftFileSystem(FileSystem fileSystem) { | ||
this.fileSystem = fileSystem; | ||
this.predicates = fileSystem.predicates(); | ||
this.isSwiftLanguage = predicates.hasLanguage(Swift.KEY); | ||
this.isMainTypeFile = predicates.hasType(InputFile.Type.MAIN); | ||
} | ||
|
||
public boolean hasSwiftFiles() { | ||
return fileSystem.hasFiles(isSwiftLanguage); | ||
} | ||
|
||
public List<File> sourceFiles() { | ||
Iterable<File> files = fileSystem.files(predicates.and(isSwiftLanguage, isMainTypeFile)); | ||
List<File> list = new ArrayList<>(); | ||
files.iterator().forEachRemaining(list::add); | ||
return list; | ||
} | ||
|
||
public List<InputFile> swiftInputFiles() { | ||
Iterable<InputFile> inputFiles = fileSystem.inputFiles(isSwiftLanguage); | ||
List<InputFile> list = new ArrayList<>(); | ||
inputFiles.iterator().forEachRemaining(list::add); | ||
return list; | ||
} | ||
|
||
public List<InputFile> sourceInputFiles() { | ||
Iterable<InputFile> inputFiles = fileSystem.inputFiles(predicates.and(isSwiftLanguage, isMainTypeFile)); | ||
List<InputFile> list = new ArrayList<>(); | ||
inputFiles.iterator().forEachRemaining(list::add); | ||
return list; | ||
} | ||
|
||
@CheckForNull | ||
public InputFile sourceInputFileFromRelativePath(String relativePath) { | ||
return fileSystem.inputFile(predicates.and(predicates.matchesPathPattern("**/" + relativePath), isSwiftLanguage, isMainTypeFile)); | ||
} | ||
|
||
public File baseDir() { | ||
return fileSystem.baseDir(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters