diff --git a/README.md b/README.md index f5423482f..f73a88e81 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,151 @@ -# Kotlin compiler server [![Build Status](https://travis-ci.com/AlexanderPrendota/kotlin-compiler-server.svg?branch=master)](https://travis-ci.com/AlexanderPrendota/kotlin-compiler-server) +# Kotlin compiler server [![Build Status](https://travis-ci.com/AlexanderPrendota/kotlin-compiler-server.svg?branch=master)](https://travis-ci.com/AlexanderPrendota/kotlin-compiler-server) [ ![Kotlin](https://img.shields.io/badge/Kotlin-1.3.60-orange.svg) ](https://kotlinlang.org/) [![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0) + +REST API for compiling and executing Kotlin code. +Server provides the API for [Kotlin Playground](https://github.com/JetBrains/kotlin-playground) library. + +## How to start + +Download Kotlin dependencies and build an executor before starting the server: + +```shell script +$ ./gradlew build -x test +``` + +Start the Spring Boot project. + +## API Documentation + +**Run code 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(args: Array) {\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) {\n println(args[0])\n }" + } + ] +}' +``` + +**Run 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" + } + ] +}' +``` + +**Code completions** + +```shell script +curl -X POST \ + 'http://localhost:8080/api/compiler/complete?line=1&ch=12' \ + -H 'Content-Type: application/json' \ + -d '{ + "files": [ + { + "name": "File.kt", + "text": "fun main() {\n 3.0.toIn\n}" + } + ] +}' +``` + +**Code analytics** + +```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}" + } + ] +}' +``` + +**Get the current Kotlin version** + +```shell script +curl -X GET http://localhost:8080/api/compiler/version +``` + + +Server also supports an [API](https://github.com/JetBrains/kotlin-playground) for the Kotlin Playground library. + +## How to add your dependencies to kotlin compiler :books: + +Just put whatever you need as dependencies to [build.gradle.kts](https://github.com/AlexanderPrendota/kotlin-compiler-server/blob/master/build.gradle.kts) via a task called `kotlinDependency`: + +``` + kotlinDependency "your dependency" +``` + +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). [Click here](https://docs.oracle.com/javase/7/docs/technotes/guides/security/PolicyFiles.html) for more information about *Java Security Policy*. + +**How to set Java Security Policy in `executors.policy`** + +If you want to configure a custom dependency, use the marker `@LIB_DIR@`: + +``` +grant codeBase "file:%%LIB_DIR%%/junit-4.12.jar"{ + permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; + permission java.lang.RuntimePermission "setIO"; + permission java.io.FilePermission "<>", "read"; + permission java.lang.RuntimePermission "accessDeclaredMembers"; +}; +``` + +## Kotlin release guide + +1) Update kotlin version in [gradle.properties](https://github.com/AlexanderPrendota/kotlin-compiler-server/blob/master/gradle.properties) +2) Just make sure everything is going well via the task: + +```shell script +$ ./gradlew build +``` Tasks: @@ -10,7 +157,7 @@ Tasks: 6) Test multi-version with spring starters (-) 7) New dir structure (+) 8) Support JUNIT (+) -9) Documentation +9) Documentation (+) 10) Test for compiler errors (+) 12) Endpoint for versions (+) 13) Readonly files (+)