diff --git a/AcknowledgementsPlist.podspec b/AcknowledgementsPlist.podspec index 0604cf6..0ec21b4 100644 --- a/AcknowledgementsPlist.podspec +++ b/AcknowledgementsPlist.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'AcknowledgementsPlist' - s.version = '0.0.4' + s.version = '0.0.5' s.summary = 'AcknowledgementsPlist manages the licenses of libraries that depend on your iOS app.' s.homepage = 'https://github.com/cats-oss/AcknowledgementsPlist' s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/Sources/AcknowledgementsPlist/main.swift b/Sources/AcknowledgementsPlist/main.swift index eeab02c..e22bd17 100644 --- a/Sources/AcknowledgementsPlist/main.swift +++ b/Sources/AcknowledgementsPlist/main.swift @@ -13,9 +13,10 @@ let main = command(Argument("project-root-path", description: "Project r Argument("output-path", description: "Absolute path of plist or bundle output path from project root."), Option("pods-path", default: "", description: "Absolute path of pods from project root."), Option("carthage-checkouts-path", default: "", description: "Absolute path of carthage from project root."), - Option("manual-plist-path", default: "", description: "Absolute path of carthage from project root."), + Option("manual-plist-path", default: "", description: "Absolute path of manual liceses plist from project root."), + Option("manual-license-files-path", default: "", description: "Absolute path of manual liceses files from project root."), Option("exclude-word", default: "", description: "Exclude URLs that contain the specified word.") -) { projectRootPath, outputPath, podsPath, carthageCheckoutsPath, manualAcknowledgementsPath, excludeWord in +) { projectRootPath, outputPath, podsPath, carthageCheckoutsPath, manualPlistPath, manualLicenseFilesPath, excludeWord in let outputPlistPath = outputPath.hasSuffix(".plist") ? outputPath : "" let outputBundlePath = outputPath.hasSuffix(".bundle") ? outputPath : "" let excludeWordArray = excludeWord.components(separatedBy: " ") @@ -24,7 +25,8 @@ let main = command(Argument("project-root-path", description: "Project r outputBundlePath: outputBundlePath, podsPath: podsPath, carthageCheckoutsPath: carthageCheckoutsPath, - manualAcknowledgementsPath: manualAcknowledgementsPath, + manualPlistPath: manualPlistPath, + manualLicenseFilesPath: manualLicenseFilesPath, excludeWordArray: excludeWordArray) do { let acknowledgements = try Acknowledgements(options: options) @@ -39,7 +41,7 @@ let main = command(Argument("project-root-path", description: "Project r print("Pods directory URL not found.") case .carthageDirURL: print("Carthage directory URL not found.") - case .podsCarhageLicenseURLs: + case .emptyLicenseURLs: print("Pods and Carthage URLs is impty.") case .manualAckPlist: print("ManualAcknowledgements.plist not found.") diff --git a/Sources/AcknowledgementsPlistCore/Acknowledgements.swift b/Sources/AcknowledgementsPlistCore/Acknowledgements.swift index 1ea016e..f54fa9f 100644 --- a/Sources/AcknowledgementsPlistCore/Acknowledgements.swift +++ b/Sources/AcknowledgementsPlistCore/Acknowledgements.swift @@ -13,6 +13,7 @@ public final class Acknowledgements: LicenseURLsMakable, LicensesMakable, Output public let manager: FileManager = .default public var podsLicenseURLs: [URL] = [] public var carthageLicenseURLs: [URL] = [] + public var manualLicenseURLs: [URL] = [] public init(options: Options) throws { self.options = options diff --git a/Sources/AcknowledgementsPlistCore/Common/AckError.swift b/Sources/AcknowledgementsPlistCore/Common/AckError.swift index e99053c..549cfb6 100644 --- a/Sources/AcknowledgementsPlistCore/Common/AckError.swift +++ b/Sources/AcknowledgementsPlistCore/Common/AckError.swift @@ -12,7 +12,7 @@ public enum AckError: Error { case convertedURL case podsDirURL case carthageDirURL - case podsCarhageLicenseURLs + case emptyLicenseURLs case manualAckPlist case manualACKPref } diff --git a/Sources/AcknowledgementsPlistCore/Common/Options.swift b/Sources/AcknowledgementsPlistCore/Common/Options.swift index adaf85f..aa28474 100644 --- a/Sources/AcknowledgementsPlistCore/Common/Options.swift +++ b/Sources/AcknowledgementsPlistCore/Common/Options.swift @@ -15,7 +15,8 @@ public struct Options { public let podsPath: String public let carthageCheckoutsPath: String - public let manualAcknowledgementsPath: String + public let manualPlistPath: String + public let manualLicenseFilesPath: String public let excludeWordArray: [String] public init(projectRootPath: String, @@ -23,14 +24,16 @@ public struct Options { outputBundlePath: String, podsPath: String, carthageCheckoutsPath: String, - manualAcknowledgementsPath: String, + manualPlistPath: String, + manualLicenseFilesPath: String, excludeWordArray: [String]) { self.projectRootPath = projectRootPath self.outputPlistPath = outputPlistPath self.outputBundlePath = outputBundlePath self.podsPath = podsPath self.carthageCheckoutsPath = carthageCheckoutsPath - self.manualAcknowledgementsPath = manualAcknowledgementsPath + self.manualPlistPath = manualPlistPath + self.manualLicenseFilesPath = manualLicenseFilesPath self.excludeWordArray = excludeWordArray } } diff --git a/Sources/AcknowledgementsPlistCore/Protocols/LicenseURLsMakable.swift b/Sources/AcknowledgementsPlistCore/Protocols/LicenseURLsMakable.swift index 1ca8478..ccafacd 100644 --- a/Sources/AcknowledgementsPlistCore/Protocols/LicenseURLsMakable.swift +++ b/Sources/AcknowledgementsPlistCore/Protocols/LicenseURLsMakable.swift @@ -12,6 +12,7 @@ public protocol LicenseURLsMakable: class { var manager: FileManager { get } var podsLicenseURLs: [URL] { get set } var carthageLicenseURLs: [URL] { get set } + var manualLicenseURLs: [URL] { get set } } extension LicenseURLsMakable { @@ -19,8 +20,10 @@ extension LicenseURLsMakable { public func makeLicenseURLs() throws { podsLicenseURLs = try getPodsLicenseURLs() carthageLicenseURLs = try getCarthageLicenseURLs() - if podsLicenseURLs.isEmpty && carthageLicenseURLs.isEmpty { - throw AckError.podsCarhageLicenseURLs + manualLicenseURLs = try getManualLicenseURLs() + + if podsLicenseURLs.isEmpty && carthageLicenseURLs.isEmpty && manualLicenseURLs.isEmpty { + throw AckError.emptyLicenseURLs } } @@ -63,6 +66,12 @@ extension LicenseURLsMakable { return try getLicenseURLs(dirURL: url) } + private func getManualLicenseURLs() throws -> [URL] { + let dirURLString = options.manualLicenseFilesPath.isEmpty ? nil : options.manualLicenseFilesPath + let url = dirURLString.flatMap(URL.init) + return try url.map(getLicenseURLs) ?? [] + } + private func getAllDirContentsURLs() throws -> [URL] { let managerOptions: FileManager.DirectoryEnumerationOptions = [.skipsHiddenFiles] guard let rootURL = URL(string: manager.currentDirectoryPath), let allDirPaths = manager.enumerator(at: rootURL, includingPropertiesForKeys: nil, options: managerOptions) else { diff --git a/Sources/AcknowledgementsPlistCore/Protocols/LicensesMakable.swift b/Sources/AcknowledgementsPlistCore/Protocols/LicensesMakable.swift index baaead1..6bbc220 100644 --- a/Sources/AcknowledgementsPlistCore/Protocols/LicensesMakable.swift +++ b/Sources/AcknowledgementsPlistCore/Protocols/LicensesMakable.swift @@ -11,6 +11,7 @@ public protocol LicensesMakable: class { var options: Options { get } var podsLicenseURLs: [URL] { get } var carthageLicenseURLs: [URL] { get } + var manualLicenseURLs: [URL] { get } } extension LicensesMakable { @@ -22,14 +23,16 @@ extension LicensesMakable { public func makeLicenses() throws -> [LicenseType] { let podsLicenses = try getLicenses(licenseURLs: podsLicenseURLs) let carthageLicenses = try getLicenses(licenseURLs: carthageLicenseURLs) - let manualLicenses = try getManualAcknowledgements().map { License(object: $0) } - return (podsLicenses + carthageLicenses + manualLicenses).sorted(by: { $0.title < $1.title }) + let manualPlistLicenses = try getManualPlistLicenses().map { License(object: $0) } + let manualLicenses = try getLicenses(licenseURLs: manualLicenseURLs) + return (podsLicenses + carthageLicenses + manualPlistLicenses + manualLicenses) + .sorted(by: { $0.title < $1.title }) } public func makeLicenseLinks() throws -> [LicenseType] { let podsLicenseLinks = getLicenseLinks(licenseURLs: podsLicenseURLs) let carthageLicenseLinks = getLicenseLinks(licenseURLs: carthageLicenseURLs) - let manualLicenseLinks = try getManualAcknowledgements().map { LicenseLink(object: $0) } + let manualLicenseLinks = try getManualPlistLicenses().map { LicenseLink(object: $0) } return (podsLicenseLinks + carthageLicenseLinks + manualLicenseLinks).sorted(by: { $0.title < $1.title }) } @@ -52,12 +55,12 @@ extension LicensesMakable { } } - private func getManualAcknowledgements() throws -> [LicenseType.Dictionary] { - if options.manualAcknowledgementsPath.isEmpty { + private func getManualPlistLicenses() throws -> [LicenseType.Dictionary] { + if options.manualPlistPath.isEmpty { return [] } else { - guard let plist = NSDictionary(contentsOfFile: options.manualAcknowledgementsPath) else { + guard let plist = NSDictionary(contentsOfFile: options.manualPlistPath) else { throw AckError.manualAckPlist }