Skip to content

Commit

Permalink
Initial multiplatform exploration
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvanyo committed Aug 22, 2021
1 parent f69055d commit f8fccda
Show file tree
Hide file tree
Showing 117 changed files with 676 additions and 403 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ jobs:
java-version: ${{ matrix.java-version }}

- name: Test
run: ./gradlew check jacocoTestReport
# Running check and jacocoTestReport together results in incorrect coverage (or no coverage)
# Running them separately runs the jvmTests twice, which is weird, but results in correct coverage
run: |
./gradlew check
./gradlew jacocoTestReport
- name: Danger
# Run Danger for PRs originating from within the repo (for fork PRs the token won't give permission to comment)
Expand Down
2 changes: 1 addition & 1 deletion Dangerfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
shroud.report 'build/reports/jacoco/test/jacocoTestReport.xml', 80, 80, false
shroud.report 'build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml', 80, 80, false
117 changes: 41 additions & 76 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

plugins {
kotlin("jvm") version Versions.kotlin
kotlin("multiplatform") version Versions.kotlin apply false
jacoco
id("io.gitlab.arturbosch.detekt") version Versions.detekt
id("org.jetbrains.dokka") version Versions.dokka
Expand All @@ -16,88 +16,23 @@ allprojects {
}

subprojects {
apply {
plugin<org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper>()
plugin<JacocoPlugin>()
plugin<io.gitlab.arturbosch.detekt.DetektPlugin>()
plugin<org.jetbrains.dokka.gradle.DokkaPlugin>()
}

dependencies {
detektPlugins(Dependencies.detektFormatting)
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlin {
explicitApi()
}

tasks {
compileKotlin {
withType<org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile>().configureEach {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
allWarningsAsErrors = true
}
}

compileTestKotlin {
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
allWarningsAsErrors = true
}
}

test {
useJUnitPlatform()
}

jacoco {
toolVersion = Versions.jacoco
}

jacocoTestReport {
dependsOn(test)

reports {
html.isEnabled = true
xml.isEnabled = true
}
}

withType<io.gitlab.arturbosch.detekt.Detekt> {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}

check {
dependsOn("detektMain")
}

dokkaHtml {
outputDirectory.set(javadoc.get().destinationDir)
}

plugins.withType(MavenPublishPlugin::class) {
val sourcesJar by creating(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
}

val javadocJar by creating(Jar::class) {
archiveClassifier.set("javadoc")
from(dokkaHtml)
}

publishing {
publications {
create<MavenPublication>("default") {
from(this@subprojects.components["java"])
artifact(sourcesJar)
artifact(javadocJar)

pom {
name.set(project.name)
description.set("Obsoleting enums with sealed classes of objects")
Expand Down Expand Up @@ -143,22 +78,52 @@ apiValidation {

tasks {
val jacocoMergeTest by registering(JacocoMerge::class) {
dependsOn(subprojects.map { it.tasks.jacocoTestReport })
dependsOn(subprojects.mapNotNull { it.tasks.findByName("jacocoTestReport") })

destinationFile = file("$buildDir/jacoco/test.exec")
executionData = fileTree(rootDir) {
include("**/build/jacoco/test.exec")
}
destinationFile = file("$buildDir/jacoco/jvmTest.exec")

executionData(
subprojects.filter { it.tasks.findByName("jacocoTestReport") != null }.map {
"${it.buildDir}/jacoco/jvmTest.exec"
}
)
}

jacocoTestReport {
val jacocoTestReport by registering(JacocoReport::class) {
dependsOn(jacocoMergeTest)

sourceSets(*subprojects.map { it.sourceSets.main.get() }.toTypedArray())
executionData.setFrom("$buildDir/jacoco/jvmTest.exec")
classDirectories.setFrom(
files(
subprojects
.map {
it.buildDir.resolve("classes/kotlin/jvm/main")
}
.flatMap { it.walkBottomUp().toList() }
)
)
sourceDirectories.setFrom(
files(
subprojects.flatMap {
listOf(
it.projectDir.resolve("src/commonMain"),
it.projectDir.resolve("src/jvmMain")
).filter(File::exists)
}
)
)

reports {
html.isEnabled = true
xml.isEnabled = true
}
}

val detektAll by registering {
allprojects {
this@registering.dependsOn(tasks.withType<io.gitlab.arturbosch.detekt.Detekt>())
}

getByName("check").dependsOn(this)
}
}
1 change: 1 addition & 0 deletions config/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ style:
excludedFunctions: 'describeContents'
excludeAnnotatedFunction: ['dagger.Provides']
LibraryCodeMustSpecifyReturnType:
excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ]
active: true
LibraryEntitiesShouldNotBePublic:
active: false
Expand Down
41 changes: 35 additions & 6 deletions ksp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
plugins {
kotlin("multiplatform")
`java-library`
kotlin("kapt")
id("io.gitlab.arturbosch.detekt")
id("org.jetbrains.dokka")
`maven-publish`
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlin {
explicitApi()

jvm()

sourceSets {
val jvmMain by getting {
dependencies {
implementation(projects.runtime)
implementation(projects.processingCommon)
implementation(libs.squareUp.kotlinPoet)
compileOnly(libs.ksp.api)
implementation(libs.autoService.runtime)
configurations["kapt"].dependencies.add(project.dependencies.create(libs.autoService.processor.get()))
}
}
}
}

tasks {
withType<io.gitlab.arturbosch.detekt.Detekt> {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}

dependencies {
implementation(projects.runtime)
implementation(projects.processingCommon)
implementation(libs.squareUp.kotlinPoet)
compileOnly(libs.ksp.api)
implementation(libs.autoService.runtime)
kapt(libs.autoService.processor)
detektPlugins(Dependencies.detektFormatting)
}

kapt {
Expand Down
62 changes: 62 additions & 0 deletions processing-common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,70 @@
plugins {
kotlin("multiplatform")
`java-library`
jacoco
id("io.gitlab.arturbosch.detekt")
id("org.jetbrains.dokka")
`maven-publish`
}

kotlin {
explicitApi()

jvm {
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}

sourceSets {
val jvmMain by getting {
dependencies {
implementation(projects.runtime)
implementation(libs.squareUp.kotlinPoet)
}
}

val jvmTest by getting {
dependencies {
implementation(libs.junit.jupiter)
}
}
}
}

jacoco {
toolVersion = Versions.jacoco
}

tasks {
jacocoTestReport {
dependsOn("jvmTest")

executionData.setFrom("$buildDir/jacoco/jvmTest.exec")
classDirectories.setFrom(
File("$buildDir/classes/kotlin/jvm/main").walkBottomUp().toList()
)
sourceDirectories.setFrom(
files(
"src/commonMain",
"src/jvmMain"
)
)

reports {
html.isEnabled = true
xml.isEnabled = true
}
}

withType<io.gitlab.arturbosch.detekt.Detekt> {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}

dependencies {
detektPlugins(Dependencies.detektFormatting)

implementation(projects.runtime)
implementation(libs.squareUp.kotlinPoet)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.squareup.kotlinpoet.TypeSpec
import com.squareup.kotlinpoet.asClassName
import com.squareup.kotlinpoet.buildCodeBlock
import javax.lang.model.element.TypeElement
import kotlin.reflect.KClass

/**
* A builder for a [SealedEnum] object for the given [sealedClass].
Expand Down Expand Up @@ -212,13 +213,13 @@ internal data class SealedEnumTypeSpec(
.build()

private fun createEnumClassGetter(enumForSealedEnum: ClassName): PropertySpec {
val parameterizedClass = Class::class.asClassName().parameterizedBy(enumForSealedEnum)
val parameterizedClass = KClass::class.asClassName().parameterizedBy(enumForSealedEnum)

return PropertySpec.builder("enumClass", parameterizedClass)
.addModifiers(KModifier.OVERRIDE)
.getter(
FunSpec.getterBuilder()
.addStatement("return %T::class.java", enumForSealedEnum)
.addStatement("return %T::class", enumForSealedEnum)
.build()
)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ package com.livefront.sealedenum.compilation.basic
import com.livefront.sealedenum.EnumForSealedEnumProvider
import com.livefront.sealedenum.SealedEnum
import com.livefront.sealedenum.SealedEnumWithEnumProvider
import java.lang.Class
import kotlin.Int
import kotlin.String
import kotlin.collections.List
import kotlin.reflect.KClass
/**
* An isomorphic enum for the sealed class [EmptySealedClass]
Expand Down Expand Up @@ -46,8 +46,8 @@ public object EmptySealedClassSealedEnum : SealedEnum<EmptySealedClass>,
public override val values: List<EmptySealedClass> = emptyList()
public override val enumClass: Class<EmptySealedClassEnum>
get() = EmptySealedClassEnum::class.java
public override val enumClass: KClass<EmptySealedClassEnum>
get() = EmptySealedClassEnum::class
public override fun ordinalOf(obj: EmptySealedClass): Int = throw
AssertionError("Constructing a EmptySealedClass is impossible, since it has no sealed subclasses")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EmptySealedClassTests {

@Test
fun `correct enum class`() {
assertEquals(EmptySealedClassEnum::class.java, EmptySealedClass.sealedEnum.enumClass)
assertEquals(EmptySealedClassEnum::class, EmptySealedClass.sealedEnum.enumClass)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ package com.livefront.sealedenum.compilation.basic
import com.livefront.sealedenum.EnumForSealedEnumProvider
import com.livefront.sealedenum.SealedEnum
import com.livefront.sealedenum.SealedEnumWithEnumProvider
import java.lang.Class
import kotlin.Int
import kotlin.String
import kotlin.collections.List
import kotlin.reflect.KClass
/**
* An isomorphic enum for the sealed class [EmptySealedInterface]
Expand Down Expand Up @@ -46,8 +46,8 @@ public object EmptySealedInterfaceSealedEnum : SealedEnum<EmptySealedInterface>,
public override val values: List<EmptySealedInterface> = emptyList()
public override val enumClass: Class<EmptySealedInterfaceEnum>
get() = EmptySealedInterfaceEnum::class.java
public override val enumClass: KClass<EmptySealedInterfaceEnum>
get() = EmptySealedInterfaceEnum::class
public override fun ordinalOf(obj: EmptySealedInterface): Int = throw
AssertionError("Constructing a EmptySealedInterface is impossible, since it has no sealed subclasses")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EmptySealedInterfaceTests {

@Test
fun `correct enum class`() {
assertEquals(EmptySealedInterfaceEnum::class.java, EmptySealedInterface.sealedEnum.enumClass)
assertEquals(EmptySealedInterfaceEnum::class, EmptySealedInterface.sealedEnum.enumClass)
}

@Test
Expand Down
Loading

0 comments on commit f8fccda

Please sign in to comment.