diff --git a/build.xml b/build.xml
index 78370000557..9376d85ee25 100644
--- a/build.xml
+++ b/build.xml
@@ -801,24 +801,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
+
-
-
@@ -1398,7 +1411,7 @@
depends="builtins,stdlib,kotlin-test,core,reflection,pack-runtime,pack-runtime-sources,script-runtime,mock-runtime-for-test"/>
tools/kotlin-compiler
tools/kotlin-compiler-embeddable
+ tools/kotlin-compiler-client-embeddable
+ tools/kotlin-compiler-client-embeddable-test
tools/native-platform
tools/kotlin-compiler-runner
tools/kotlin-daemon-client
diff --git a/libraries/tools/kotlin-compiler-client-embeddable-test/pom.xml b/libraries/tools/kotlin-compiler-client-embeddable-test/pom.xml
new file mode 100644
index 00000000000..508da6a3425
--- /dev/null
+++ b/libraries/tools/kotlin-compiler-client-embeddable-test/pom.xml
@@ -0,0 +1,117 @@
+
+
+
+ 4.0.0
+
+ 1.4.1
+ 3.0.4
+
+
+
+ org.jetbrains.kotlin
+ kotlin-project
+ 1.1-SNAPSHOT
+ ../../pom.xml
+
+
+ kotlin-compiler-client-embeddable-test
+ jar
+
+ the Kotlin compiler client embeddable tests
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib
+ ${project.version}
+ test
+
+
+ org.jetbrains.kotlin
+ kotlin-script-runtime
+ ${project.version}
+ test
+
+
+ org.jetbrains.kotlin
+ kotlin-test-junit
+ ${project.version}
+ test
+
+
+ org.jetbrains.kotlin
+ kotlin-compiler-client-embeddable
+ ${project.version}
+ test
+
+
+ org.jetbrains.kotlin
+ kotlin-compiler
+ ${project.version}
+ test
+
+
+
+
+ ${project.basedir}/src/test/kotlin
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+ 2.3
+
+
+
+ properties
+
+
+
+
+
+
+ kotlin-maven-plugin
+ org.jetbrains.kotlin
+ ${project.version}
+
+
+
+ test-compile
+ test-compile
+ test-compile
+
+
+
+
+
+ maven-failsafe-plugin
+ 2.6
+
+ ${project.build.directory}
+
+ ${env.JDK_17}/bin/java
+ ${org.jetbrains.kotlin:kotlin-compiler:jar}
+ ${org.jetbrains.kotlin:kotlin-stdlib:jar}
+ ${org.jetbrains.kotlin:kotlin-script-runtime:jar}
+
+
+
+
+
+ integration-test
+ verify
+
+
+
+
+
+ maven-deploy-plugin
+
+ true
+
+
+
+
+
diff --git a/libraries/tools/kotlin-compiler-client-embeddable-test/src/test/kotlin/org/jetbrains/kotlin/compiler/client/CompilerClientIT.kt b/libraries/tools/kotlin-compiler-client-embeddable-test/src/test/kotlin/org/jetbrains/kotlin/compiler/client/CompilerClientIT.kt
new file mode 100644
index 00000000000..5c4e6312e4a
--- /dev/null
+++ b/libraries/tools/kotlin-compiler-client-embeddable-test/src/test/kotlin/org/jetbrains/kotlin/compiler/client/CompilerClientIT.kt
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2010-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jetbrains.kotlin.compiler.client
+
+import org.junit.Rule
+import org.junit.Test
+import org.junit.rules.TemporaryFolder
+import java.io.File
+import java.io.FileNotFoundException
+import kotlin.test.assertEquals
+import org.jetbrains.kotlin.daemon.client.*
+import org.jetbrains.kotlin.daemon.common.*
+import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
+import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
+import org.jetbrains.kotlin.cli.common.messages.MessageCollector
+import java.io.ByteArrayOutputStream
+import java.io.PrintStream
+
+
+class CompilerClientIT {
+
+ @JvmField
+ @Rule
+ val workingDir = TemporaryFolder()
+
+ private val compilerClasspath: List by lazy {
+ listOf(fileFromProp("compilerJar", "kotlin-compiler.jar"))
+ }
+
+ private val compilationClasspath: List by lazy {
+ listOf(fileFromProp("stdlibJar", "kotlin-stdlib.jar"),
+ fileFromProp("scriptRuntimeJar", "kotlin-script-runtime.jar"))
+ }
+
+ private val clientAliveFile by lazy {
+ createTempFile("client", ".alive").apply {
+ deleteOnExit()
+ }
+ }
+
+ private fun fileFromProp(propName: String, defaultPath: String) =
+ File((System.getProperty(propName) ?: defaultPath)).apply {
+ if (!exists())
+ throw FileNotFoundException("cannot find $defaultPath ($this)")
+ }
+
+ private val compilerService: CompileService by lazy {
+ val compilerId = CompilerId.makeCompilerId(compilerClasspath)
+ val daemonOptions = DaemonOptions(runFilesPath = File(workingDir.root, "daemonRunPath").absolutePath, verbose = true, reportPerf = true)
+ val daemonJVMOptions = org.jetbrains.kotlin.daemon.common.DaemonJVMOptions()
+ val daemonReportMessages = arrayListOf()
+
+ KotlinCompilerClient.connectToCompileService(compilerId, clientAliveFile, daemonJVMOptions, daemonOptions,
+ DaemonReportingTargets(messages = daemonReportMessages), true)
+ ?: throw IllegalStateException("Unable to connect to compiler daemon:" + daemonReportMessages.joinToString("\n ", prefix = "\n ") { "${it.category.name} ${it.message}" })
+ }
+
+ private val myMessageCollector = TestMessageCollector()
+
+ @Test
+ fun testSimpleScript() {
+ val (out, code) = runCompiler(
+ "-cp", compilationClasspath.joinToString(File.pathSeparator) { it.canonicalPath },
+ File("../src/test/resources/scripts/simpleHelloWorld.kts").canonicalPath)
+ assertEquals(0, code, "compilation failed:\n" + out + "\n")
+ }
+
+ private fun runCompiler(vararg args: String): Pair {
+
+ var code = -1
+ myMessageCollector.clear()
+ val out = captureOutAndErr {
+ code = KotlinCompilerClient.compile(compilerService, CompileService.NO_SESSION, CompileService.TargetPlatform.JVM, args, myMessageCollector,
+ reportSeverity = ReportSeverity.DEBUG)
+ }
+ return myMessageCollector.messages.joinToString("\n") { it.message } + "\n" + out to code
+ }
+}
+
+internal fun captureOutAndErr(body: () -> Unit): String {
+ val outStream = ByteArrayOutputStream()
+ val prevOut = System.out
+ val prevErr = System.err
+ System.setOut(PrintStream(outStream))
+ System.setErr(PrintStream(outStream))
+ try {
+ body()
+ }
+ finally {
+ System.out.flush()
+ System.setOut(prevOut)
+ System.err.flush()
+ System.setErr(prevErr)
+ }
+ return outStream.toString()
+}
+
+class TestMessageCollector : MessageCollector {
+
+ data class Message(val severity: CompilerMessageSeverity, val message: String, val location: CompilerMessageLocation)
+
+ val messages = arrayListOf()
+
+ override fun clear() {
+ messages.clear()
+ }
+
+ override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) {
+ messages.add(Message(severity, message, location))
+ }
+
+ override fun hasErrors(): Boolean = messages.any { it.severity == CompilerMessageSeverity.EXCEPTION || it.severity == CompilerMessageSeverity.ERROR }
+}
diff --git a/libraries/tools/kotlin-compiler-client-embeddable-test/src/test/resources/scripts/simpleHelloWorld.kts b/libraries/tools/kotlin-compiler-client-embeddable-test/src/test/resources/scripts/simpleHelloWorld.kts
new file mode 100644
index 00000000000..af528c8ce7b
--- /dev/null
+++ b/libraries/tools/kotlin-compiler-client-embeddable-test/src/test/resources/scripts/simpleHelloWorld.kts
@@ -0,0 +1,2 @@
+
+println("Hello, World!")
diff --git a/libraries/tools/kotlin-compiler-client-embeddable/pom.xml b/libraries/tools/kotlin-compiler-client-embeddable/pom.xml
new file mode 100644
index 00000000000..010f6da3401
--- /dev/null
+++ b/libraries/tools/kotlin-compiler-client-embeddable/pom.xml
@@ -0,0 +1,68 @@
+
+
+
+ 4.0.0
+
+ 1.4.1
+ 3.0.4
+
+
+
+ org.jetbrains.kotlin
+ kotlin-project
+ 1.1-SNAPSHOT
+ ../../pom.xml
+
+
+ kotlin-compiler-client-embeddable
+ jar
+
+ the Kotlin compiler client embeddable
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.6
+
+
+ empty-sources-jar
+ package
+
+ jar
+
+
+ false
+ sources
+ ${basedir}/sources
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-antrun-plugin
+
+
+ copy-jar
+ package
+
+
+
+
+
+
+ run
+
+
+
+
+
+
+
diff --git a/resources/kotlinManifest.properties b/resources/kotlinManifest.properties
index 43fa48034bf..f4f1558b453 100644
--- a/resources/kotlinManifest.properties
+++ b/resources/kotlinManifest.properties
@@ -28,8 +28,11 @@ manifest.impl.title.kotlin.runner=Kotlin Runner
manifest.impl.title.kotlin.test=Kotlin Testing library
-manifest.impl.title.kotlin.daemon-client=Kotlin Compile Daemon Client
+manifest.impl.title.kotlin.daemon.client=Kotlin Compile Daemon Client
manifest.impl.title.kotlin.daemon.client.sources=Kotlin Compile Daemon Client Sources
manifest.impl.title.kotlin.build.common=Kotlin Build Common
manifest.impl.title.kotlin.build.common.sources=Kotlin Build Common Sources
+
+manifest.impl.title.kotlin.compiler.client.embeddable=Kotlin Compiler Client Embeddable
+manifest.impl.title.kotlin.compiler.client.embeddable.sources=Kotlin Compiler Client Embeddable Sources