Code Monkey home page Code Monkey logo

kotlin-compiler-server's Introduction

Kotlin compiler server

Build Status Java CI TC status Kotlin GitHub license Docker Cloud Build Status

A REST server for compiling and executing Kotlin code. The server provides the API for Kotlin Playground library.

How to start ๐Ÿ

Simple Spring Boot application

Download Kotlin dependencies and build an executor before starting the server:

$ ./gradlew build -x test 

Start the Spring Boot project. The main class: com.compiler.server.CompilerApplication

From Docker Hub

View images on Docker Hub.

docker pull prendota/kotlin-compiler-server

From Amazon lambda

Based on aws-serverless-container.

$ ./gradlew buildLambda

Getting .zip file from build/distributions.

Lambda handler: com.compiler.server.lambdas.StreamLambdaHandler::handleRequest.

Publish your Lambda function: you can follow the instructions in AWS Lambda's documentation on how to package your function for deployment.

From Kotless

Coming soon...

API Documentation ๐Ÿ“ƒ

Execute Kotlin code on JVM

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<String>) {\n    println(\"123\")\n}"
        }
    ]
}'

Translate Kotlin code to JavaScript code

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

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

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}"
    }
  ]
}'

Get code analysis results

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

curl -X GET http://localhost:8080/versions

The server also supports an API for the Kotlin Playground library.

How to add your dependencies to kotlin compiler ๐Ÿ“š

Just put whatever you need as dependencies to 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. Click here 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 "<<ALL FILES>>", "read";
  permission java.lang.RuntimePermission "accessDeclaredMembers";
};

CORS configuration

Set the environment variables

ENV Default value
ACCESS_CONTROL_ALLOW_ORIGIN_VALUE *
ACCESS_CONTROL_ALLOW_HEADER_VALUE *

Kotlin release guide ๐Ÿš€

  1. Update the kotlin version in gradle.properties
  2. Update the kotlin version in build.gradle.kts
  3. Update the kotlin version in Dockerfile
  4. Make sure everything is going well via the task:
$ ./gradlew build
  1. Save branch with the name of the kotlin version. Pattern: /^[0-9.]+$/ (optional)
  2. Bump version on GitHub releases (optional)

kotlin-compiler-server's People

Contributors

alexanderprendota avatar dsavvinov avatar erokhins avatar myannyax avatar p7nov avatar renovate-bot avatar renovate[bot] avatar rvadim avatar stasjas avatar wayfarer-rus avatar zarechenskiy avatar zhelenskiy avatar zoobestik avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.