diff --git a/build.gradle b/build.gradle index 426715e..4cadaba 100755 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.50' + ext.kotlin_version = '1.5.10' repositories { google() jcenter() diff --git a/kokain-di/src/main/java/com/schwarz/kokain/di/observer/ActivityRefered.kt b/kokain-core-api/src/main/java/com/schwarz/kokain/api/internal/ActivityRefered.kt similarity index 60% rename from kokain-di/src/main/java/com/schwarz/kokain/di/observer/ActivityRefered.kt rename to kokain-core-api/src/main/java/com/schwarz/kokain/api/internal/ActivityRefered.kt index f229430..d355b39 100644 --- a/kokain-di/src/main/java/com/schwarz/kokain/di/observer/ActivityRefered.kt +++ b/kokain-core-api/src/main/java/com/schwarz/kokain/api/internal/ActivityRefered.kt @@ -1,4 +1,4 @@ -package com.schwarz.kokain.di.observer +package com.schwarz.kokain.api.internal interface ActivityRefered { diff --git a/kokain-di/src/main/java/com/schwarz/kokain/di/scope/BeanScope.kt b/kokain-core-api/src/main/java/com/schwarz/kokain/api/internal/BeanScope.kt similarity index 69% rename from kokain-di/src/main/java/com/schwarz/kokain/di/scope/BeanScope.kt rename to kokain-core-api/src/main/java/com/schwarz/kokain/api/internal/BeanScope.kt index d333567..2c6ff5c 100644 --- a/kokain-di/src/main/java/com/schwarz/kokain/di/scope/BeanScope.kt +++ b/kokain-core-api/src/main/java/com/schwarz/kokain/api/internal/BeanScope.kt @@ -1,4 +1,4 @@ -package com.schwarz.kokain.di.scope +package com.schwarz.kokain.api.internal import com.schwarz.kokain.api.EBean diff --git a/kokain-di/src/main/java/com/schwarz/kokain/di/ActivityContextGuard.kt b/kokain-di/src/main/java/com/schwarz/kokain/di/ActivityContextGuard.kt index 85e5b74..d569930 100644 --- a/kokain-di/src/main/java/com/schwarz/kokain/di/ActivityContextGuard.kt +++ b/kokain-di/src/main/java/com/schwarz/kokain/di/ActivityContextGuard.kt @@ -3,7 +3,6 @@ package com.schwarz.kokain.di import android.app.Activity import android.app.Application import android.content.Context -import android.util.Log import android.view.View import androidx.activity.ComponentActivity import androidx.fragment.app.Fragment @@ -11,8 +10,8 @@ import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleObserver import androidx.lifecycle.OnLifecycleEvent import com.schwarz.kokain.api.EBean -import com.schwarz.kokain.di.observer.ActivityRefered -import com.schwarz.kokain.di.scope.BeanScope +import com.schwarz.kokain.api.internal.ActivityRefered +import com.schwarz.kokain.api.internal.BeanScope import java.lang.ref.WeakReference import kotlin.reflect.KProperty diff --git a/kokain-di/src/main/java/com/schwarz/kokain/di/observer/BeanLifecycleCurator.kt b/kokain-di/src/main/java/com/schwarz/kokain/di/observer/BeanLifecycleCurator.kt index f0f1941..357df45 100644 --- a/kokain-di/src/main/java/com/schwarz/kokain/di/observer/BeanLifecycleCurator.kt +++ b/kokain-di/src/main/java/com/schwarz/kokain/di/observer/BeanLifecycleCurator.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.LifecycleObserver import androidx.lifecycle.OnLifecycleEvent import com.schwarz.kokain.api.EBean import com.schwarz.kokain.api.KDiFactory +import com.schwarz.kokain.api.internal.BeanScope import com.schwarz.kokain.di.scope.* import kotlin.reflect.KClass diff --git a/kokain-processor/build.gradle b/kokain-processor/build.gradle index cbf7382..40db9ff 100644 --- a/kokain-processor/build.gradle +++ b/kokain-processor/build.gradle @@ -7,14 +7,12 @@ apply plugin: 'kotlin-kapt' dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.squareup:kotlinpoet:1.6.0' - implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.1.0" + implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.3.0" implementation project(path: ':kokain-core-api', configuration: 'default') implementation 'org.apache.commons:commons-lang3:3.4' - testImplementation 'com.google.testing.compile:compile-testing:0.11' testImplementation 'junit:junit:4.12' testImplementation project(path: ':kokain-core-api', configuration: 'default') - testImplementation 'com.google.truth:truth:1.0' - testImplementation 'com.github.tschuchortdev:kotlin-compile-testing:1.2.7' + testImplementation 'com.github.tschuchortdev:kotlin-compile-testing:1.4.2' testImplementation 'org.mockito:mockito-core:1.10.19' kapt "com.google.auto.service:auto-service:1.0-rc6" implementation "com.google.auto.service:auto-service:1.0-rc6" @@ -22,8 +20,8 @@ dependencies { } -targetCompatibility = '1.7' -sourceCompatibility = '1.7' +targetCompatibility = '1.8' +sourceCompatibility = '1.8' task sourcesJar(type: Jar, dependsOn: classes) { classifier = 'sources' @@ -35,6 +33,10 @@ task javadocJar(type: Jar, dependsOn: javadoc) { from javadoc.destinationDir } +jacoco { + toolVersion = "0.8.7" +} + jacocoTestReport { group 'verification' dependsOn 'test' @@ -51,7 +53,7 @@ artifacts { archives javadocJar } buildscript { - ext.kotlin_version = '1.3.41' + ext.kotlin_version = '1.5.10' repositories { mavenCentral() } diff --git a/kokain-processor/src/main/java/com/schwarz/kokain/processor/model/EBeanModel.kt b/kokain-processor/src/main/java/com/schwarz/kokain/processor/model/EBeanModel.kt index 6287db0..ffc15c1 100644 --- a/kokain-processor/src/main/java/com/schwarz/kokain/processor/model/EBeanModel.kt +++ b/kokain-processor/src/main/java/com/schwarz/kokain/processor/model/EBeanModel.kt @@ -4,16 +4,12 @@ import com.schwarz.kokain.api.EBean import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.TypeName -import com.sun.org.apache.xpath.internal.operations.Mod import com.sun.tools.javac.code.Symbol import kotlinx.metadata.Flag -import kotlinx.metadata.Flags import kotlinx.metadata.KmClass import kotlinx.metadata.jvm.KotlinClassHeader import kotlinx.metadata.jvm.KotlinClassMetadata -import sun.tools.util.ModifierFilter import javax.lang.model.element.Element -import javax.lang.model.element.Modifier class EBeanModel(scope: EBean.Scope, sourceElement: Element) { @@ -22,7 +18,7 @@ class EBeanModel(scope: EBean.Scope, sourceElement: Element) { init { var meta = sourceElement?.getAnnotation(Metadata::class.java) kotlinClassMetadata = if(meta != null){ - (KotlinClassMetadata.read(KotlinClassHeader(meta.kind, meta.metadataVersion, meta.bytecodeVersion, meta.data1, meta.data2, meta.extraString, meta.packageName, meta.extraInt)) as? KotlinClassMetadata.Class)?.toKmClass() + (KotlinClassMetadata.read(KotlinClassHeader(meta.kind, meta.metadataVersion, meta.data1, meta.data2, meta.extraString, meta.packageName, meta.extraInt)) as? KotlinClassMetadata.Class)?.toKmClass() }else{ null } diff --git a/kokain-processor/src/main/java/com/schwarz/kokain/processor/util/TypeUtil.kt b/kokain-processor/src/main/java/com/schwarz/kokain/processor/util/TypeUtil.kt index 4d3d36d..cf780a0 100644 --- a/kokain-processor/src/main/java/com/schwarz/kokain/processor/util/TypeUtil.kt +++ b/kokain-processor/src/main/java/com/schwarz/kokain/processor/util/TypeUtil.kt @@ -8,8 +8,6 @@ import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy object TypeUtil { - const val KOKAIN_DI_BASE_PACKAGE = "com.schwarz.kokain.di" - const val KOKAIN_API_BASE_PACKAGE = "com.schwarz.kokain.api" fun string(): TypeName { @@ -61,11 +59,11 @@ object TypeUtil { } fun activityRefered(): TypeName { - return ClassName("$KOKAIN_DI_BASE_PACKAGE.observer", "ActivityRefered") + return ClassName("$KOKAIN_API_BASE_PACKAGE.internal", "ActivityRefered") } fun beanScope(): TypeName { - return ClassName("$KOKAIN_DI_BASE_PACKAGE.scope", "BeanScope") + return ClassName("$KOKAIN_API_BASE_PACKAGE.internal", "BeanScope") } fun scope(): TypeName { @@ -94,28 +92,6 @@ object TypeUtil { return if (lastIndexOf >= 0) type.toString().substring(0, lastIndexOf) else type.toString() } -// fun parseMetaType(type: TypeMirror, list: Boolean, subEntity: String?): TypeName { -// -// val simpleName = if (subEntity != null && subEntity.contains(getSimpleName(type))) subEntity else getSimpleName(type) -// -// var baseType: TypeName? = null -// -// if (type.toString().split(".").size == 1) { -// baseType = type.asTypeName() -// } else { -// try { -// baseType = ClassName(getPackage(type), simpleName) -// } catch (e: IllegalArgumentException) { -// baseType = type.asTypeName() -// } -// } -// -// return if (list) { -// list(baseType!!.javaToKotlinType()) -// } else baseType!!.javaToKotlinType() -// } - - fun classStar(): ParameterizedTypeName { return ClassName("kotlin.reflect", "KClass").parameterizedBy(star()) } diff --git a/kokain-processor/src/test/java/com/schwarz/kokain/processor/util/KokainProcessorKotlinTest.kt b/kokain-processor/src/test/java/com/schwarz/kokain/processor/util/KokainProcessorKotlinTest.kt index e100fb9..8406ed3 100644 --- a/kokain-processor/src/test/java/com/schwarz/kokain/processor/util/KokainProcessorKotlinTest.kt +++ b/kokain-processor/src/test/java/com/schwarz/kokain/processor/util/KokainProcessorKotlinTest.kt @@ -11,7 +11,7 @@ class KokainProcessorKotlinTest { @Test - fun testKotlinAbstractGeneration() { + fun testKotlinBasicGeneration() { val subEntity = SourceFile.kotlin("FooBean.kt", HEADER + @@ -23,14 +23,28 @@ class KokainProcessorKotlinTest { val compilation = compileKotlin(subEntity) + Assert.assertEquals(compilation.exitCode, KotlinCompilation.ExitCode.OK) + } + + @Test + fun testKotlinInternalBasicGeneration() { + + val subEntity = SourceFile.kotlin("FooBean.kt", + HEADER + + "@EBean\n" + + "@EFactory\n" + + "open internal class FooBean {\n" + + "}") + + + val compilation = compileKotlin(subEntity) - //TODO Fix classpath problem and make this great again - Assert.assertEquals(compilation.exitCode, KotlinCompilation.ExitCode.COMPILATION_ERROR) + Assert.assertEquals(compilation.exitCode, KotlinCompilation.ExitCode.OK) } private fun compileKotlin(vararg sourceFiles: SourceFile): KotlinCompilation.Result { return KotlinCompilation().apply { - sources = sourceFiles.toList() + sources = sourceFiles.toMutableList() // pass your own instance of an annotation processor annotationProcessors = listOf(KokainProcessor()) @@ -44,11 +58,8 @@ class KokainProcessorKotlinTest { const val HEADER: String = "package com.kaufland.test\n" + "\n" + - "import android.content.Context\n" + "import com.schwarz.kokain.api.EBean\n" + "import com.schwarz.kokain.api.EFactory\n" -// "import com.schwarz.kokaindi.context\n" + -// "import com.schwarz.kokaindi.inject\n" } }