Skip to content

Commit

Permalink
feat: 合并生成方法, 补充缺失的规则
Browse files Browse the repository at this point in the history
  • Loading branch information
suiyun39 committed Jan 15, 2024
1 parent 24830b2 commit 5ff41cc
Showing 1 changed file with 18 additions and 39 deletions.
57 changes: 18 additions & 39 deletions src/main/kotlin/sh/suiyun/chooseLicense/license/License.kt
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
}
Expand Down

0 comments on commit 5ff41cc

Please sign in to comment.