Skip to content
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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ group=org.jetbrains.kotlinx

kotlin_version=1.9.21

asm_version=9.3
asm_version=9.6
slf4j_version=1.8.0-alpha2
junit_version=4.12
kotlinx_metadata_version=0.7.0
Expand Down
78 changes: 78 additions & 0 deletions integration-testing/examples/jdk-compatibility/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import org.jetbrains.kotlin.config.JvmTarget

buildscript {
repositories {
mavenLocal()
mavenCentral()
}

dependencies {
val atomicfuVersion = libs.versions.atomicfuVersion.get()
val kotlinVersion = libs.versions.kotlinVersion.get()
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfuVersion")
classpath("org.jetbrains.kotlin:atomicfu:$kotlinVersion")
}
}

group = "kotlinx.atomicfu.examples"
version = "DUMMY_VERSION"

plugins {
kotlin("jvm") version libs.versions.kotlinVersion.get()
`maven-publish`
}

apply(plugin = "kotlinx-atomicfu")

repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
mavenLocal()
}

dependencies {
implementation(kotlin("stdlib"))
implementation(kotlin("test-junit"))
}

tasks.compileKotlin {
kotlinOptions {
freeCompilerArgs += listOf("-Xskip-prerelease-check")
}
}

kotlin {
val minTarget = JvmTarget.supportedValues().minBy { it.majorVersion }
val maxTarget = JvmTarget.supportedValues().maxBy { it.majorVersion }

val useMax = (project.properties["useMaxVersion"]?.toString() ?: "false").toBoolean()
val target = (if (useMax) maxTarget else minTarget).toString()

val toolchainVersion = target.split('.').last().toInt()
val targetVersionString = "JVM_" + target.replace('.', '_')
jvmToolchain(toolchainVersion)

compilerOptions {
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.valueOf(targetVersionString))
}
}

publishing {
repositories {
/**
* Maven repository in build directory to store artifacts for using in functional tests.
*/
maven("build/.m2/") {
name = "local"
}
}

publications {
create<MavenPublication>("maven") {
groupId = "kotlinx.atomicfu.examples"
artifactId = "jdk-compatibility"

from(components["kotlin"])
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
##
## Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
##
kotlin_version=1.9.21
atomicfu_version=0.23.1-SNAPSHOT
23 changes: 23 additions & 0 deletions integration-testing/examples/jdk-compatibility/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pluginManagement {
repositories {
mavenLocal()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
gradlePluginPortal()
}
}

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version ("0.7.0")
}

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
version("atomicfuVersion", providers.gradleProperty("atomicfu_version").orNull)
version("kotlinVersion", providers.gradleProperty("kotlin_version").orNull)
}
}
}

rootProject.name = "jdk-compatibility"
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

import kotlinx.atomicfu.*
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class IntArithmetic {
private val _x = atomic(0)
val x get() = _x.value

fun doWork(finalValue: Int) {
assertEquals(0, x)
assertEquals(0, _x.getAndSet(3))
assertEquals(3, x)
assertTrue(_x.compareAndSet(3, finalValue))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

import kotlin.test.*

class ArithmeticTest {
@Test
fun testInt() {
val a = IntArithmetic()
a.doWork(1234)
assertEquals(1234, a.x)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package kotlinx.atomicfu.gradle.plugin.test.cases

import kotlinx.atomicfu.gradle.plugin.test.framework.runner.GradleBuild
import kotlinx.atomicfu.gradle.plugin.test.framework.runner.cleanAndBuild
import kotlinx.atomicfu.gradle.plugin.test.framework.runner.createGradleBuildFromSources
import kotlin.test.Test

class JvmVersionCompatibilityTest {
private val jvmSample: GradleBuild = createGradleBuildFromSources("jdk-compatibility")

@Test
fun testClassTransformationWithEarliestJdkVersion() {
jvmSample.enableJvmIrTransformation = false
jvmSample.extraProperties.add("-PuseMaxVersion=false")
jvmSample.cleanAndBuild()
}

@Test
fun testClassTransformationWithLatestJdkVersion() {
jvmSample.enableJvmIrTransformation = false
jvmSample.extraProperties.add("-PuseMaxVersion=true")
jvmSample.cleanAndBuild()
}

@Test
fun testIrTransformationWithEarliestJdkVersion() {
jvmSample.enableJvmIrTransformation = true
jvmSample.extraProperties.add("-PuseMaxVersion=false")
jvmSample.cleanAndBuild()
}

@Test
fun testIrTransformationWithLatestJdkVersion() {
jvmSample.enableJvmIrTransformation = true
jvmSample.extraProperties.add("-PuseMaxVersion=true")
jvmSample.cleanAndBuild()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal class GradleBuild(val projectName: String, val targetDir: File) {
var enableJsIrTransformation = false
var enableNativeIrTransformation = false
var localRepositoryUrl: String? = null
val extraProperties = mutableListOf<String>()

private val properties
get() = buildList {
Expand All @@ -21,6 +22,7 @@ internal class GradleBuild(val projectName: String, val targetDir: File) {
localRepositoryUrl?.let {
add("-P$LOCAL_REPOSITORY_URL_PROPERTY=$it")
}
addAll(extraProperties)
}

private var runCount = 0
Expand Down