Skip to content

Commit

Permalink
- improve naming
Browse files Browse the repository at this point in the history
  • Loading branch information
SageDroid committed Aug 21, 2024
1 parent 121e536 commit 0151ec0
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MetaData(
)

fun ResultContainer.writeToDisk(outputFile: File, excludeFields: Array<String>, prettyPrint: Boolean) {
val allowedQualifiers = setOf(
val allowedExclusionQualifiers = setOf(
ResultContainer::class.simpleName,
Library::class.simpleName,
Developer::class.simpleName,
Expand All @@ -41,24 +41,24 @@ fun ResultContainer.writeToDisk(outputFile: File, excludeFields: Array<String>,
License::class.simpleName,
MetaData::class.simpleName,
)
val qualifiedFieldNames = mutableSetOf(
val excludedQualifiedFieldNames = mutableSetOf(
"${Library::class.simpleName}.${Library::artifactId.name}",
"${Library::class.simpleName}.${Library::groupId.name}",
"${Library::class.simpleName}.${Library::artifactFolder.name}"
)
val unqualifiedFieldNames = mutableSetOf<String>()
val excludedUnqualifiedFieldNames = mutableSetOf<String>()
excludeFields.forEach { excludedField ->
val segments = excludedField.split(".")
if (segments.size == 2 && allowedQualifiers.contains(segments.first())) {
qualifiedFieldNames.add(excludedField)
if (segments.size == 2 && allowedExclusionQualifiers.contains(segments.first())) {
excludedQualifiedFieldNames.add(excludedField)
} else {
unqualifiedFieldNames.add(excludedField)
excludedUnqualifiedFieldNames.add(excludedField)
}
}
val jsonGenerator = JsonGenerator.Options()
.excludeNulls()
.excludeFieldsByName(unqualifiedFieldNames)
.addConverter(PartialObjectConverter(qualifiedFieldNames))
.excludeFieldsByName(excludedUnqualifiedFieldNames)
.addConverter(PartialObjectConverter(excludedQualifiedFieldNames))
.build()
PrintWriter(OutputStreamWriter(outputFile.outputStream(), StandardCharsets.UTF_8), true).use {
it.write(jsonGenerator.toJson(this).let { json -> if (prettyPrint) JsonOutput.prettyPrint(json) else json })
Expand Down

0 comments on commit 0151ec0

Please sign in to comment.