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

Prepare sources for 2.0.0-betaX #710

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ef9a726
feat: prepare source for 2.0.0-Beta2
zoobestik Dec 11, 2023
b9a77bf
feat: reduce test fails for 2.0.0-Beta2
zoobestik Dec 11, 2023
fda3686
test: add 1.9.0 stable cases
zoobestik Dec 12, 2023
34b99ac
test(api): add http test with a previous version
zoobestik Dec 12, 2023
1b834dc
tmp; add response for E2E from v1.9.20
zoobestik Dec 12, 2023
b56f6d4
tmp; `@Deprecated` showed in warning
zoobestik Dec 13, 2023
3140332
tmp; report for 'unused variable' doesn't show.
zoobestik Dec 13, 2023
37dd96d
The Kotlin version has been updated to '2.0.0-Beta2'. Likewise, the K…
zoobestik Dec 15, 2023
201bc6b
KTL-1313 feat: add support for explicit backing fields
nikpachoo Dec 28, 2023
4378b39
Handle 'ExplicitBackingFields' compiler warnings
zoobestik Dec 28, 2023
a66d9ee
chore(release): support 2.0.0-Beta3
zoobestik Jan 17, 2024
f3be766
chore(release): support 2.0.0-Beta5
zoobestik Mar 20, 2024
d25a530
test(2.0.0-RC1): fix deprecation message
zoobestik Apr 9, 2024
3925e65
chore(release): support 2.0.0-RC2
zoobestik Apr 29, 2024
aa63ae4
Merge branch 'refs/heads/master' into 2.0.0-beta2-prepare
nikpachoo Apr 30, 2024
ea04f68
fix: update coroutines test
nikpachoo Apr 30, 2024
50e6205
Merge branch 'refs/heads/master' into 2.0.0-beta2-prepare
nikpachoo Apr 30, 2024
de9d879
ktl-1476: release 2.0.0-RC3
nikpachoo May 10, 2024
bfa2260
Merge pull request #731 from JetBrains/ktl-1476-rc3
nikpachoo May 10, 2024
054c593
Merge branch 'refs/heads/master' into 2.0.0-beta2-prepare
nikpachoo May 11, 2024
65d4aa9
Merge branch 'refs/heads/master' into 2.0.0-beta2-prepare
nikpachoo May 12, 2024
8d40c75
fix: -Xreport-all-warnings is not supported by this version of the co…
nikpachoo May 12, 2024
e06f56c
Use kotlin version to get compose compiler plugin
ilgonmic May 15, 2024
7885564
Parametrize compose runtime version
ilgonmic May 15, 2024
794dae9
Merge pull request #734 from JetBrains/ilgonmic/prepare-2.0
nikpachoo May 21, 2024
672bcd2
Merge branch 'refs/heads/master' into 2.0.0-beta2-prepare
nikpachoo May 21, 2024
288d6cf
ktl-1497 feat: release 2.0.0
nikpachoo May 21, 2024
aa9ef18
Merge pull request #738 from JetBrains/2.0.0
nikpachoo May 21, 2024
6318fbf
Added kotlinx-io dependency
dkrasnoff Aug 8, 2024
8874c4f
Added swagger
dkrasnoff Aug 6, 2024
06ce3b0
Merge pull request #746 from JetBrains/dkrasnov/KTL-1613-kotlinx-io
nikpachoo Aug 12, 2024
6380b0b
Merge pull request #747 from JetBrains/dkrasnov/swagger
nikpachoo Aug 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ build/
!**/src/test/**
src/main/resources/application.properties

# compile artifacts
.kotlin/
1.9.*/
2.*/
indexes*.json
*.log

