Skip to content

Commit

Permalink
Merge pull request #219 from nandodelauni/main
Browse files Browse the repository at this point in the history
Add `Source` key to the generated *.plist files
  • Loading branch information
mono0926 committed Sep 6, 2023
2 parents 302a0a4 + 2f594b6 commit cdf8421
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Sources/LicensePlistCore/Entity/LicensePlistHolder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ struct LicensePlistHolder {
}
.joined(separator: [String(repeating: "-", count: 40)])
.map { (paragraph) -> [String: String] in
return ["Type": "PSGroupSpecifier",
"FooterText": paragraph,
"License": license.licenseType.rawValue]
return [
"Type": "PSGroupSpecifier",
"FooterText": paragraph,
"License": license.licenseType.rawValue,
"Source": options.config.addSources ? license.source : nil
].compactMapValues { $0 }
}
]

Expand All @@ -52,8 +55,9 @@ struct LicensePlistHolder {
return ["Type": "PSGroupSpecifier",
"Title": license.name(withVersion: options.config.addVersionNumbers),
"FooterText": license.body,
"License": license.licenseType.rawValue
]
"License": license.licenseType.rawValue,
"Source": options.config.addSources ? license.source : nil
].compactMapValues { $0 }
}
return body
}()
Expand Down
49 changes: 49 additions & 0 deletions Tests/LicensePlistTests/Entity/LicensePlistHolderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,53 @@ class LicensePlistHolderTests: XCTestCase {
XCTAssertEqual(item1_4["Type"], "PSGroupSpecifier")
XCTAssertEqual(item1_4["FooterText"], thirdPart)
}
func testLoad_addSources() throws {
let github = GitHub(name: "name", nameSpecified: nil, owner: "owner", version: nil)
let githubLicense = GitHubLicense(library: github, body: "'<body>", githubResponse: nil)
let pods = CocoaPods(name: "name", nameSpecified: nil, version: nil)
let podsLicense = CocoaPodsLicense(library: pods, body: "'<body>")
var config: Config = .empty
config.addSources = true
let result = LicensePlistHolder.loadAllToRoot(
licenses: [podsLicense, githubLicense],
options: .emptyOptions(with: config)
)
let (root, items) = result.deserialized()
let rootItems = try XCTUnwrap(root["PreferenceSpecifiers"])
XCTAssertEqual(rootItems.count, 2)
XCTAssertEqual(items.count, 0)

let rootItems1 = try XCTUnwrap(rootItems.first)
XCTAssertEqual(rootItems1["Type"], "PSGroupSpecifier")
XCTAssertEqual(rootItems1["Title"], "name")
XCTAssertEqual(rootItems1["FooterText"], "'<body>")
XCTAssertEqual(rootItems1["Source"], "https://cocoapods.org/pods/name")

let rootItems2 = try XCTUnwrap(rootItems.last)
XCTAssertEqual(rootItems2["Type"], "PSGroupSpecifier")
XCTAssertEqual(rootItems2["Title"], "name")
XCTAssertEqual(rootItems2["FooterText"], "'<body>")
XCTAssertEqual(rootItems2["Source"], "https://github.com/owner/name")
}
}

extension Options {
static func emptyOptions(with config: Config) -> Self {
.init(
outputPath: .init(fileURLWithPath: ""),
cartfilePath: .init(fileURLWithPath: ""),
mintfilePath: .init(fileURLWithPath: ""),
podsPath: .init(fileURLWithPath: ""),
packagePaths: [],
packageSourcesPath: nil,
xcworkspacePath: .init(fileURLWithPath: ""),
xcodeprojPath: .init(fileURLWithPath: ""),
prefix: Consts.prefix,
gitHubToken: nil,
htmlPath: nil,
markdownPath: nil,
licenseFileNames: [],
config: config
)
}
}

0 comments on commit cdf8421

Please sign in to comment.