Skip to content

Commit

Permalink
Configure JPMS checks (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr3zee authored Sep 23, 2024
1 parent c9c6d03 commit 4dc54f2
Show file tree
Hide file tree
Showing 77 changed files with 227 additions and 89 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ allprojects {
}

object Const {
const val INTERNAL_RPC_API_ANNOTATION = "kotlinx.rpc.internal.InternalRPCApi"
const val INTERNAL_RPC_API_ANNOTATION = "kotlinx.rpc.internal.utils.InternalRPCApi"
}

apiValidation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package kotlinx.rpc
import kotlinx.rpc.internal.RPCDeferredField
import kotlinx.rpc.internal.RPCServiceFieldsProvider
import kotlinx.rpc.internal.findRPCStubProvider
import kotlinx.rpc.internal.safeCast
import kotlinx.rpc.internal.utils.safeCast
import kotlin.reflect.KClass

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package kotlinx.rpc.internal

import kotlinx.rpc.internal.utils.InternalRPCApi

@InternalRPCApi
public interface RPCDeferredField<Self> {
public suspend fun await(): Self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package kotlinx.rpc.internal

import kotlinx.rpc.internal.utils.InternalRPCApi

@InternalRPCApi
public interface RPCMethodClassArguments {
public fun asArray(): Array<out Any?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package kotlinx.rpc.internal

import kotlinx.rpc.RPC
import kotlinx.rpc.RPCClient
import kotlinx.rpc.internal.utils.InternalRPCApi
import kotlin.reflect.KType

@InternalRPCApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package kotlinx.rpc.internal

import kotlinx.rpc.internal.utils.InternalRPCApi
import kotlin.reflect.KClass
import kotlin.reflect.KType

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package kotlinx.rpc.internal
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.withContext
import kotlinx.rpc.internal.utils.InternalRPCApi
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package kotlinx.rpc.internal

import kotlinx.rpc.internal.utils.InternalRPCApi
import kotlin.reflect.KClass

@InternalRPCApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package kotlinx.rpc.internal

import kotlinx.coroutines.CoroutineScope
import kotlinx.rpc.internal.utils.InternalRPCApi

/**
* Scopes client RPC call from a service with [serviceScope].
Expand Down
2 changes: 1 addition & 1 deletion core/src/commonMain/kotlin/kotlinx/rpc/withService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlinx.atomicfu.atomic
import kotlinx.rpc.internal.RPCStubServiceProvider
import kotlinx.rpc.internal.findRPCStubProvider
import kotlinx.rpc.internal.kClass
import kotlinx.rpc.internal.safeCast
import kotlinx.rpc.internal.utils.safeCast
import kotlin.reflect.KClass
import kotlin.reflect.KType

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package kotlinx.rpc.internal

import kotlinx.rpc.internal.utils.InternalRPCApi
import kotlin.reflect.KClass

@InternalRPCApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package kotlinx.rpc.internal

import js.objects.Object
import kotlinx.rpc.RPC
import kotlinx.rpc.internal.utils.InternalRPCApi
import kotlin.reflect.AssociatedObjectKey
import kotlin.reflect.ExperimentalAssociatedObjects
import kotlin.reflect.KClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package kotlinx.rpc.internal

import kotlinx.rpc.internal.utils.InternalRPCApi
import kotlin.reflect.KClass

@InternalRPCApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package kotlinx.rpc.internal

import kotlinx.rpc.internal.utils.InternalRPCApi
import kotlin.reflect.KClass
import kotlin.reflect.full.companionObjectInstance

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package kotlinx.rpc.internal

import kotlinx.rpc.internal.utils.InternalRPCApi
import kotlin.reflect.KClass

@InternalRPCApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package kotlinx.rpc.internal

import kotlinx.rpc.RPC
import kotlinx.rpc.internal.utils.InternalRPCApi
import kotlin.reflect.AssociatedObjectKey
import kotlin.reflect.ExperimentalAssociatedObjects
import kotlin.reflect.KClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension

fun KotlinProjectExtension.optInForRPCApi() {
sourceSets.all {
languageSettings.optIn("kotlinx.rpc.internal.InternalRPCApi")
languageSettings.optIn("kotlinx.rpc.internal.ExperimentalRPCApi")
languageSettings.optIn("kotlinx.rpc.internal.utils.InternalRPCApi")
languageSettings.optIn("kotlinx.rpc.internal.utils.ExperimentalRPCApi")
}
}
3 changes: 3 additions & 0 deletions gradle-conventions-settings/src/main/kotlin/util/Path.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package util

import org.gradle.api.Project
import java.io.File
import java.nio.file.Files
import java.nio.file.Path
Expand All @@ -13,3 +14,5 @@ fun Path.name() = fileName?.toString().orEmpty()
fun filterDirectory(sourceSetPath: Path, filter: (Path) -> Boolean): List<File> {
return Files.newDirectoryStream(sourceSetPath).use { it.toList() }.filter(filter).map { it.toFile() }
}

val Project.files: Array<File> get() = project.projectDir.resolve("src").listFiles() ?: emptyArray()
35 changes: 35 additions & 0 deletions gradle-conventions-settings/src/main/kotlin/util/jvm.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package util

import org.gradle.api.Project
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.attributes
import org.gradle.kotlin.dsl.getByName

fun Project.configureJvm(isKmp: Boolean) {
tasks.getByName<Jar>(if (isKmp) "jvmJar" else "jar").apply {
manifest {
attributes(
"Implementation-Title" to name,
"Implementation-Version" to libs.versions.kotlinx.rpc.get()
)
val name = project.javaModuleName()
attributes("Automatic-Module-Name" to name)
}
}
}

fun Project.javaModuleName(): String {
return "kotlinx.rpc.${project.name}".replace('-', '.')
}

val Project.hasJavaModule: Boolean
get() = plugins.hasPlugin("maven-publish") && name != "bom" && name != "jpms-check" && hasJvm

val Project.hasJvm: Boolean
get() = files.any { it.name == "commonMain" }
|| files.any { it.name == "jvmMain" }
|| files.any { it.name == "main" }
3 changes: 3 additions & 0 deletions gradle-conventions/src/main/kotlin/conventions-jvm.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import util.configureJvm
import util.optInForRPCApi

plugins {
Expand All @@ -23,3 +24,5 @@ configure<KotlinJvmProjectExtension> {

explicitApi()
}

configureJvm(isKmp = false)
3 changes: 3 additions & 0 deletions gradle-conventions/src/main/kotlin/conventions-kmp.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import util.configureJvm
import util.configureKotlin
import util.optInForRPCApi
import util.optionalProperty
Expand Down Expand Up @@ -30,3 +31,5 @@ configureKotlin(
js = !excludeJs,
native = !excludeNative,
)

configureJvm(isKmp = true)
1 change: 1 addition & 0 deletions jpms-check/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/main/java/module-info.java
66 changes: 66 additions & 0 deletions jpms-check/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import util.hasJavaModule
import util.javaModuleName

plugins {
`java-library`
}

description = "Internal module for checking JPMS compliance"

tasks.register("generateModuleInfo") {
val modules = project.rootProject.subprojects
.filter { it.hasJavaModule }
.map { it.javaModuleName() }

val moduleInfoPath = project.projectDir.absolutePath + "/src/main/java/module-info.java"

doLast {
File(moduleInfoPath)
.apply {
parentFile.mkdirs()
createNewFile()
}
.bufferedWriter().use { writer ->
writer.write("module kotlinx.rpc.test.module {\n")
modules.forEach { writer.write("\trequires $it;\n") }
writer.write("}")
}
}
}

tasks.getByName<JavaCompile>("compileJava") {
dependsOn("generateModuleInfo")

val projectFiles = project.files()
doFirst {
options.compilerArgs.addAll(listOf("--module-path", classpath.asPath))
classpath = projectFiles
}
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

dependencies {
rootProject.subprojects
.forEach {
val dep = generateSequence(it) { subProject -> subProject.parent }
.toList()
.dropLast(1)
.reversed()
.joinToString(":", prefix = ":") { segment -> segment.name }

it.plugins.withId("maven-publish") {
if (it.hasJavaModule) {
api(project(dep))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.rpc.RPCCall
import kotlinx.rpc.RPCClient
import kotlinx.rpc.RPCField
import kotlinx.rpc.internal.InternalRPCApi
import kotlinx.rpc.internal.SupervisedCompletableDeferred
import kotlinx.rpc.internal.getOrNull
import kotlinx.rpc.internal.map.ConcurrentHashMap
import kotlinx.rpc.internal.serviceScopeOrNull
import kotlinx.rpc.internal.utils.InternalRPCApi
import kotlinx.rpc.internal.utils.SupervisedCompletableDeferred
import kotlinx.rpc.internal.utils.getOrNull
import kotlinx.rpc.internal.utils.map.ConcurrentHashMap
import kotlinx.rpc.krpc.*
import kotlinx.rpc.krpc.client.internal.FieldDataObject
import kotlinx.rpc.krpc.client.internal.RPCClientConnector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.rpc.internal.RPCDeferredField
import kotlinx.rpc.internal.SupervisedCompletableDeferred
import kotlinx.rpc.internal.utils.SupervisedCompletableDeferred

internal sealed class RPCFlow<T, FlowT : Flow<T>>(private val serviceName: String, parent: Job) :
RPCDeferredField<FlowT> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package kotlinx.rpc.krpc
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.rpc.internal.InternalRPCApi
import kotlinx.rpc.internal.utils.InternalRPCApi
import kotlinx.rpc.krpc.serialization.RPCSerialFormat
import kotlinx.rpc.krpc.serialization.RPCSerialFormatBuilder
import kotlinx.rpc.krpc.serialization.RPCSerialFormatConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
package kotlinx.rpc.krpc

import kotlinx.coroutines.*
import kotlinx.rpc.internal.AutoCloseable
import kotlinx.rpc.internal.ExperimentalRPCApi
import kotlinx.rpc.internal.InternalRPCApi
import kotlinx.rpc.internal.map.ConcurrentHashMap
import kotlinx.rpc.internal.use
import kotlinx.rpc.internal.utils.AutoCloseable
import kotlinx.rpc.internal.utils.ExperimentalRPCApi
import kotlinx.rpc.internal.utils.InternalRPCApi
import kotlinx.rpc.internal.utils.map.ConcurrentHashMap
import kotlinx.rpc.internal.utils.use
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

package kotlinx.rpc.krpc.internal

import kotlinx.rpc.internal.IndexedEnum
import kotlinx.rpc.internal.InternalRPCApi
import kotlinx.rpc.internal.utils.IndexedEnum
import kotlinx.rpc.internal.utils.InternalRPCApi

@InternalRPCApi
@Suppress("detekt.MagicNumber")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

package kotlinx.rpc.krpc.internal

import kotlinx.rpc.internal.InternalRPCApi
import kotlinx.rpc.internal.typeName
import kotlinx.rpc.internal.utils.InternalRPCApi

@InternalRPCApi
public fun serializeException(cause: Throwable): SerializedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package kotlinx.rpc.krpc.internal

import kotlinx.rpc.internal.InternalRPCApi
import kotlinx.rpc.internal.utils.InternalRPCApi

private const val HEX_RADIX = 16

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.rpc.internal.InternalRPCApi
import kotlinx.rpc.internal.hex.toHexStringInternal
import kotlinx.rpc.internal.utils.InternalRPCApi
import kotlinx.rpc.internal.utils.hex.toHexStringInternal
import kotlinx.rpc.krpc.RPCTransport
import kotlinx.rpc.krpc.RPCTransportMessage
import kotlinx.rpc.krpc.internal.logging.CommonLogger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package kotlinx.rpc.krpc.internal

import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import kotlinx.rpc.internal.InternalRPCApi
import kotlinx.rpc.internal.utils.InternalRPCApi

@InternalRPCApi
public interface RPCEndpoint {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package kotlinx.rpc.krpc.internal

import kotlinx.rpc.internal.InternalRPCApi
import kotlinx.rpc.internal.utils.InternalRPCApi
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand Down
Loading

0 comments on commit 4dc54f2

Please sign in to comment.