Skip to content

Commit

Permalink
Add new artifact kotlin-compiler-client-embeddable.jar
Browse files Browse the repository at this point in the history
  • Loading branch information
ligee committed Apr 6, 2017
1 parent aebfc2f commit 7ceaca1
Show file tree
Hide file tree
Showing 8 changed files with 341 additions and 10 deletions.
29 changes: 21 additions & 8 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -801,24 +801,37 @@
</target>

<target name="compiler-client-embeddable">
<cleandir dir="${output}/classes/android-extensions/compiler-client-embeddable"/>
<javac2 destdir="${output}/classes/compiler-client-embeddable" debug="true" debuglevel="lines,vars,source" includeAntRuntime="false">
<withKotlin modulename="compiler-deps">
<compilerarg value="-version"/>
</withKotlin>
<src>
<pathelement path="compiler/daemon/daemon-common/src"/>
<pathelement path="compiler/cli/cli-common/"/>
</src>
<classpath>
<pathelement path="${kotlin-home}/lib/kotlin-compiler.jar"/>
<pathelement path="${idea.sdk}/core/intellij-core.jar"/>
</classpath>
</javac2>

<taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpath="dependencies/jarjar.jar"/>

<jarjar jarfile="${output}/kotlin-compiler-client-embeddable-before-shrink.jar">
<jarjar jarfile="${kotlin-home}/lib/kotlin-compiler-client-embeddable.jar">
<zipfileset file="${kotlin-home}/build.txt" prefix="META-INF"/>
<zipfileset src="${kotlin-home}/lib/kotlin-daemon-client.jar"/>
<fileset dir="${output}/classes/compiler"
includes="org/jetbrains/kotlin/daemon/common/** org/jetbrains/kotlin/cli/common/messages/CompilerMessage* org/jetbrains/kotlin/cli/common/messages/Message* org/jetbrains/kotlin/cli/common/repl/**"/>
<zipfileset src="${kotlin-home}/lib/kotlin-daemon-client.jar" excludes="net/rubygrapefruit/platform/** net/ net/rubygrapefruit/"/>
<fileset dir="${output}/classes/compiler-client-embeddable"
includes="META-INF/** org/jetbrains/kotlin/daemon/common/** org/jetbrains/kotlin/cli/common/messages/CompilerMessage* org/jetbrains/kotlin/cli/common/messages/Message* org/jetbrains/kotlin/cli/common/repl/**"/>

<manifest>
<attribute name="Built-By" value="${manifest.impl.vendor}"/>
<attribute name="Implementation-Vendor" value="${manifest.impl.vendor}"/>
<attribute name="Implementation-Title" value="${manifest.impl.title.kotlin.compiler.client,embeddable}"/>
<attribute name="Implementation-Title" value="${manifest.impl.title.kotlin.compiler.client.embeddable}"/>
<attribute name="Implementation-Version" value="${build.number}"/>
<attribute name="Class-Path" value="kotlin-stdlib.jar"/>
</manifest>
</jarjar>

<shrink configuration="${basedir}/compiler/compiler-client.pro"/>
</target>

<target name="android-extensions-compiler">
Expand Down Expand Up @@ -1398,7 +1411,7 @@
depends="builtins,stdlib,kotlin-test,core,reflection,pack-runtime,pack-runtime-sources,script-runtime,mock-runtime-for-test"/>

<target name="dist"
depends="clean,init,prepare-dist,preloader,runner,serialize-builtins,compiler,compiler-sources,ant-tools,runtime,kotlin-js-stdlib,android-extensions-compiler,allopen-compiler-plugin,noarg-compiler-plugin,sam-with-receiver-compiler-plugin,source-sections-compiler-plugin,annotation-processing-under-jdk8,daemon-client,kotlin-build-common-test"
depends="clean,init,prepare-dist,preloader,runner,serialize-builtins,compiler,compiler-sources,ant-tools,runtime,kotlin-js-stdlib,android-extensions-compiler,allopen-compiler-plugin,noarg-compiler-plugin,sam-with-receiver-compiler-plugin,source-sections-compiler-plugin,annotation-processing-under-jdk8,daemon-client,compiler-client-embeddable,kotlin-build-common-test"
description="Builds redistributables from sources"/>

<target name="dist-quick"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompil
import org.jetbrains.kotlin.load.kotlin.incremental.components.JvmPackagePartProto
import org.jetbrains.kotlin.modules.TargetId
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
import org.jetbrains.kotlin.utils.rethrow
import java.rmi.server.UnicastRemoteObject
import kotlin.reflect.full.allSuperclasses

Expand Down
2 changes: 2 additions & 0 deletions libraries/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
<modules>
<module>tools/kotlin-compiler</module>
<module>tools/kotlin-compiler-embeddable</module>
<module>tools/kotlin-compiler-client-embeddable</module>
<module>tools/kotlin-compiler-client-embeddable-test</module>
<module>tools/native-platform</module>
<module>tools/kotlin-compiler-runner</module>
<module>tools/kotlin-daemon-client</module>
Expand Down
117 changes: 117 additions & 0 deletions libraries/tools/kotlin-compiler-client-embeddable-test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<modelVersion>4.0.0</modelVersion>
<properties>
<maven-plugin-anno.version>1.4.1</maven-plugin-anno.version>
<maven.version>3.0.4</maven.version>
</properties>

<parent>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-project</artifactId>
<version>1.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>kotlin-compiler-client-embeddable-test</artifactId>
<packaging>jar</packaging>

<description>the Kotlin compiler client embeddable tests</description>

<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-script-runtime</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-compiler-client-embeddable</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-compiler</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${project.version}</version>

<executions>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals> <goal>test-compile</goal> </goals>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.6</version>
<configuration>
<workingDirectory>${project.build.directory}</workingDirectory>
<systemPropertyVariables>
<jvm>${env.JDK_17}/bin/java</jvm>
<compilerJar>${org.jetbrains.kotlin:kotlin-compiler:jar}</compilerJar>
<stdlibJar>${org.jetbrains.kotlin:kotlin-stdlib:jar}</stdlibJar>
<scriptRuntimeJar>${org.jetbrains.kotlin:kotlin-script-runtime:jar}</scriptRuntimeJar>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -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<File> by lazy {
listOf(fileFromProp("compilerJar", "kotlin-compiler.jar"))
}

private val compilationClasspath: List<File> 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<DaemonReportMessage>()

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<String, Int> {

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<Message>()

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 }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

println("Hello, World!")
68 changes: 68 additions & 0 deletions libraries/tools/kotlin-compiler-client-embeddable/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<modelVersion>4.0.0</modelVersion>
<properties>
<maven-plugin-anno.version>1.4.1</maven-plugin-anno.version>
<maven.version>3.0.4</maven.version>
</properties>

<parent>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-project</artifactId>
<version>1.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>kotlin-compiler-client-embeddable</artifactId>
<packaging>jar</packaging>

<description>the Kotlin compiler client embeddable</description>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>empty-sources-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<skipIfEmpty>false</skipIfEmpty>
<classifier>sources</classifier>
<classesDirectory>${basedir}/sources</classesDirectory>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>copy-jar</id>
<phase>package</phase>
<configuration>
<tasks>
<copy file="${kotlin-dist}/kotlinc/lib/kotlin-compiler-client-embeddable.jar"
tofile="${basedir}/target/${project.artifactId}-${project.version}.jar"
overwrite="true" verbose="true"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit 7ceaca1

Please sign in to comment.