### STS ###
.apt_generated
.classpath
Expand Down
100 changes: 2 additions & 98 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,103 +52,7 @@ remove [aws-serverless-container](https://github.com/awslabs/aws-serverless-java

## API Documentation :page_with_curl:

### Execute Kotlin code on JVM

```shell script
curl -X POST \
http://localhost:8080/api/compiler/run \
-H 'Content-Type: application/json' \
-d '{
"args": "1 2 3",
"files": [
{
"name": "File.kt",
"text": "fun main() {\n println(\"123\")\n}"
}
]
}'
```

### Translate Kotlin code to JavaScript code

```shell script
curl -X POST \
http://localhost:8080/api/compiler/translate \
-H 'Content-Type: application/json' \
-d '{
"args": "1 2 3",
"files": [
{
"name": "File.kt",
"text": "fun main(args: Array<String>) {\n println(args[0])\n }"
}
]
}'
```

### Run Kotlin tests

```shell script
curl -X POST \
http://localhost:8080/api/compiler/test \
-H 'Content-Type: application/json' \
-d '{
"files": [
{
"name": "File.kt",
"text": "fun start(): String = \"OK\""
},
{
"name": "test0.kt",
"text": "import org.junit.Assert\nimport org.junit.Test\n\nclass TestStart {\n @Test fun testOk() {\n Assert.assertEquals(\"OK\", start())\n }\n}"
},
{
"name": "test1.kt",
"text": "package koans.util\n\nfun String.toMessage() = \"The function '\''$this'\'' is implemented incorrectly\"\n\nfun String.toMessageInEquals() = toMessage().inEquals()\n\nfun String.inEquals() = this"
}
]
}'
```

### Get code completions for a specified place in code

```shell script
curl -X POST \
'http://localhost:8080/api/compiler/complete?line=2&ch=15' \
-H 'Content-Type: application/json' \
-d '{
"files": [
{
"name": "File.kt",
"text": "fun main() {\n val sinusoid = \"sinusoid\"\n val s = sin\n}"
}
]
}'
```

### Get code analysis results

```shell script
curl -X POST \
http://localhost:8080/api/compiler/highlight \
-H 'Content-Type: application/json' \
-d '{
"files": [
{
"name": "File.kt",
"text": "fun main() {\n println(\"Hello, world!!!\")ass\n val random = Random\n}"
}
]
}'
```

### Get the current Kotlin version

```shell script
curl -X GET http://localhost:8080/versions
```

The server also supports an [API](https://github.com/JetBrains/kotlin-playground) for the Kotlin Playground library.
Swagger url: http://localhost:8080/swagger-ui/

## How to add your dependencies to kotlin compiler :books:

Expand All @@ -163,7 +67,7 @@ task called `kotlinDependency`:
NOTE: If the library you're adding uses reflection, accesses the file system, or performs any other type of
security-sensitive operations, don't forget to
configure
the [executors.policy](https://github.com/AlexanderPrednota/kotlin-compiler-server/blob/master/executors.policy)
the [executor.policy](https://github.com/JetBrains/kotlin-compiler-server/blob/master/executor.policy)
. [Click here](https://docs.oracle.com/javase/7/docs/technotes/guides/security/PolicyFiles.html) for more information
about *Java Security Policy*.

Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ dependencies {
annotationProcessor("org.springframework:spring-context-indexer")
implementation("com.google.code.gson:gson")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("io.springfox:springfox-boot-starter:3.0.0")
implementation("com.amazonaws.serverless:aws-serverless-java-container-springboot2:1.9.3")
implementation("junit:junit:4.13.2")
implementation("net.logstash.logback:logstash-logback-encoder:7.3")
Expand Down
3 changes: 2 additions & 1 deletion common/src/main/kotlin/component/KotlinEnvironment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class KotlinEnvironment(
"-opt-in=kotlin.contracts.ExperimentalContracts",
"-opt-in=kotlin.experimental.ExperimentalTypeInference",
"-Xcontext-receivers",
"-XXLanguage:+ExplicitBackingFields"
)
}

Expand Down Expand Up @@ -107,7 +108,7 @@ class KotlinEnvironment(
}

private val environment = KotlinCoreEnvironment.createForProduction(
parentDisposable = Disposer.newDisposable(),
projectDisposable = Disposer.newDisposable(),
configuration = configuration.copy(),
configFiles = EnvironmentConfigFiles.JVM_CONFIG_FILES
)
Expand Down
21 changes: 12 additions & 9 deletions dependencies/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ val composeWasmCompilerPlugins: Configuration by configurations.creating {

val jacksonVersionKotlinDependencyJar = "2.14.0" // don't forget to update version in `executor.policy` file.

val composeRuntimeVersion = "1.6.0"

val copyDependencies by tasks.creating(Copy::class) {
from(kotlinDependency)
into(libJVMFolder)
Expand Down Expand Up @@ -101,6 +103,7 @@ dependencies {
kotlinDependency("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion")
kotlinDependency("org.jetbrains.kotlin:kotlin-test:$kotlinVersion")
kotlinDependency("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.7.3")
kotlinDependency("org.jetbrains.kotlinx:kotlinx-io-core:0.5.1")
kotlinDependency("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4")
kotlinDependency("org.jetbrains.kotlinx:kotlinx-datetime:0.6.0-RC.2")
kotlinJsDependency("org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion")
Expand All @@ -109,13 +112,13 @@ dependencies {

// compose
kotlinComposeWasmDependency("org.jetbrains.kotlin:kotlin-stdlib-wasm-js:$kotlinVersion")
kotlinComposeWasmDependency("org.jetbrains.compose.runtime:runtime:1.6.0")
kotlinComposeWasmDependency("org.jetbrains.compose.ui:ui:1.6.0")
kotlinComposeWasmDependency("org.jetbrains.compose.animation:animation:1.6.0")
kotlinComposeWasmDependency("org.jetbrains.compose.animation:animation-graphics:1.6.0")
kotlinComposeWasmDependency("org.jetbrains.compose.foundation:foundation:1.6.0")
kotlinComposeWasmDependency("org.jetbrains.compose.material:material:1.6.0")
kotlinComposeWasmDependency("org.jetbrains.compose.components:components-resources:1.6.0")

composeWasmCompilerPlugins("org.jetbrains.compose.compiler:compiler-hosted:1.5.10")
kotlinComposeWasmDependency("org.jetbrains.compose.runtime:runtime:$composeRuntimeVersion")
kotlinComposeWasmDependency("org.jetbrains.compose.ui:ui:$composeRuntimeVersion")
kotlinComposeWasmDependency("org.jetbrains.compose.animation:animation:$composeRuntimeVersion")
kotlinComposeWasmDependency("org.jetbrains.compose.animation:animation-graphics:$composeRuntimeVersion")
kotlinComposeWasmDependency("org.jetbrains.compose.foundation:foundation:$composeRuntimeVersion")
kotlinComposeWasmDependency("org.jetbrains.compose.material:material:$composeRuntimeVersion")
kotlinComposeWasmDependency("org.jetbrains.compose.components:components-resources:$composeRuntimeVersion")

composeWasmCompilerPlugins("org.jetbrains.kotlin:kotlin-compose-compiler-plugin:$kotlinVersion")
}
1 change: 1 addition & 0 deletions executor.policy
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ grant {
permission java.io.FilePermission "%%GENERATED%%/*", "read";
permission java.util.PropertyPermission "com.fasterxml.jackson.core.util.BufferRecyclers.trackReusableBuffers", "read";
permission java.util.PropertyPermission "kotlin.collections.*", "read";
permission java.util.PropertyPermission "kotlinx.io.*", "read";
};

grant codeBase "file:%%LIB_DIR%%/executors.jar"{
Expand Down
5 changes: 3 additions & 2 deletions executors/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
Expand All @@ -11,8 +12,8 @@ dependencies {
}

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "17"
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
systemProp.kotlinVersion=1.9.24
systemProp.kotlinIdeVersion=1.9.20-RC2-494
systemProp.kotlinVersion=2.0.0
systemProp.kotlinIdeVersion=1.9.20-506
systemProp.kotlinIdeVersionSuffix=IJ8109.175
systemProp.policy=executor.policy
systemProp.indexes=indexes.json
Expand Down
2 changes: 1 addition & 1 deletion indexation/src/main/kotlin/JvmIndexationBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProvid
class JvmIndexationBuilder(private val kotlinEnvironment: KotlinEnvironment): IndexationBuilder() {
override fun getAllIndexes(): List<ImportInfo> =
kotlinEnvironment.environment { coreEnvironment ->
val trace = CliBindingTrace()
val project = coreEnvironment.project
val trace = CliBindingTrace(project)
val componentProvider = TopDownAnalyzerFacadeForJVM.createContainer(
project = project,
files = emptyList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,25 @@ fun <T> CLICompiler<*>.tryCompilation(inputDirectory: Path, inputFiles: List<Pat
message: String,
location: CompilerMessageSourceLocation?
): String {
val textInterval = location?.let {
TextInterval(
start = TextInterval.TextPosition(minusOne(location.line), minusOne(location.column)),
end = TextInterval.TextPosition(minusOne(location.lineEnd), minusOne(location.columnEnd))
)
when {
// suppress -XXLanguage:+ExplicitBackingFields
severity == STRONG_WARNING && message.contains("ExplicitBackingFields") ->
return ""
}

val messageSeverity: ProjectSeveriry = when (severity) {
EXCEPTION, ERROR -> ProjectSeveriry.ERROR
STRONG_WARNING, WARNING -> ProjectSeveriry.WARNING
INFO, LOGGING, OUTPUT -> return ""
}

val textInterval = location?.let {
TextInterval(
start = TextInterval.TextPosition(minusOne(location.line), minusOne(location.column)),
end = TextInterval.TextPosition(minusOne(location.lineEnd), minusOne(location.columnEnd))
)
}

val errorFilePath = location?.path?.let(::Path)?.outputFilePathString() ?: defaultFileName

val className = if (!message.startsWith(UNRESOLVED_REFERENCE_PREFIX) && severity == ERROR) "red_wavy_line" else messageSeverity.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class ErrorAnalyzer(
}

fun analysisOf(files: List<KtFile>, coreEnvironment: KotlinCoreEnvironment): Analysis {
val trace = CliBindingTrace()
val project = files.first().project
val trace = CliBindingTrace(project)
val componentProvider = TopDownAnalyzerFacadeForJVM.createContainer(
project = project,
files = files,
Expand Down Expand Up @@ -157,7 +157,7 @@ class ErrorAnalyzer(
)
val dependencies = mutableSetOf(context.module) + mds + JsPlatformAnalyzerServices.builtIns.builtInsModule
context.module.setDependencies(dependencies.toList())
val trace = CliBindingTrace()
val trace = CliBindingTrace(project)
val providerFactory = FileBasedDeclarationProviderFactory(context.storageManager, files)
val analyzerAndProvider = createContainerForTopDownAnalyzerForJs(context, trace, providerFactory, JsPlatforms.defaultJsPlatform, JsPlatformAnalyzerServices)

Expand Down Expand Up @@ -242,7 +242,7 @@ class ErrorAnalyzer(
)
val dependenciesDescriptors = mutableSetOf(context.module) + mds + WasmPlatformAnalyzerServices.builtIns.builtInsModule
context.module.setDependencies(dependenciesDescriptors.toList())
val trace = CliBindingTrace()
val trace = CliBindingTrace(project)
val providerFactory = FileBasedDeclarationProviderFactory(context.storageManager, files)
val analyzerAndProvider = createContainerForTopDownAnalyzerForJs(context, trace, providerFactory, WasmPlatforms.Default, WasmPlatformAnalyzerServices)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class IndexationProvider(
@Value("\${indexesComposeWasm.file}") private val indexesComposeWasmFileName: String,
) {
companion object {
const val UNRESOLVED_REFERENCE_PREFIX = "Unresolved reference: "
const val UNRESOLVED_REFERENCE_PREFIX = "Unresolved reference "
private val log = LogFactory.getLog(IndexationProvider::class.java)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class KotlinToJSTranslator(
))
}
.map { (outputDir / "js" / "$moduleName.js").readText() }
.map { it.withMainArgumentsIr(arguments, moduleName) }
.map { it.withMainArgumentsIr(arguments) }
.map(::redirectOutput)
}
}
Expand Down Expand Up @@ -184,17 +184,17 @@ class KotlinToJSTranslator(
}
}

private fun String.withMainArgumentsIr(arguments: List<String>, moduleName: String): String {
val postfix = """| main([]);
| return _;
|}(typeof $moduleName === 'undefined' ? {} : $moduleName);
|""".trimMargin()
if (!endsWith(postfix)) return this
val objectMapper = ObjectMapper()
return this.removeSuffix(postfix) + """| main([${arguments.joinToString { objectMapper.writeValueAsString(it) }}]);
| return _;
|}(typeof $moduleName === 'undefined' ? {} : $moduleName);
|""".trimMargin()
private fun String.withMainArgumentsIr(arguments: List<String>): String {
val mainIrFunction = """
| function mainWrapper() {
| main([%s]);
| }
""".trimMargin()

return replace(
String.format(mainIrFunction, ""),
String.format(mainIrFunction, arguments.joinToString { ObjectMapper().writeValueAsString(it) })
)
}

data class WasmTranslationSuccessfulOutput(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.compiler.server.configuration

import com.compiler.server.controllers.CompilerRestController
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import springfox.documentation.builders.PathSelectors
import springfox.documentation.builders.RequestHandlerSelectors
import springfox.documentation.spi.DocumentationType
import springfox.documentation.spring.web.plugins.Docket

@Configuration
class SwaggerConfiguration {
@Bean
fun apiDocket(): Docket {
return Docket(DocumentationType.OAS_30)
.select()
// If controllers are in different packages we should add selectors for these packages as well
.apis(RequestHandlerSelectors.basePackage(CompilerRestController::class.java.packageName))
.paths(PathSelectors.any())
.build()
}
}
19 changes: 19 additions & 0 deletions src/test/kotlin/com/compiler/server/CoroutinesRunnerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,25 @@ class CoroutinesRunnerTest : BaseExecutorTest() {
)
}

@Test
fun `IO coroutine out order`() {
run(
//language=kotlin
code = """
import kotlinx.coroutines.*

fun main() = runBlocking {
CoroutineScope(Dispatchers.IO).launch {
delay(1000)
println("A")
}
println("B")
delay(2000)
}
""".trimIndent(),
contains = "<outStream>B\nA\n</outStream>"
)
}

@Test
@Disabled
Expand Down
Loading
Loading