Skip to content

Commit 13e6c67

Browse files
committed
Support LICENCE
1 parent 2763ebe commit 13e6c67

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

Sources/LicenseCheckerModule/PackageParser.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public struct PackageParser {
3535
let _licenseURL = contents.map { content in
3636
return dirURL.appendingPathComponent(content)
3737
}.filter { contentURL in
38-
if contentURL.lastPathComponent.lowercased().hasPrefix("license") {
38+
let fileName = contentURL.deletingPathExtension().lastPathComponent.lowercased()
39+
if ["license", "licence"].contains(fileName) {
3940
var isDiractory: ObjCBool = false
4041
fm.fileExists(atPath: contentURL.path, isDirectory: &isDiractory)
4142
return isDiractory.boolValue == false
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 20XX Developer
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Tests/LicenseCheckerModuleTests/PackageParserTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ final class PackageParserTests: XCTestCase {
8282
XCTAssertEqual(sut, [expect])
8383
}
8484

85+
func test_extractLicence() throws {
86+
let jsonPath = "SourcePackagesUnknown/workspace-state"
87+
let jsonURL = try XCTUnwrap(testResources.getJsonUrl(jsonPath))
88+
let packageParser = try XCTUnwrap(PackageParser(url: jsonURL))
89+
90+
let resourceURL = try XCTUnwrap(testResources.resourceURL)
91+
let dirURL = resourceURL.appendingPathComponent("SourcePackagesLICENCE")
92+
.appendingPathComponent("checkouts")
93+
.appendingPathComponent("mit-package")
94+
95+
let sut = packageParser.extractLicense(dirURL: dirURL)
96+
XCTAssertEqual(sut, LicenseType.mit)
97+
}
98+
8599
// BSD
86100
func test_extractLicense_bsd() throws {
87101
let jsonPath = "SourcePackagesUnknown/workspace-state"

0 commit comments

Comments
 (0)