Make reading the license files case insensitive. (#7725)

Remove license files that were duplicated but cased differently.

Co-authored-by: Isaac Tell <isaacftell@gmail.comm>
This commit is contained in:
IsaacTell 2023-09-20 22:17:06 +01:00 committed by GitHub
parent 5150c14afd
commit 12dc39591d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 29 deletions

View File

@ -266,37 +266,51 @@ case class Review(root: File, dependencySummary: DependencySummary) {
val customFilename = content.strip()
WithWarnings(LicenseReview.Custom(customFilename))
case None =>
val settingPath =
root / Paths.reviewedLicenses / Review.normalizeName(
info.license.name
)
readFile(settingPath)
.map { content =>
if (content.isBlank) {
WithWarnings(
LicenseReview.NotReviewed,
Seq(s"License review file $settingPath is empty.")
)
} else
try {
val path = Path.of(content.strip())
val bothDefaultAndCustom =
(packageRoot / Paths.defaultAndCustomLicense).exists()
WithWarnings(
LicenseReview.Default(
path,
allowAdditionalCustomLicenses = bothDefaultAndCustom
)
)
} catch {
case e: InvalidPathException =>
val directory = root / Paths.reviewedLicenses
val fileName = Review.normalizeName(info.license.name)
var settingPath = directory / fileName
directory.listFiles.filter(_.getName.equalsIgnoreCase(fileName)) match {
case Array(settingPath) =>
readFile(settingPath)
.map { content =>
if (content.isBlank) {
WithWarnings(
LicenseReview.NotReviewed,
Seq(s"License review file $settingPath is malformed: $e")
Seq(s"License review file $settingPath is empty.")
)
} else
try {
val path = Path.of(content.strip())
val bothDefaultAndCustom =
(packageRoot / Paths.defaultAndCustomLicense).exists()
WithWarnings(
LicenseReview.Default(
path,
allowAdditionalCustomLicenses = bothDefaultAndCustom
)
)
} catch {
case e: InvalidPathException =>
WithWarnings(
LicenseReview.NotReviewed,
Seq(
s"License review file $settingPath is malformed: $e"
)
)
}
}
}
.getOrElse(WithWarnings(LicenseReview.NotReviewed))
.getOrElse(WithWarnings(LicenseReview.NotReviewed))
case Array(_, _*) =>
WithWarnings(
LicenseReview.NotReviewed,
Seq(s"Multiple copies of file $settingPath with differing case.")
)
case Array() =>
WithWarnings(
LicenseReview.NotReviewed,
Seq(s"License review file $settingPath is missing.")
)
}
}
/** Reads the file as lines.

View File

@ -1 +0,0 @@
tools/legal-review/license-texts/APACHE2.0

View File

@ -1 +0,0 @@
tools/legal-review/license-texts/APACHE2.0