Skip to content

Commit

Permalink
support licence & remove licenseType
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyome22 committed Apr 15, 2023
1 parent 6a4b567 commit 725714f
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 128 deletions.
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,11 @@ Generate a list of licenses for the Swift Package libraries that your app depend
<img src="./Screenshots/demo-mit.png" width="240px" />
</div>

## Supported License Types

- Apache license 2.0
- MIT License
- BSD 3-clause Clear license
- zLib License

## Requirements

- Written in Swift 5
- Compatible with iOS 13.0+
- Developement with Xcode 14.0.1+
- Developement with Xcode 14.2+

## Installation

Expand Down
1 change: 0 additions & 1 deletion Sources/LicenseList/Library.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ import Foundation

public struct Library: Hashable {
public let name: String
public let licenseType: String
public let licenseBody: String
}
10 changes: 4 additions & 6 deletions Sources/LicenseList/LicenseListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ public struct LicenseListView: View {
}
let _libraries = (dict["libraries"] as? [[String: Any]])?.compactMap({ info -> Library? in
guard let name = info["name"] as? String,
let type = info["licenseType"] as? String,
let body = info["licenseBody"] as? String else {
return nil
}
return Library(name: name,
licenseType: type,
licenseBody: body)
return Library(name: name, licenseBody: body)
})
guard let libraries = _libraries else {
libraries = []
Expand Down Expand Up @@ -59,8 +56,9 @@ public struct LicenseListView: View {
var navigationController: UINavigationController? {
guard let scene = UIApplication.shared.connectedScenes.first,
let sceneDelegate = scene as? UIWindowScene,
var controller = sceneDelegate.windows.first?.rootViewController
else { return nil }
var controller = sceneDelegate.windows.first?.rootViewController else {
return nil
}
while true {
if let navigationController = controller as? UINavigationController,
let visibleViewController = navigationController.visibleViewController {
Expand Down
1 change: 0 additions & 1 deletion Sources/SourcePackagesParser/Library.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ import Foundation

struct Library: Hashable {
let name: String
let licenseType: LicenseType
let licenseBody: String
}
37 changes: 0 additions & 37 deletions Sources/SourcePackagesParser/LicenseType.swift

This file was deleted.

24 changes: 10 additions & 14 deletions Sources/SourcePackagesParser/SourcePackagesParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ final class SourcePackagesParser {
.replacingOccurrences(of: ".git", with: "")
let directoryURL = URL(fileURLWithPath: checkoutsPath)
.appendingPathComponent(repositoryName)
guard let license = extractLicense(directoryURL) else {
guard let licenseBody = extractLicenseBody(directoryURL) else {
return nil
}
return Library(name: dependency.packageRef.name,
licenseType: license.0,
licenseBody: license.1)
return Library(name: dependency.packageRef.name, licenseBody: licenseBody)
}
.sorted { $0.name.lowercased() < $1.name.lowercased() }

Expand All @@ -53,41 +51,39 @@ final class SourcePackagesParser {
try exportLicenseList(libraries, to: saveURL)
}

private func extractLicense(_ directoryURL: URL) -> (LicenseType, String)? {
private func extractLicenseBody(_ directoryURL: URL) -> String? {
let fm = FileManager.default
let contents = (try? fm.contentsOfDirectory(atPath: directoryURL.path)) ?? []
let _licenseURL = contents.map { content in
return directoryURL.appendingPathComponent(content)
}.filter { contentURL in
if contentURL.deletingPathExtension().lastPathComponent.lowercased() == "license" {
let fileName = contentURL.deletingPathExtension().lastPathComponent.lowercased()
if ["license", "licence"].contains(fileName) {
var isDiractory: ObjCBool = false
fm.fileExists(atPath: contentURL.path, isDirectory: &isDiractory)
return isDiractory.boolValue == false
}
return false
}.first

if let licenseURL = _licenseURL,
let text = try? String(contentsOf: licenseURL) {
return (LicenseType(licenseText: text), text)
guard let licenseURL = _licenseURL,
let text = try? String(contentsOf: licenseURL) else {
return nil
}

return nil
return text
}

private func printLibraries(_ libraries: [Library]) {
let length = libraries.map { $0.name.count }.max() ?? 0
libraries.forEach { library in
let name = library.name.padding(toLength: length, withPad: " ", startingAt: 0)
print(name, library.licenseType.rawValue)
print(name)
}
}

private func exportLicenseList(_ libraries: [Library], to saveURL: URL) throws {
let array: [[String: Any]] = libraries.map { library in
return [
"name": library.name,
"licenseType": library.licenseType.rawValue,
"licenseBody": library.licenseBody
]
}
Expand Down
5 changes: 0 additions & 5 deletions Tests/LicenseListTests/LicenseListTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@ final class LicenseListTests: XCTestCase {
XCTAssertEqual(sut.libraries.count, 5)

XCTAssertEqual(sut.libraries[0].name, "Package-A")
XCTAssertEqual(sut.libraries[0].licenseType, "Unknown License")

XCTAssertEqual(sut.libraries[1].name, "Package-B")
XCTAssertEqual(sut.libraries[1].licenseType, "Apache license 2.0")

XCTAssertEqual(sut.libraries[2].name, "Package-C")
XCTAssertEqual(sut.libraries[2].licenseType, "MIT License")

XCTAssertEqual(sut.libraries[3].name, "Package-D")
XCTAssertEqual(sut.libraries[3].licenseType, "BSD 3-clause Clear license")

XCTAssertEqual(sut.libraries[4].name, "Package-E")
XCTAssertEqual(sut.libraries[4].licenseType, "zLib License")
}
}
58 changes: 24 additions & 34 deletions Tests/LicenseListTests/license-list.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
<key>licenseBody</key>
<string>Unknown License
</string>
<key>licenseType</key>
<string>Unknown License</string>
<key>name</key>
<string>Package-A</string>
</dict>
Expand All @@ -23,60 +21,60 @@
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
&quot;License&quot; shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
&quot;Licensor&quot; shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
&quot;Legal Entity&quot; shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
&quot;control&quot; means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
&quot;You&quot; (or &quot;Your&quot;) shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
&quot;Source&quot; form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
&quot;Object&quot; form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
&quot;Work&quot; shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
&quot;Derivative Works&quot; shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
&quot;Contribution&quot; shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
the copyright owner. For the purposes of this definition, &quot;submitted&quot;
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
designated in writing by the copyright owner as &quot;Not a Contribution.&quot;
"Contributor" shall mean Licensor and any individual or Legal Entity
&quot;Contributor&quot; shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
Expand Down Expand Up @@ -120,7 +118,7 @@
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
(d) If the Work includes a &quot;NOTICE&quot; text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
Expand Down Expand Up @@ -159,7 +157,7 @@
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
Contributor provides its Contributions) on an &quot;AS IS&quot; BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
Expand Down Expand Up @@ -195,24 +193,24 @@
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
boilerplate notice, with the fields enclosed by brackets &quot;[]&quot;
replaced with your own identifying information. (Don&apos;t include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
same &quot;printed page&quot; as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Expand All @@ -227,8 +225,6 @@
you may redistribute such product without providing attribution as would
otherwise be required by Sections 4(a), 4(b) and 4(d) of the License.
</string>
<key>licenseType</key>
<string>Apache license 2.0</string>
<key>name</key>
<string>Package-B</string>
</dict>
Expand All @@ -239,7 +235,7 @@
Copyright (c) 20XX Dummy Human
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
of this software and associated documentation files (the &quot;Software&quot;), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
Expand All @@ -248,7 +244,7 @@ furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Expand All @@ -257,8 +253,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
</string>
<key>licenseType</key>
<string>MIT License</string>
<key>name</key>
<string>Package-C</string>
</dict>
Expand All @@ -281,7 +275,7 @@ contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
&quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Expand All @@ -292,16 +286,14 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</string>
<key>licenseType</key>
<string>BSD 3-clause Clear license</string>
<key>name</key>
<string>Package-D</string>
</dict>
<dict>
<key>licenseBody</key>
<string>Copyright (c) 20XX Dummy Human
This software is provided 'as-is', without any express or
This software is provided &apos;as-is&apos;, without any express or
implied warranty. In no event will the authors be held liable
for any damages arising from the use of this software.
Expand All @@ -320,8 +312,6 @@ redistribute it freely, subject to the following restrictions:
3. This notice may not be removed or altered from any source
distribution.
</string>
<key>licenseType</key>
<string>zLib License</string>
<key>name</key>
<string>Package-E</string>
</dict>
Expand Down
Loading

0 comments on commit 725714f

Please sign in to comment.