-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
18 additions
and
39 deletions.
There are no files selected for viewing
57 changes: 18 additions & 39 deletions
57
src/main/kotlin/sh/suiyun/chooseLicense/license/License.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,41 @@ | ||
package sh.suiyun.chooseLicense.license | ||
|
||
class License(val spdxId: String, val content: String) { | ||
private fun replaceAuthor(author: String, text: String): String { | ||
when (spdxId) { | ||
"AGPL-3.0", "GPL-2.0", "GPL-3.0", "LGPL-2.1" -> { | ||
return text.replace("<name of author>", author) | ||
} | ||
|
||
"Apache-2.0" -> { | ||
return text.replace("[name of copyright owner]", author) | ||
} | ||
|
||
"BSD-2-Clause", "BSD-3-Clause", "BSD-3-Clause-Clear", "BSD-4-Clause", "MIT", "MIT-0", "ISC" -> { | ||
return text.replace("[fullname]", author) | ||
} | ||
|
||
"WTFPL" -> { | ||
return text.replace("Sam Hocevar <[email protected]>", author) | ||
} | ||
|
||
else -> { | ||
return text | ||
} | ||
} | ||
} | ||
|
||
private fun replaceYear(year: String, text: String): String { | ||
/** | ||
* 生成 license | ||
*/ | ||
fun generateLicense(author: String, year: String): String { | ||
when (spdxId) { | ||
"AGPL-3.0", "GPL-2.0", "GPL-3.0", "LGPL-2.1" -> { | ||
return text.replace("<year>", year) | ||
return content | ||
.replace("<name of author>", author) | ||
.replace("<year>", year) | ||
} | ||
|
||
"Apache-2.0" -> { | ||
return text.replace("[yyyy]", year) | ||
return content | ||
.replace("[name of copyright owner]", author) | ||
.replace("[yyyy]", year) | ||
} | ||
|
||
"BSD-2-Clause", "BSD-3-Clause", "BSD-3-Clause-Clear", "BSD-4-Clause", "MIT", "MIT-0", "ISC" -> { | ||
return text.replace("[year]", year) | ||
"0BSD", "BSD-2-Clause", "BSD-3-Clause", "BSD-3-Clause-Clear", "BSD-4-Clause", "MIT", "MIT-0", "ISC" -> { | ||
return content | ||
.replace("[fullname]", author) | ||
.replace("[year]", year) | ||
} | ||
|
||
"WTFPL" -> { | ||
return text.replace("Copyright (C) 2004", "Copyright (C) $year") | ||
return content | ||
.replace("Sam Hocevar <[email protected]>", author) | ||
.replace("Copyright (C) 2004", "Copyright (C) $year") | ||
} | ||
|
||
else -> { | ||
return text | ||
return content | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* 生成 license | ||
*/ | ||
fun generateLicense(author: String, year: String): String { | ||
val text = replaceAuthor(author, content) | ||
return replaceYear(year, text) | ||
} | ||
|
||
override fun toString(): String { | ||
return spdxId | ||
} | ||
|