From 411dd9a82225b48da6f7da0bbd54c2257dbdd2c8 Mon Sep 17 00:00:00 2001 From: oshio Date: Wed, 17 Apr 2024 19:24:36 +0900 Subject: [PATCH 1/7] Add makeSummary --- Sources/LicensePlistCore/Entity/PlistInfo.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/LicensePlistCore/Entity/PlistInfo.swift b/Sources/LicensePlistCore/Entity/PlistInfo.swift index c92ba845..c0ce47f3 100644 --- a/Sources/LicensePlistCore/Entity/PlistInfo.swift +++ b/Sources/LicensePlistCore/Entity/PlistInfo.swift @@ -200,4 +200,12 @@ struct PlistInfo { fatalError("'--package-sources-path' must be specified when using '--sandbox-mode'") } } + + private func makeSummary(licenseDescriptions: [String]) -> String { + let additionalInfos: [String] = [ + "add-version-numbers: \(options.config.addVersionNumbers)", + "LicensePlist Version: \(Consts.version)" + ] + return (licenseDescriptions + additionalInfos).joined(separator: "\n\n") + } } From 3fa99ce4811ba326e2614a8eee2ff1a754665f99 Mon Sep 17 00:00:00 2001 From: oshio Date: Wed, 17 Apr 2024 19:25:02 +0900 Subject: [PATCH 2/7] Update compareWithLatestSummary --- Sources/LicensePlistCore/Entity/PlistInfo.swift | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Sources/LicensePlistCore/Entity/PlistInfo.swift b/Sources/LicensePlistCore/Entity/PlistInfo.swift index c0ce47f3..be3ef967 100644 --- a/Sources/LicensePlistCore/Entity/PlistInfo.swift +++ b/Sources/LicensePlistCore/Entity/PlistInfo.swift @@ -72,17 +72,18 @@ struct PlistInfo { let config = options.config - let contents = (cocoaPodsLicenses.map { String(describing: $0) } + - githubLibraries.map { String(describing: $0) } + - manualLicenses.map { String(describing: $0) } + - ["add-version-numbers: \(options.config.addVersionNumbers)", "LicensePlist Version: \(Consts.version)"]) - .joined(separator: "\n\n") + let potential = makeSummary( + licenseDescriptions: ( + cocoaPodsLicenses.map { String(describing: $0) } + + githubLibraries.map { String(describing: $0) } + + manualLicenses.map { String(describing: $0) } + ) + ) let savePath = options.outputPath.appendingPathComponent("\(options.prefix).latest_result.txt") - if let previous = savePath.lp.read(), previous == contents, !config.force { + if let previous = savePath.lp.read(), previous == potential, !config.force { Log.warning("Completed because no diff. You can execute force by `--force` flag.") exit(0) } - summary = contents summaryPath = savePath } From a92754281b13f5f331ff25e5c0f0f49017cae0b3 Mon Sep 17 00:00:00 2001 From: oshio Date: Wed, 17 Apr 2024 19:25:47 +0900 Subject: [PATCH 3/7] Make GitHubLicense conform to CustomStringConvertible --- Sources/LicensePlistCore/Entity/GitHubLicense.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/LicensePlistCore/Entity/GitHubLicense.swift b/Sources/LicensePlistCore/Entity/GitHubLicense.swift index 3144f330..268ff94b 100644 --- a/Sources/LicensePlistCore/Entity/GitHubLicense.swift +++ b/Sources/LicensePlistCore/Entity/GitHubLicense.swift @@ -13,6 +13,10 @@ public struct GitHubLicense: License, Equatable { } } +extension GitHubLicense: CustomStringConvertible { + public var description: String { library.description } +} + extension GitHubLicense { public enum DownloadError: Error { From 997f085c247d458b57c41a419789ec6a0e37e795 Mon Sep 17 00:00:00 2001 From: oshio Date: Wed, 17 Apr 2024 19:26:46 +0900 Subject: [PATCH 4/7] Update collectLicenseInfos --- Sources/LicensePlistCore/Entity/PlistInfo.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sources/LicensePlistCore/Entity/PlistInfo.swift b/Sources/LicensePlistCore/Entity/PlistInfo.swift index be3ef967..f566f5a8 100644 --- a/Sources/LicensePlistCore/Entity/PlistInfo.swift +++ b/Sources/LicensePlistCore/Entity/PlistInfo.swift @@ -101,13 +101,19 @@ struct PlistInfo { let githubLicenses = githubLicenses, let manualLicenses = manualLicenses else { preconditionFailure() } - licenses = ((cocoaPodsLicenses as [LicenseInfo]) + (githubLicenses as [LicenseInfo]) + (manualLicenses as [LicenseInfo])) + let licenseInfos: [LicenseInfo] = cocoaPodsLicenses + githubLicenses + manualLicenses + + licenses = licenseInfos .reduce([String: LicenseInfo]()) { sum, e in var sum = sum sum[e.name] = e return sum }.values .sorted { $0.name.lowercased() < $1.name.lowercased() } + + summary = makeSummary( + licenseDescriptions: licenseInfos.map { String(describing: $0) } + ) } func outputPlist() { From a829aac68db8c3b9fc5920951759c6d617cce6bf Mon Sep 17 00:00:00 2001 From: oshio Date: Wed, 17 Apr 2024 20:18:48 +0900 Subject: [PATCH 5/7] Add test --- .../Entity/PlistInfoTests.swift | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Tests/LicensePlistTests/Entity/PlistInfoTests.swift b/Tests/LicensePlistTests/Entity/PlistInfoTests.swift index dd75d404..ceb8eb81 100644 --- a/Tests/LicensePlistTests/Entity/PlistInfoTests.swift +++ b/Tests/LicensePlistTests/Entity/PlistInfoTests.swift @@ -88,8 +88,6 @@ class PlistInfoTests: XCTestCase { XCTAssertNil(target.summaryPath) target.compareWithLatestSummary() - XCTAssertEqual(target.summary, - "add-version-numbers: false\n\nLicensePlist Version: 3.25.1") XCTAssertNotNil(target.summaryPath) } @@ -111,7 +109,7 @@ class PlistInfoTests: XCTestCase { func testCollectLicenseInfos() throws { var target = PlistInfo(options: options) - let github = GitHub(name: "LicensePlist", nameSpecified: nil, owner: "mono0926", version: nil) + let github = GitHub(name: "LicensePlist", nameSpecified: "LicensePlist", owner: "mono0926", version: "0.0.1") let githubLicense = GitHubLicense(library: github, body: "body", githubResponse: LicenseResponse(content: "", @@ -119,11 +117,21 @@ class PlistInfoTests: XCTestCase { kind: LicenseKindResponse(name: "name", spdxId: nil))) target.cocoaPodsLicenses = [] - let manual = Manual(name: "FooBar", source: "https://foo.bar", nameSpecified: nil, version: nil) + let manual = Manual(name: "FooBar", source: "https://foo.bar", nameSpecified: "FooBar", version: "0.0.1") let manualLicense = ManualLicense(library: manual, body: "body") target.manualLicenses = [manualLicense] target.githubLicenses = [githubLicense] + let expectedSummary = """ + name: LicensePlist, nameSpecified: LicensePlist, owner: mono0926, version: 0.0.1, source: https://github.com/mono0926/LicensePlist + + name: FooBar, nameSpecified: FooBar, version: 0.0.1 + body: body… + + add-version-numbers: false + + LicensePlist Version: 3.25.1 + """ XCTAssertNil(target.licenses) target.collectLicenseInfos() @@ -131,6 +139,7 @@ class PlistInfoTests: XCTestCase { XCTAssertEqual(licenses.count, 2) let license = licenses.last XCTAssertEqual(license?.name, "LicensePlist") + XCTAssertEqual(target.summary, expectedSummary) } // MEMO: No result assertions From 8323c1b51efc2c433c699b3e9a5ee6c1aebfb44b Mon Sep 17 00:00:00 2001 From: oshio Date: Wed, 17 Apr 2024 20:54:26 +0900 Subject: [PATCH 6/7] Fix typo --- Sources/LicensePlistCore/LicensePlist.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/LicensePlistCore/LicensePlist.swift b/Sources/LicensePlistCore/LicensePlist.swift index 6096c86a..724a1b85 100644 --- a/Sources/LicensePlistCore/LicensePlist.swift +++ b/Sources/LicensePlistCore/LicensePlist.swift @@ -47,7 +47,7 @@ public final class LicensePlist { } } - /// Gets the result of attempting to read the `Package.resolved` from ether a Xcode Workspace or Xcode project. + /// Gets the result of attempting to read the `Package.resolved` from either a Xcode Workspace or Xcode project. /// - note: If an Xcode workspace is found it is preferred over a Xcode project. private func xcodeFileReadResult(xcworkspacePath: URL, xcodeprojPath: URL) throws -> String? { From eb417f064588ee9ce0604c5ce363f69d234d4c6a Mon Sep 17 00:00:00 2001 From: oshio Date: Fri, 19 Apr 2024 18:24:55 +0900 Subject: [PATCH 7/7] Fix trailing_whitespace violations --- Tests/LicensePlistTests/Entity/PlistInfoTests.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/LicensePlistTests/Entity/PlistInfoTests.swift b/Tests/LicensePlistTests/Entity/PlistInfoTests.swift index ceb8eb81..3204db19 100644 --- a/Tests/LicensePlistTests/Entity/PlistInfoTests.swift +++ b/Tests/LicensePlistTests/Entity/PlistInfoTests.swift @@ -124,12 +124,12 @@ class PlistInfoTests: XCTestCase { target.githubLicenses = [githubLicense] let expectedSummary = """ name: LicensePlist, nameSpecified: LicensePlist, owner: mono0926, version: 0.0.1, source: https://github.com/mono0926/LicensePlist - + name: FooBar, nameSpecified: FooBar, version: 0.0.1 body: body… - + add-version-numbers: false - + LicensePlist Version: 3.25.1 """