Skip to content

Commit

Permalink
Merge pull request #114 from PDF-Archiver/master
Browse files Browse the repository at this point in the history
parse Xcode 11 projects with integrated SPM
  • Loading branch information
mono0926 authored Oct 27, 2019
2 parents cf0bcc5 + 6e857a1 commit 0250e45
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Sources/LicensePlist/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ private func loadConfig(configPath: URL) -> Config {
let main = command(Option("cartfile-path", default: Consts.cartfileName),
Option("pods-path", default: Consts.podsDirectoryName),
Option("package-path", default: Consts.packageName),
Option("xcodeproj-path", default: "*.xcodeproj"),
Option("output-path", default: Consts.outputPath),
Option("github-token", default: ""),
Option("config-path", default: Consts.configPath),
Expand All @@ -21,7 +22,7 @@ let main = command(Option("cartfile-path", default: Consts.cartfileName),
Option("markdown-path", default: ""),
Flag("force"),
Flag("add-version-numbers"),
Flag("suppress-opening-directory")) { cartfile, podsPath, packagePath, output, gitHubToken, configPath, prefix, htmlPath, markdownPath, force, version, suppressOpen in
Flag("suppress-opening-directory")) { cartfile, podsPath, packagePath, xcodeprojPath, output, gitHubToken, configPath, prefix, htmlPath, markdownPath, force, version, suppressOpen in

Logger.configure()
var config = loadConfig(configPath: URL(fileURLWithPath: configPath))
Expand All @@ -32,6 +33,7 @@ let main = command(Option("cartfile-path", default: Consts.cartfileName),
cartfilePath: URL(fileURLWithPath: cartfile),
podsPath: URL(fileURLWithPath: podsPath),
packagePath: URL(fileURLWithPath: packagePath),
xcodeprojPath: URL(fileURLWithPath: xcodeprojPath),
prefix: prefix,
gitHubToken: gitHubToken.isEmpty ? ProcessInfo.processInfo.environment["LICENSE_PLIST_GITHUB_TOKEN"] : gitHubToken,
htmlPath: htmlPath.isEmpty ? nil : URL(fileURLWithPath: htmlPath),
Expand Down
1 change: 1 addition & 0 deletions Sources/LicensePlistCore/Consts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public struct Consts {
public static let cartfileName = "Cartfile"
public static let podsDirectoryName = "Pods"
public static let packageName = "Package.swift"
public static let xcodeprojExtension = "xcodeproj"
public static let prefix = "com.mono0926.LicensePlist"
public static let outputPath = "\(prefix).Output"
public static let configPath = "license_plist.yml"
Expand Down
4 changes: 4 additions & 0 deletions Sources/LicensePlistCore/Entity/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public struct Options {
public let cartfilePath: URL
public let podsPath: URL
public let packagePath: URL
public let xcodeprojPath: URL
public let prefix: String
public let gitHubToken: String?
public let htmlPath: URL?
Expand All @@ -15,6 +16,7 @@ public struct Options {
cartfilePath: URL(fileURLWithPath: ""),
podsPath: URL(fileURLWithPath: ""),
packagePath: URL(fileURLWithPath: ""),
xcodeprojPath: URL(fileURLWithPath: ""),
prefix: Consts.prefix,
gitHubToken: nil,
htmlPath: nil,
Expand All @@ -25,6 +27,7 @@ public struct Options {
cartfilePath: URL,
podsPath: URL,
packagePath: URL,
xcodeprojPath: URL,
prefix: String,
gitHubToken: String?,
htmlPath: URL?,
Expand All @@ -34,6 +37,7 @@ public struct Options {
self.cartfilePath = cartfilePath
self.podsPath = podsPath
self.packagePath = packagePath
self.xcodeprojPath = xcodeprojPath
self.prefix = prefix
self.gitHubToken = gitHubToken
self.htmlPath = htmlPath
Expand Down
27 changes: 25 additions & 2 deletions Sources/LicensePlistCore/LicensePlist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public final class LicensePlist {
var info = PlistInfo(options: options)
info.loadCocoaPodsLicense(acknowledgements: readPodsAcknowledgements(path: options.podsPath))
info.loadGitHubLibraries(cartfile: readCartfile(path: options.cartfilePath))
info.loadSwiftPackageLibraries(packageFile: readSwiftPackages(path: options.packagePath))
info.loadSwiftPackageLibraries(packageFile: readSwiftPackages(path: options.packagePath) ?? readXcodeProject(path: options.xcodeprojPath))
info.loadManualLibraries()
info.compareWithLatestSummary()
info.downloadGitHubLicenses()
Expand All @@ -37,7 +37,7 @@ private func readCartfile(path: URL) -> String? {
}

private func readSwiftPackages(path: URL) -> String? {
if path.lastPathComponent != Consts.packageName {
if path.lastPathComponent != Consts.packageName && path.lastPathComponent != "Package.resolved" {
fatalError("Invalid Package.swift name: \(path.lastPathComponent)")
}
if let content = path.deletingPathExtension().appendingPathExtension("resolved").lp.read() {
Expand All @@ -46,6 +46,29 @@ private func readSwiftPackages(path: URL) -> String? {
return path.lp.read()
}

private func readXcodeProject(path: URL) -> String? {

var projectPath: URL?
if path.lastPathComponent.contains("*") {
// find first "xcodeproj" in directory
projectPath = path.deletingLastPathComponent().lp.listDir().first { $0.pathExtension == Consts.xcodeprojExtension }
} else {
// use the specified path
projectPath = path
}
guard let validatedPath = projectPath else { return nil }

if validatedPath.pathExtension != Consts.xcodeprojExtension {
return nil
}
let packageResolvedPath = validatedPath
.appendingPathComponent("project.xcworkspace")
.appendingPathComponent("xcshareddata")
.appendingPathComponent("swiftpm")
.appendingPathComponent("Package.resolved")
return readSwiftPackages(path: packageResolvedPath)
}

private func readPodsAcknowledgements(path: URL) -> [String] {
if path.lastPathComponent != Consts.podsDirectoryName {
fatalError("Invalid Pods name: \(path.lastPathComponent)")
Expand Down
1 change: 1 addition & 0 deletions Tests/LicensePlistTests/Entity/PlistInfoTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class PlistInfoTests: XCTestCase {
cartfilePath: URL(fileURLWithPath: "test_result_dir"),
podsPath: URL(fileURLWithPath: "test_result_dir"),
packagePath: URL(fileURLWithPath: "test_result_dir"),
xcodeprojPath: URL(fileURLWithPath: "test_result_dir"),
prefix: Consts.prefix,
gitHubToken: nil,
htmlPath: nil,
Expand Down

0 comments on commit 0250e45

Please sign in to comment.