@@ -14,29 +14,27 @@ It can detect libraries that are not included in a whitelist specifying the lice
1414
1515``` shell
1616$ license-checker --source-packages-path ~ /SourcePackages --white-list-path ~ /white-list.json
17- abseil Apache
18- BoringSSL-GRPC BoringSSL
19- Eureka MIT
20- Firebase Apache
21- GoogleAppMeasurement Apache
22- GoogleDataTransport Apache
23- GoogleUtilities MIT
24- gRPC Apache
25- GTMSessionFetcher Apache
26- Kanna MIT
27- KeychainAccess MIT
28- Kingfisher MIT
29- leveldb BSD
30- LicenseChecker unknown
31- LicenseList MIT
32- nanopb zlib
33- ObjectMapper MIT
34- Promises Apache
35- R.swift.Library MIT
36- Reachability MIT
37- RxGesture MIT
38- RxSwift MIT
39- SwiftProtobuf Apache
17+ ✔︎ abseil Apache
18+ ✔︎ BoringSSL-GRPC BoringSSL
19+ ✔︎ Firebase Apache
20+ ✔︎ GoogleAppMeasurement Apache
21+ ✔︎ GoogleDataTransport Apache
22+ ✔︎ GoogleUtilities MIT
23+ ✔︎ gRPC Apache
24+ ✔︎ GTMSessionFetcher Apache
25+ ✔︎ Kanna MIT
26+ ✔︎ KeychainAccess MIT
27+ ✔︎ Kingfisher MIT
28+ ✔︎ leveldb BSD
29+ ✔︎ LicenseList MIT
30+ ✔︎ nanopb zlib
31+ ✔︎ ObjectMapper MIT
32+ ✔︎ Promises Apache
33+ ✔︎ R.swift.Library MIT
34+ ✔︎ Reachability MIT
35+ ✔︎ RxGesture MIT
36+ ✔︎ RxSwift MIT
37+ ✔︎ SwiftProtobuf Apache
4038✅ No problems with library licensing.
4139$
4240```
@@ -134,8 +132,6 @@ LicenseChecker supports the following licenses:
134132 license-checker -s ${SOURCE_PACKAGES_PATH} -w [Path to white-list.json]
135133 ```
136134
137- ⚠️ ` white-list.json ` must be included in Target Membership.
138-
139135### BuildToolPlugin (for Swift Package Project)
140136
1411371 . Add binary target & plugin to ` Package.swift ` .
@@ -165,25 +161,33 @@ LicenseChecker supports the following licenses:
165161
166162 @main
167163 struct LicenseCheckerPlugin : BuildToolPlugin {
164+ enum LCError : Error {
165+ case sourcePackagesNotFound
166+ }
167+
168+ func sourcePackages (_ pluginWorkDirectory : Path) throws -> Path {
169+ var tmpPath = pluginWorkDirectory
170+ guard pluginWorkDirectory.string.contains (" SourcePackages" ) else {
171+ throw LCError.sourcePackagesNotFound
172+ }
173+ while tmpPath.lastComponent != " SourcePackages" {
174+ tmpPath = tmpPath.removingLastComponent ()
175+ }
176+ return tmpPath
177+ }
178+
168179 func createBuildCommands (context : PluginContext, target : Target) async throws -> [Command] {
180+ let executablePath = try context.tool (named : " license-checker" ).path
181+ let sourcePackagesPath = try sourcePackages (context.pluginWorkDirectory )
169182 let whiteListPath = " Path to white-list.json" // Please change accordingly.
170- let pluginWorkDirectory = context.pluginWorkDirectory .string
171- let regex = try NSRegularExpression (pattern : " .*SourcePackages" )
172- let range = NSMakeRange (0 , pluginWorkDirectory.utf16 .count )
173- guard let result = regex.firstMatch (in : pluginWorkDirectory, range : range) else {
174- throw NSError (domain : " com.cybozu.LicenseCheckerPlugin" ,
175- code : 1 ,
176- userInfo : [" message" : " Failed to match" ])
177- }
178- let sourcePackageDirectory = NSString (string : pluginWorkDirectory)
179- .substring (with : result.range (at : 0 ))
183+
180184 return [
181185 .prebuildCommand (
182- displayName : " LicenseChecker " ,
183- executable : try context. tool ( named : " license-checker " ). path ,
186+ displayName : " Prepare LicenseList " ,
187+ executable : executablePath ,
184188 arguments : [
185189 " --source-packages-path" ,
186- sourcePackageDirectory ,
190+ sourcePackagesPath. string ,
187191 " --white-list-path" ,
188192 whiteListPath
189193 ],
@@ -220,9 +224,9 @@ USAGE: license-checker --source-packages-path <source-packages-path> --white-lis
220224
221225OPTIONS:
222226 -s, --source-packages-path < source-packages-path>
223- Path of SourcePackages directory
227+ Path to SourcePackages directory
224228 -w, --white-list-path < white-list-path>
225- Path of white-list.json
229+ Path to white-list.json
226230 --version Show the version.
227231 -h, --help Show help information.
228232```
0 commit comments