Skip to content

Commit

Permalink
# configured maven-publish
Browse files Browse the repository at this point in the history
  • Loading branch information
sbra0902 committed Dec 7, 2023
1 parent 50c25a5 commit 7054d76
Show file tree
Hide file tree
Showing 51 changed files with 173 additions and 126 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:8.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.21"
classpath "org.jlleitschuh.gradle:ktlint-gradle:10.2.0"
classpath "org.jlleitschuh.gradle:ktlint-gradle:11.5.1"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ open class DefaultSchemaValidator : SchemaValidator {
}

protected open fun validateModelLevel(current: EntitySchema?, released: EntitySchema, logger: SchemaValidationLogger): Boolean {

current?.let {

released.docId?.let {
if (current.docId?.scheme != it.scheme) {
logger.error(released, "forbidden DocId Schema change")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ object CrystalWrap {
PersistenceConfig.onTypeConversionError(
com.schwarz.crystalapi.TypeConversionErrorWrapper(
ex,
fieldName, value, clazz
fieldName,
value,
clazz
)
)
null
Expand All @@ -117,7 +119,9 @@ object CrystalWrap {
PersistenceConfig.onTypeConversionError(
com.schwarz.crystalapi.TypeConversionErrorWrapper(
ex,
fieldName, value, clazz
fieldName,
value,
clazz
)
)
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package com.schwarz.crystalapi.util

import com.schwarz.crystalapi.mapify.IMapifyable
import org.apache.commons.codec.binary.Base64
import java.io.*
import java.util.*
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.ObjectInputStream
import java.io.ObjectOutputStream
import java.io.Serializable

class SerializableMapifyable<T : Serializable> : IMapifyable<T?> {
override fun fromMap(map: Map<String, Any>): T? = (map.get("serial") as? String)?.let { serializableFromMapValue<T>(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ abstract class Couchbase2Connector : PersistenceConfig.Connector {
onlyInclude: List<String>?
): List<Map<String, Any>> {
try {

val builder = QueryBuilder.select(SelectResult.expression(Meta.id), SelectResult.all())
.from(DataSource.database(getDatabase(dbName)))

Expand Down Expand Up @@ -131,11 +130,9 @@ abstract class Couchbase2Connector : PersistenceConfig.Connector {
}

private fun parseExpressions(queryParams: Map<String, Any?>): Expression? {

var result: Expression? = null

for (queryParam in queryParams) {

val equalTo = Expression.property(queryParam.key).equalTo(
Expression.value(queryParam.value)
)
Expand Down
21 changes: 19 additions & 2 deletions crystal-map-processor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ dependencies {
implementation 'org.apache.commons:commons-lang3:3.4'
implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.13.3"
implementation 'com.j2html:j2html:1.4.0'
testImplementation 'com.google.testing.compile:compile-testing:0.19'
testImplementation 'com.google.testing.compile:compile-testing:0.21.0'
testImplementation 'junit:junit:4.12'
testImplementation 'com.github.tschuchortdev:kotlin-compile-testing:1.4.9'
testImplementation 'dev.zacsweers.kctfork:core:0.4.0'
testImplementation 'org.mockito:mockito-core:1.10.19'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0'
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
Expand All @@ -32,6 +32,23 @@ java {
withJavadocJar()
}

if (JavaVersion.current() >= JavaVersion.VERSION_16) {
test {
jvmArgs(
"--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
)
}
}

publishing {
publications {
maven(MavenPublication) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import javax.annotation.processing.*
import javax.lang.model.SourceVersion
import javax.lang.model.element.TypeElement

@SupportedSourceVersion(SourceVersion.RELEASE_8)
@SupportedSourceVersion(SourceVersion.RELEASE_17)
@AutoService(Processor::class)
@SupportedOptions(KAPT_KOTLIN_GENERATED_OPTION_NAME, FRAMEWORK_USE_SUSPEND_OPTION_NAME, FRAMEWORK_DOCUMENTATION_PATH_OPTION_NAME, FRAMEWORK_DOCUMENTATION_FILENAME_OPTION_NAME, FRAMEWORK_SCHEMA_PATH_OPTION_NAME, FRAMEWORK_SCHEMA_FILENAME_OPTION_NAME)
class CoachBaseBinderProcessor : AbstractProcessor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ fun TypeName.javaToKotlinType(): TypeName = if (this is ParameterizedTypeName) {
} else {
val className = JavaToKotlinClassMap.INSTANCE
.mapJavaToKotlin(FqName(toString()))?.asSingleFqName()?.asString()
if (className == null) this
else ClassName.bestGuess(className)
if (className == null) {
this
} else {
ClassName.bestGuess(className)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ object ProcessingContext {
fun asFullTypeName(): TypeName? = asTypeName()?.let {
if (it is ClassName && typeParams.isNotEmpty()) {
it.parameterizedBy(typeParams.mapNotNull { if (it.isTypeVar()) TypeVariableName(it.name) else it.asFullTypeName() })
} else it
} else {
it
}
}

fun hasEmptyConstructor() = (typeMirror as? Type.ClassType?)?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,15 @@ class DocumentationGenerator(path: String, fileName: String) {

val btnWithSectionLink = "<button onclick=\"alert(window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.search + '#${entityHolder.sourceClazzSimpleName}');\">showLink</button>"
docuEntitySegments[entityHolder.sourceClazzSimpleName] = div().withId(entityHolder.sourceClazzSimpleName).with(
h1(entityHolder.sourceClazzSimpleName), rawHtml(btnWithSectionLink), evaluateAvailableTypes(entityHolder.sourceElement), br(), *buildComment(entityHolder.comment), br(),
h1(entityHolder.sourceClazzSimpleName),
rawHtml(btnWithSectionLink),
evaluateAvailableTypes(entityHolder.sourceElement),
br(),
*buildComment(entityHolder.comment),
br(),
table(
attrs(".table"), thead(*createTableHead()),
attrs(".table"),
thead(*createTableHead()),
tbody(
each(entityHolder.fields) { field ->
tr(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class CodeGenerator(private val filer: Filer) {

@Throws(IOException::class)
fun generate(entityToGenerate: FileSpec, processingEnvironment: ProcessingEnvironment) {

ClassName(entityToGenerate.packageName, entityToGenerate.name)?.apply {
ProcessingContext.createdQualifiedClazzNames.add(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import java.util.*
class MapperGeneration {

fun generate(holder: MapperHolder): FileSpec {

val mapperTypeParam = holder.declaringName.asFullTypeName() ?: holder.sourceClazzTypeName

val typeSpec = TypeSpec.classBuilder(holder.targetMapperSimpleName)
Expand Down Expand Up @@ -53,9 +52,7 @@ class MapperGeneration {

val addedHelpers = mutableSetOf<String>()
for (fieldWithTypeParam in holder.fields.values.filter { it.typeHandleMode == MapifyHolder.TypeHandleMode.MAPPER && it.declaringName.typeParams.isNotEmpty() }) {

for (mapifyHelper in fieldWithTypeParam.declaringName.typeParams) {

val helperClazzName = buildHelperClazzName(mapifyHelper)

if (addedHelpers.contains(helperClazzName)) {
Expand Down Expand Up @@ -94,7 +91,6 @@ class MapperGeneration {
}

for (field in holder.fields.values) {

typeSpec.addProperties(field.reflectionProperties(holder.sourceClazzTypeName))

typeSpec.addProperty(
Expand Down Expand Up @@ -148,7 +144,6 @@ class MapperGeneration {

@Throws(Exception::class)
private fun resolveDeclaringName(name: ProcessingContext.DeclaringName, resolverParam: ResolverParam, accessorName: String, typeParams: List<ProcessingContext.DeclaringName>) {

if (name.isProcessingType()) {
resolverParam.fromMapBuilder.addStatement("%T.Mapper().fromMap(it as %T)", name.asTypeName()!!, TypeUtil.mapStringAny())

Expand All @@ -166,7 +161,6 @@ class MapperGeneration {
}

if (name.isTypeVar()) {

typeParams.indexOfFirst { it.name == name.name }?.let {
resolverParam.fromMapBuilder.addStatement("typeParam$it.fromMap(it as %T)", TypeUtil.mapStringAny())
resolverParam.toMapBuilder.addStatement("typeParam$it.toMap(it)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import com.squareup.kotlinpoet.KModifier
object CblConstantGeneration {

fun addConstants(holder: BaseEntityHolder, useNullableMap: Boolean): FunSpec {

val type = if (useNullableMap) TypeUtil.mutableMapStringAnyNullable() else TypeUtil.mutableMapStringAny()
val builder = FunSpec.builder("addConstants").addModifiers(KModifier.PRIVATE).addParameter("map", type)

for (fieldHolder in holder.fieldConstants.values) {

if (fieldHolder.isConstant) {
builder.addStatement("map.put(%N, DOC_%N)", fieldHolder.constantName, fieldHolder.constantName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.squareup.kotlinpoet.KModifier
object CblDefaultGeneration {

fun addDefaults(holder: BaseEntityHolder, useNullableMap: Boolean): FunSpec {

val type =
if (useNullableMap) TypeUtil.mutableMapStringAnyNullable() else TypeUtil.mutableMapStringAny()
val valueType =
Expand All @@ -25,14 +24,14 @@ object CblDefaultGeneration {

builder.addStatement("%T.addDefaults<%T, %T>(listOf(", CrystalWrap::class, typeConversionReturnType, valueType)
for (fieldHolder in holder.fields.values) {

if (fieldHolder.isDefault) {
builder.addStatement(
"arrayOf(%N, %T::class, ${ConversionUtil.convertStringToDesiredFormat(
fieldHolder.typeMirror,
fieldHolder.defaultValue
)}),",
fieldHolder.constantName, fieldHolder.fieldType
fieldHolder.constantName,
fieldHolder.fieldType
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.squareup.kotlinpoet.PropertySpec
object CblReduceGeneration {

fun onlyIncludeProperty(holder: BaseEntityHolder): PropertySpec {

val spec = PropertySpec.builder(PROPERTY_ONLY_INCLUDES, TypeUtil.list(TypeUtil.string()).copy(nullable = true))

if (holder.isReduced) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ private const val GENERATED_REPRESENT_NAME = "Represent"
class CommonInterfaceGeneration {

fun generateModel(holder: BaseEntityHolder, useSuspend: Boolean): FileSpec {

val interfaceSpec = TypeSpec.interfaceBuilder(holder.interfaceSimpleName)
interfaceSpec.addSuperinterface(TypeUtil.mapSupport())

Expand Down Expand Up @@ -40,7 +39,6 @@ class CommonInterfaceGeneration {
}

private fun generateRepresent(holder: BaseModelHolder, parent: TypeSpec.Builder, useSuspend: Boolean) {

val typeBuilder = TypeSpec.classBuilder(GENERATED_REPRESENT_NAME)
.addSuperinterface(TypeUtil.mapSupport())
.addModifiers(KModifier.PRIVATE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.squareup.kotlinpoet.FunSpec
object EnsureTypesGeneration {

fun ensureTypes(holder: BaseEntityHolder, useNullableMap: Boolean): FunSpec {

val explicitType =
if (useNullableMap) TypeUtil.hashMapStringAnyNullable() else TypeUtil.hashMapStringAny()
val type = if (useNullableMap) TypeUtil.mapStringAnyNullable() else TypeUtil.mapStringAny()
Expand All @@ -20,7 +19,6 @@ object EnsureTypesGeneration {

ensureTypes.addStatement("result.putAll(%T.ensureTypes<%T>(mapOf(", CrystalWrap::class, typeConversionReturnType)
for (field in holder.fields.values) {

ensureTypes.addStatement("%N to %T::class,", field.constantName, field.evaluateClazzForTypeConversion())
}
ensureTypes.addStatement("), doc))")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,24 +280,30 @@ class EntityGeneration {
}

private fun evaluateModifiers(useSuspend: Boolean): List<KModifier> {
return if (useSuspend) listOf(
KModifier.PUBLIC,
KModifier.SUSPEND
) else listOf(KModifier.PUBLIC)
return if (useSuspend) {
listOf(
KModifier.PUBLIC,
KModifier.SUSPEND
)
} else {
listOf(KModifier.PUBLIC)
}
}

private fun create(holder: EntityHolder, useSuspend: Boolean): List<FunSpec> {

return listOf(
FunSpec.builder("create").addModifiers(evaluateModifiers(useSuspend))
.addParameter("id", String::class).addAnnotation(JvmStatic::class).addStatement(
"return %N(%T.${getDocumentMethod(useSuspend)}(id, %S) ?: mutableMapOf(_ID to id))",
holder.entitySimpleName, PersistenceConfig::class, holder.dbName
holder.entitySimpleName,
PersistenceConfig::class,
holder.dbName
).returns(holder.entityTypeName).build(),
FunSpec.builder("create").addModifiers(evaluateModifiers(useSuspend))
.addAnnotation(JvmStatic::class).addStatement(
"return %N(%T())",
holder.entitySimpleName, TypeUtil.hashMapStringAny()
holder.entitySimpleName,
TypeUtil.hashMapStringAny()
).returns(holder.entityTypeName).build(),
FunSpec.builder("create").addModifiers(KModifier.PUBLIC)
.addParameter("map", TypeUtil.mutableMapStringAny()).addAnnotation(JvmStatic::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.squareup.kotlinpoet.FunSpec
class RebindMethodGeneration {

fun generate(clearMDocChanges: Boolean): FunSpec {

val explicitType = if (clearMDocChanges) TypeUtil.hashMapStringAny() else TypeUtil.linkedHashMapStringAnyNullable()
val type = if (clearMDocChanges) TypeUtil.mapStringAny() else TypeUtil.mapStringAnyNullable()
val rebind = FunSpec.builder("rebind").addParameter("doc", type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.squareup.kotlinpoet.KModifier
class SetAllMethodGeneration {

fun generate(holder: BaseEntityHolder, useMDocChanges: Boolean): FunSpec {

val attributeName = if (useMDocChanges) "mDocChanges" else "mDoc"
val setAllBuilder = FunSpec.builder("setAll").addModifiers(KModifier.PUBLIC, KModifier.OVERRIDE)
.addParameter("map", TypeUtil.mapStringAnyNullable()).addStatement(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import java.util.*
class WrapperGeneration {

fun generateModel(holder: WrapperEntityHolder, useSuspend: Boolean): FileSpec {

val companionSpec = TypeSpec.companionObjectBuilder()

val builderBuilder = BuilderClassGeneration.generateBaseBuilder(holder)
Expand Down Expand Up @@ -46,7 +45,6 @@ class WrapperGeneration {
}

for (fieldHolder in holder.allFields) {

companionSpec.addProperties(fieldHolder.createFieldConstant())
typeBuilder.addProperty(fieldHolder.property(null, holder.abstractParts, false, holder.deprecated))
fieldHolder.builderSetter(null, holder.sourcePackage, holder.entitySimpleName, false, holder.deprecated)?.let {
Expand Down Expand Up @@ -126,15 +124,15 @@ class WrapperGeneration {
}

private fun create(holder: WrapperEntityHolder): List<FunSpec> {

return Arrays.asList(
FunSpec.builder("create").addModifiers(KModifier.PUBLIC).addParameter("doc", TypeUtil.mutableMapStringAnyNullable()).addAnnotation(JvmStatic::class).addStatement(
"return %N(doc)",
holder.entitySimpleName
).returns(holder.entityTypeName).build(),
FunSpec.builder("create").addModifiers(KModifier.PUBLIC).addAnnotation(JvmStatic::class).addStatement(
"return %N(%T())",
holder.entitySimpleName, TypeUtil.hashMapStringAnyNullable()
holder.entitySimpleName,
TypeUtil.hashMapStringAnyNullable()
).returns(holder.entityTypeName).build()
)
}
Expand Down
Loading

0 comments on commit 7054d76

Please sign in to comment.