Skip to content

Commit

Permalink
Merge pull request #6 from cats-oss/manual-lisence-dir
Browse files Browse the repository at this point in the history
Manual license files support
  • Loading branch information
ra1028 authored Apr 3, 2019
2 parents 52c0a95 + 33c687f commit ce2952e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion AcknowledgementsPlist.podspec
Original file line number Diff line number Diff line change
@@ -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' }
Expand Down
10 changes: 6 additions & 4 deletions Sources/AcknowledgementsPlist/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ let main = command(Argument<String>("project-root-path", description: "Project r
Argument<String>("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: " ")
Expand All @@ -24,7 +25,8 @@ let main = command(Argument<String>("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)
Expand All @@ -39,7 +41,7 @@ let main = command(Argument<String>("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.")
Expand Down
1 change: 1 addition & 0 deletions Sources/AcknowledgementsPlistCore/Acknowledgements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Sources/AcknowledgementsPlistCore/Common/AckError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public enum AckError: Error {
case convertedURL
case podsDirURL
case carthageDirURL
case podsCarhageLicenseURLs
case emptyLicenseURLs
case manualAckPlist
case manualACKPref
}
9 changes: 6 additions & 3 deletions Sources/AcknowledgementsPlistCore/Common/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,25 @@ 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,
outputPlistPath: String,
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ 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 {

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
}
}

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 })
}

Expand All @@ -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
}

Expand Down

0 comments on commit ce2952e

Please sign in to comment.