Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Kotlin 1.9.10 and other dependencies #447

Merged
merged 5 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ if ( status is StudyStatus.RegisteringDevices )

In case you want to contribute, please follow our [contribution guidelines](https://github.com/cph-cachet/carp.core-kotlin/blob/develop/CONTRIBUTING.md).

We recommend using IntelliJ IDEA 2022, as this is the development environment we use and is therefore fully tested.
We recommend using IntelliJ IDEA 2023, as this is the development environment we use and is therefore fully tested.

- Open the project folder in IntelliJ 2022.
- Open the project folder in IntelliJ 2023.
- Make sure Google Chrome is installed; JS unit tests are run on headless Chrome.
- In case you want to run TypeScript declaration tests (`verifyTsDeclarations`), install node.
- To build/test/publish, click "Edit Configurations" to add configurations for [the included Gradle tasks](#gradle-tasks), or run them from the Gradle tool window.
Expand Down
52 changes: 26 additions & 26 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ buildscript {

versions = [
// Kotlin multiplatform versions.
kotlin:'1.8.21',
serialization:'1.5.0',
coroutines:'1.7.0',
datetime:'0.4.0',
kotlin:'1.9.10',
serialization:'1.6.0',
coroutines:'1.7.3',
datetime:'0.4.1',

// JVM versions.
jvmTarget:'1.8',
dokkaPlugin:'1.8.10',
reflections:'0.10.2',

// JS versions.
nodePlugin:'4.0.0',
nodePlugin:'7.0.1',
bigJs:'6.2.1',

// DevOps versions.
detektPlugin:'1.22.0',
detektPlugin:'1.23.1',
detektVerifyImplementation:'1.2.5',
nexusPublishPlugin:'1.3.0',
apacheCommons:'2.11.0'
Expand Down Expand Up @@ -91,6 +91,26 @@ configure( subprojects - devOpsModules ) {
generateTypeScriptDefinitions()
}

targets.configureEach {
compilations.configureEach {
def isTestSourceSet = it.name == 'test'

compilerOptions.configure((Action) {
// Treat compilation warning as errors for all compilation targets.
it.allWarningsAsErrors = true

// We do not mind being early adopters of Jetbrains APIs likely to change in the future.
it.optIn.add('kotlin.RequiresOptIn')
it.optIn.add('kotlin.time.ExperimentalTime')
it.optIn.add('kotlin.js.ExperimentalJsExport')
if (isTestSourceSet)
{
it.optIn.add('kotlinx.coroutines.ExperimentalCoroutinesApi')
}
} )
}
}

sourceSets {
commonMain {
dependencies {
Expand All @@ -110,29 +130,9 @@ configure( subprojects - devOpsModules ) {
implementation "org.reflections:reflections:${versions.reflections}"
}
}

all {
def isTestSourceSet = it.name.endsWith('Test')

languageSettings {
// We do not mind being early adopters of Jetbrains APIs likely to change in the future.
optIn('kotlin.RequiresOptIn')
optIn('kotlin.time.ExperimentalTime')
optIn('kotlin.js.ExperimentalJsExport')
if (isTestSourceSet)
{
optIn('kotlinx.coroutines.ExperimentalCoroutinesApi')
}
}
}
}
}

// Treat compilation warning as errors for all compilation targets.
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions { allWarningsAsErrors = true }
}

// Publish configuration.
// For signing and publishing to work, a 'publish.properties' file needs to be added to the root containing:
// The OpenPGP credentials to sign all artifacts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class EventSubscriptionBuilder(
*/
inline fun <
reified TService : ApplicationService<TService, TEvent>,
reified TEvent : IntegrationEvent<TService>> event(
reified TEvent : IntegrationEvent<TService>
> event(
noinline handler: suspend (TEvent) -> Unit
) = eventBus.registerHandler( TService::class, TEvent::class, subscriber, handler )
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ abstract class EventBus
*/
fun <
TService : ApplicationService<TService, TEvent>,
TEvent : IntegrationEvent<TService>> registerHandler(
TEvent : IntegrationEvent<TService>
> registerHandler(
eventSource: KClass<TService>,
eventType: KClass<TEvent>,
subscriber: Any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ data class WebTask(
/**
* Identifies the condition, defined by the study protocol, which caused the [WebTask] to be triggered.
*/
TRIGGER_ID( markup( "trigger id" ) );
TRIGGER_ID( markup( "trigger id" ) )
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class SingleThreadedEventBus : EventBus()
*/
override suspend fun <
TApplicationService : ApplicationService<TApplicationService, TEvent>,
TEvent : IntegrationEvent<TApplicationService>> publish(
TEvent : IntegrationEvent<TApplicationService>
> publish(
publishingService: KClass<TApplicationService>,
event: TEvent
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,12 @@ private fun <T : Any> String.makeUnknown(
// This is complex, and furthermore not 100% foolproof in rare cases (e.g., if the string is used not as a type name).
// Probably this should be rewritten with a JSON parser.
val escapedQualifiedName = qualifiedName.replace( ".", "\\." )
val objectRegex = Regex( "(\\{\"__type\":\")($escapedQualifiedName)(\",(?!.*?$escapedQualifiedName.*?\"$key\":\"$value\").*?\"$key\":\"$value\".*?\\})" )
val objectRegex =
Regex( "(\\{\"__type\":\")($escapedQualifiedName)(\",(?!.*?$escapedQualifiedName.*?\"$key\":\"$value\").*?\"$key\":\"$value\".*?\\})" )

// Replace type name with an unknown type name to mimic it is not available at runtime.
val match = objectRegex.find( this )
require( match != null && match.groups.count() == 4 ) { "Could not find the specified object in the serialized string." }
require( match != null && match.groups.count() == 4 )
{ "Could not find the specified object in the serialized string." }
return this.replace( objectRegex, "$1$unknownTypeName$3" )
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class CarpPrimitiveSerializerTest
{
override fun toString(): String = string
}
object PrimitiveStringSerializer : KSerializer<PrimitiveString> by createCarpStringPrimitiveSerializer( { PrimitiveString( it ) } )
object PrimitiveStringSerializer : KSerializer<PrimitiveString> by
createCarpStringPrimitiveSerializer( { PrimitiveString( it ) } )

@Test
fun createCarpStringPrimitiveSerializer_serializes_as_string()
Expand All @@ -39,7 +40,8 @@ class CarpPrimitiveSerializerTest

@Serializable( PrimitiveLongSerializer::class )
class PrimitiveLong( val long: Long )
object PrimitiveLongSerializer : KSerializer<PrimitiveLong> by createCarpLongPrimitiveSerializer( { PrimitiveLong( it ) }, { it.long } )
object PrimitiveLongSerializer : KSerializer<PrimitiveLong> by
createCarpLongPrimitiveSerializer( { PrimitiveLong( it ) }, { it.long } )

@Test
fun createCarpLongPrimitiveSerializer_serializes_as_long()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ class UnknownPolymorphicSerializerTest
val knownType = DerivingType( "Test" )
val serialized = json.encodeToString<BaseType>( knownType )
val unknownSerialized = serialized.replace( DerivingType::class.simpleName!!, "UnknownType" )
val unknown = CustomBaseType( "dk.cachet.carp.common.infrastructure.serialization.UnknownPolymorphicSerializerTest.UnknownType", unknownSerialized, json )
val unknown = CustomBaseType(
"dk.cachet.carp.common.infrastructure.serialization.UnknownPolymorphicSerializerTest.UnknownType",
unknownSerialized,
json
)

val unpacked = json.encodeToString<BaseType>( unknown )
assertEquals( unknownSerialized, unpacked )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ class SingleThreadedEventBusTest
val bus = SingleThreadedEventBus()

var receivedBySubscriber1 = false
bus.registerHandler( TestService::class, BaseIntegrationEvent.SomeIntegrationEvent::class, this ) { receivedBySubscriber1 = true }
bus.registerHandler( TestService::class, BaseIntegrationEvent.SomeIntegrationEvent::class, this )
{ receivedBySubscriber1 = true }
var receivedBySubscriber2 = false
bus.registerHandler( TestService::class, BaseIntegrationEvent.SomeIntegrationEvent::class, this ) { receivedBySubscriber2 = true }
bus.registerHandler( TestService::class, BaseIntegrationEvent.SomeIntegrationEvent::class, this )
{ receivedBySubscriber2 = true }
bus.activateHandlers( this )

bus.publish( TestService::class, BaseIntegrationEvent.SomeIntegrationEvent( "Test" ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class PrimaryDeviceDeploymentTest
{
val unexpectedType = DataType( "something", "unexpected" )
val unexpectedTypeConfiguration = NoOptionsSamplingConfiguration
val primary = StubPrimaryDeviceConfiguration( "Primary", false, mapOf( unexpectedType to unexpectedTypeConfiguration ) )
val primary =
StubPrimaryDeviceConfiguration( "Primary", false, mapOf( unexpectedType to unexpectedTypeConfiguration ) )
val registration = primary.createRegistration()
val deployment = PrimaryDeviceDeployment( primary, registration )

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ class StudyDeploymentTest
fun fromSnapshot_succeeds_with_rich_registration_history()
{
val deployment: StudyDeployment = createActiveDeployment( "Primary" )
val primary: AnyPrimaryDeviceConfiguration = deployment.protocol.devices.first { it.roleName == "Primary" } as AnyPrimaryDeviceConfiguration
val primary: AnyPrimaryDeviceConfiguration =
deployment.protocol.devices.first { it.roleName == "Primary" } as AnyPrimaryDeviceConfiguration

// Create registration history with two registrations for primary.
val registration1 = primary.createRegistration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,14 @@ class StudyProtocolSnapshotTest
@Test
fun order_of_tasks_devices_and_expected_participant_data_in_snapshot_does_not_matter_for_equality_or_hashcode()
{
val primaryDevices = listOf<AnyPrimaryDeviceConfiguration>( StubPrimaryDeviceConfiguration( "M1" ), StubPrimaryDeviceConfiguration( "M2" ) )
val connectedDevices = listOf<AnyDeviceConfiguration>( StubDeviceConfiguration( "C1" ), StubDeviceConfiguration( "C2" ) )
val primaryDevices = listOf<AnyPrimaryDeviceConfiguration>(
StubPrimaryDeviceConfiguration( "M1" ),
StubPrimaryDeviceConfiguration( "M2" )
)
val connectedDevices = listOf<AnyDeviceConfiguration>(
StubDeviceConfiguration( "C1" ),
StubDeviceConfiguration( "C2" )
)
val connections = listOf(
StudyProtocolSnapshot.DeviceConnection( "C1", "M1" ),
StudyProtocolSnapshot.DeviceConnection( "C2", "M2" )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ class UseCompositeTaskWarningTest

val warning = UseCompositeTaskWarning()
val overlapping = warning.getOverlappingTasks( protocol )
val expectedOverlapping = setOf( UseCompositeTaskWarning.OverlappingTasks( trigger, device, listOf( task1, task2 ) ) )
val expectedOverlapping = setOf(
UseCompositeTaskWarning.OverlappingTasks( trigger, device, listOf( task1, task2 ) )
)
assertEquals( expectedOverlapping.count(), overlapping.intersect( expectedOverlapping ).count() )
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ class HostsIntegrationTest
var studyRemovedEvent: StudyService.Event.StudyRemoved? = null
eventBus.registerHandler( StudyService::class, StudyService.Event.StudyRemoved::class, this ) { studyRemovedEvent = it }
var deploymentRemovedEvent: DeploymentService.Event.StudyDeploymentRemoved? = null
eventBus.registerHandler( DeploymentService::class, DeploymentService.Event.StudyDeploymentRemoved::class, this ) { deploymentRemovedEvent = it }
eventBus.registerHandler( DeploymentService::class, DeploymentService.Event.StudyDeploymentRemoved::class, this )
{ deploymentRemovedEvent = it }
eventBus.activateHandlers( this )
studyService.remove( studyId )

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ interface StudyRepositoryTest
val study = Study( UUID.randomUUID(), "Test" )
repo.add( study )

val studyWithSameId = Study( UUID.randomUUID(), "Study 2", "Description", StudyInvitation( "Some study" ), study.id )
val studyWithSameId =
Study( UUID.randomUUID(), "Study 2", "Description", StudyInvitation( "Some study" ), study.id )
assertFailsWith<IllegalArgumentException>
{
repo.add( studyWithSameId )
Expand Down
1 change: 1 addition & 0 deletions carp.test/src/jsMain/kotlin/dk/cachet/carp/test/Nested.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package dk.cachet.carp.test


// The Mocha test runtime does not rely on a 'Nested' attribute in order to run tests of nested classes.
@Target( AnnotationTarget.CLASS )
actual annotation class Nested
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package dk.cachet.carp.test


// Nothing to do. This should only ignore tests on the JavaScript test runtime.
@Target( AnnotationTarget.CLASS, AnnotationTarget.FUNCTION )
actual annotation class JsIgnore
4 changes: 4 additions & 0 deletions detekt.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
complexity:
LongMethod:
excludes: ['**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/test/**']
LongParameterList:
excludes: ['**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/test/**']
TooManyFunctions:
Expand All @@ -9,6 +11,8 @@ formatting:
excludes: ['**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/test/**']
Filename:
active: false
FunctionStartOfBodySpacing:
active: false
Indentation:
active: false
MaximumLineLength:
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Tue Sep 03 11:02:31 CEST 2019
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
Expand Down
Loading
Loading