Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 517f219

Browse files
committed
1 parent 6586d05 commit 517f219

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
plugins {
3+
kotlin("jvm")
4+
}
5+
6+
val kotlinVersion: String by rootProject.extra
7+
8+
dependencies {
9+
implementation(project(":jvm:basic:jvm-simple-script:script"))
10+
implementation("org.jetbrains.kotlin:kotlin-scripting-jvm:$kotlinVersion")
11+
compileOnly("org.jetbrains.kotlin:kotlin-scripting-jvm-host:$kotlinVersion")
12+
testRuntimeOnly("org.jetbrains.kotlin:kotlin-scripting-jvm-host-embeddable:$kotlinVersion")
13+
testRuntimeOnly("com.google.guava:guava:28.2-jre")
14+
testImplementation("junit:junit:4.12")
15+
}
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
4+
*/
5+
package org.jetbrains.kotlin.script.examples.jvm.embeddable.host
6+
7+
import org.jetbrains.kotlin.script.examples.jvm.simple.SimpleScript
8+
import java.io.File
9+
import kotlin.script.experimental.api.EvaluationResult
10+
import kotlin.script.experimental.api.ResultWithDiagnostics
11+
import kotlin.script.experimental.host.toScriptSource
12+
import kotlin.script.experimental.jvm.dependenciesFromCurrentContext
13+
import kotlin.script.experimental.jvm.jvm
14+
import kotlin.script.experimental.jvmhost.BasicJvmScriptingHost
15+
import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromTemplate
16+
17+
fun evalFile(scriptFile: File): ResultWithDiagnostics<EvaluationResult> {
18+
val compilationConfiguration = createJvmCompilationConfigurationFromTemplate<SimpleScript> {
19+
jvm {
20+
dependenciesFromCurrentContext(
21+
"script", /* script library jar name */
22+
"guava",
23+
wholeClasspath = true
24+
)
25+
}
26+
}
27+
28+
return BasicJvmScriptingHost().eval(scriptFile.toScriptSource(), compilationConfiguration, null)
29+
}
30+
31+
fun main(vararg args: String) {
32+
if (args.size != 1) {
33+
println("usage: <app> <script file>")
34+
} else {
35+
val scriptFile = File(args[0])
36+
println("Executing script $scriptFile")
37+
38+
val res = evalFile(scriptFile)
39+
40+
res.reports.forEach {
41+
println(" : ${it.message}" + if (it.exception == null) "" else ": ${it.exception}")
42+
}
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
4+
*/
5+
6+
package org.jetbrains.kotlin.script.examples.jvm.embeddable.test
7+
8+
import org.jetbrains.kotlin.script.examples.jvm.embeddable.host.evalFile
9+
import org.junit.Assert
10+
import java.io.File
11+
import org.junit.Test
12+
import kotlin.script.experimental.api.ResultWithDiagnostics
13+
14+
class SimpleTest {
15+
16+
@Test
17+
fun testSimple() {
18+
// guava is packed into the kotlin compiler jar, so this test will fail on the regular compiler jar
19+
// see comments in the script file
20+
val res = evalFile(File("testData/useGuava.simplescript.kts"))
21+
22+
Assert.assertTrue(
23+
"test failed:\n ${res.reports.joinToString("\n ") { it.message + if (it.exception == null) "" else ": ${it.exception}" }}",
24+
res is ResultWithDiagnostics.Success
25+
)
26+
}
27+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
// assuming to be executed on proguarded compiler in which `newArrayList` is present, but `asList` ist removed
3+
// first pulling `newArrayList`, so with non-embeddable (not shaded) host/compiler the class `Lists` will be pulled from
4+
// the guava embedded into compiler, then using `asList`, which should not be present in this version of the class due to proguarding
5+
// So, the compilation should only succeed if shaded compiler is used and `Lists` are loaded from the non-embedded guava jar
6+
7+
val arr = com.google.common.collect.Lists.newArrayList<Int>()
8+
val lst = listOf("Hello", "Guava")
9+
val glist = com.google.common.collect.Lists.asList(lst.first(), lst[1], emptyArray())
10+
11+
println(glist.joinToString(", ", "", "!"))

‎settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ include("jvm:basic:jvm-simple-script:host")
1111

1212
include("jvm:basic:jvm-maven-deps:script")
1313
include("jvm:basic:jvm-maven-deps:host")
14+
15+
include("jvm:basic:jvm-embeddable-host")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /