From e08b1ad4948f8bab44d1898b8707fffc2de0a690 Mon Sep 17 00:00:00 2001 From: Yi Wang Date: Mon, 10 Dec 2018 14:07:37 -0800 Subject: [PATCH] Support passing in individual Swift source files (#220) This makes debugging and testing easier. I also intent to use this as the test method for Homebrew formula. --- .../Parsing/FileFilters/UrlFilter.swift | 6 +----- .../NeedleFramework/Utilities/Extensions.swift | 9 +++++++++ .../NeedleFramework/Utilities/FileEnumerator.swift | 12 ++++++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Generator/Sources/NeedleFramework/Parsing/FileFilters/UrlFilter.swift b/Generator/Sources/NeedleFramework/Parsing/FileFilters/UrlFilter.swift index 7ae63173..ae38d9cb 100644 --- a/Generator/Sources/NeedleFramework/Parsing/FileFilters/UrlFilter.swift +++ b/Generator/Sources/NeedleFramework/Parsing/FileFilters/UrlFilter.swift @@ -38,7 +38,7 @@ class UrlFilter: FileFilter { /// /// - returns: `true` if the URL should be parsed. `false` otherwise. func filter() -> Bool { - if !isUrlSwiftSource || urlHasExcludedSuffix || urlHasExcludedPath { + if !url.isSwiftSource || urlHasExcludedSuffix || urlHasExcludedPath { return false } return true @@ -50,10 +50,6 @@ class UrlFilter: FileFilter { private let exclusionSuffixes: [String] private let exclusionPaths: [String] - private var isUrlSwiftSource: Bool { - return url.pathExtension == "swift" - } - private var urlHasExcludedSuffix: Bool { let name = url.deletingPathExtension().lastPathComponent for suffix in exclusionSuffixes { diff --git a/Generator/Sources/NeedleFramework/Utilities/Extensions.swift b/Generator/Sources/NeedleFramework/Utilities/Extensions.swift index 56a0cb6c..1bfe60d9 100644 --- a/Generator/Sources/NeedleFramework/Utilities/Extensions.swift +++ b/Generator/Sources/NeedleFramework/Utilities/Extensions.swift @@ -72,4 +72,13 @@ extension URL { self.init(fileURLWithPath: path) } } + + /// Check if this URL represents a Swift source file by examining its + /// file extenson. + /// + /// - returns: `true` if the URL is a Swift source file. `false` + /// otherwise. + var isSwiftSource: Bool { + return pathExtension == "swift" + } } diff --git a/Generator/Sources/NeedleFramework/Utilities/FileEnumerator.swift b/Generator/Sources/NeedleFramework/Utilities/FileEnumerator.swift index d37dc3b9..e2e30483 100644 --- a/Generator/Sources/NeedleFramework/Utilities/FileEnumerator.swift +++ b/Generator/Sources/NeedleFramework/Utilities/FileEnumerator.swift @@ -70,10 +70,14 @@ class FileEnumerator { /// - throws: `FileEnumerationError` if any errors occurred. func enumerate(from rootUrl: URL, withSourcesListFormat sourcesListFormatValue: String?, handler: (URL) -> Void) throws { if rootUrl.isFileURL { - let format = try sourcesListFileFormat(from: sourcesListFormatValue, withDefault: .newline) - let fileUrls = try self.fileUrls(fromSourcesList: rootUrl, with: format) - for fileUrl in fileUrls { - handler(fileUrl) + if rootUrl.isSwiftSource { + handler(rootUrl) + } else { + let format = try sourcesListFileFormat(from: sourcesListFormatValue, withDefault: .newline) + let fileUrls = try self.fileUrls(fromSourcesList: rootUrl, with: format) + for fileUrl in fileUrls { + handler(fileUrl) + } } } else { let enumerator = try newFileEnumerator(for: rootUrl)