Skip to content

Commit

Permalink
- switch from fully qualified names to partly qualified names (class …
Browse files Browse the repository at this point in the history
…name + property name) in `excludeFields`
  • Loading branch information
SageDroid committed Aug 21, 2024
1 parent dd927f5 commit 121e536
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.mikepenz.aboutlibraries.plugin.model

import com.mikepenz.aboutlibraries.plugin.mapping.Developer
import com.mikepenz.aboutlibraries.plugin.mapping.Funding
import com.mikepenz.aboutlibraries.plugin.mapping.Library
import com.mikepenz.aboutlibraries.plugin.mapping.License
import com.mikepenz.aboutlibraries.plugin.mapping.Organization
import com.mikepenz.aboutlibraries.plugin.mapping.Scm
import com.mikepenz.aboutlibraries.plugin.util.PartialObjectConverter
import groovy.json.JsonGenerator
import groovy.json.JsonOutput
Expand All @@ -27,14 +31,25 @@ class MetaData(
)

fun ResultContainer.writeToDisk(outputFile: File, excludeFields: Array<String>, prettyPrint: Boolean) {
val allowedQualifiers = setOf(
ResultContainer::class.simpleName,
Library::class.simpleName,
Developer::class.simpleName,
Organization::class.simpleName,
Funding::class.simpleName,
Scm::class.simpleName,
License::class.simpleName,
MetaData::class.simpleName,
)
val qualifiedFieldNames = mutableSetOf(
"${Library::class.qualifiedName}.${Library::artifactId.name}",
"${Library::class.qualifiedName}.${Library::groupId.name}",
"${Library::class.qualifiedName}.${Library::artifactFolder.name}"
"${Library::class.simpleName}.${Library::artifactId.name}",
"${Library::class.simpleName}.${Library::groupId.name}",
"${Library::class.simpleName}.${Library::artifactFolder.name}"
)
val unqualifiedFieldNames = mutableSetOf<String>()
excludeFields.forEach { excludedField ->
if (excludedField.startsWith("com.mikepenz.aboutlibraries.plugin")) {
val segments = excludedField.split(".")
if (segments.size == 2 && allowedQualifiers.contains(segments.first())) {
qualifiedFieldNames.add(excludedField)
} else {
unqualifiedFieldNames.add(excludedField)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.codehaus.groovy.runtime.DefaultGroovyMethods
/**
* A converter for [JsonGenerator], which allows properties to be excluded from the output.
* The way it works is identical to the serialization of objects in [DefaultJsonGenerator].
* @property excludedQualifiedPropertyNames The fully qualified name (package name + class name + property name)
* @property excludedQualifiedPropertyNames The qualified name (class name + property name)
* of the properties that should be excluded from serialization.
*/
class PartialObjectConverter(
Expand All @@ -21,12 +21,12 @@ class PartialObjectConverter(
private val excludedPropertyNames = setOf("class", "declaringClass", "metaClass")

override fun handles(type: Class<*>?): Boolean {
return type != null && targetClassNames.contains(type.name)
return type != null && targetClassNames.contains(type.simpleName)
}

override fun convert(value: Any, key: String?): Any {
return DefaultGroovyMethods.getProperties(value).filterKeys { propertyName ->
propertyName !in excludedPropertyNames && "${value::class.qualifiedName}.$propertyName" !in excludedQualifiedPropertyNames
propertyName !in excludedPropertyNames && "${value::class.simpleName}.$propertyName" !in excludedQualifiedPropertyNames
}
}

Expand Down

0 comments on commit 121e536

Please sign in to comment.