Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ Wisconsin-Madison.</license.copyrightOwners>

<!-- NB: Work around duplicate classes issue in Kotlin dependencies-->
<allowedDuplicateClasses>org/jetbrains/kotlin/daemon/common/*,kotlinx/coroutines/**</allowedDuplicateClasses>
<kotlin.version>1.4.30</kotlin.version>
<!-- NB: Have to disable manifest-only jar ot be able to run tests on command line. -->
<!-- NB: Tests work in IntelliJ but manifest-only jar seems to mess with it on command line. -->
<!-- NB: cf: mvn surefire:help -Ddetail=true -->
<surefire.useManifestOnlyJar>false</surefire.useManifestOnlyJar>
</properties>

<repositories>
Expand All @@ -111,20 +116,13 @@ Wisconsin-Madison.</license.copyrightOwners>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-script-util</artifactId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-script-runtime</artifactId>
<artifactId>kotlin-scripting-jsr223</artifactId>
<version>${kotlin.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-scripting-compiler-embeddable</artifactId>
<version>${kotlin.version}</version>
<scope>runtime</scope>
</dependency>

<!-- Test dependencies -->
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* #%L
* JSR-223-compliant Kotlin scripting language plugin.
* %%
* Copyright (C) 2016 - 2019 Board of Regents of the University of
* Wisconsin-Madison.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package org.scijava.plugins.scripting.kotlin

import org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineFactoryBase
import org.scijava.plugin.Plugin
import org.scijava.script.AdaptedScriptLanguage
import org.scijava.script.ScriptLanguage
import java.io.Reader
import javax.script.*

/**
* A SciJava [ScriptLanguage] for Kotlin.
*
* @author Curtis Rueden
* @author Philipp Hanslovsky
* @see ScriptEngine
*/
@Plugin(type = ScriptLanguage::class, name = "Kotlin")
class KotlinScriptLanguage : AdaptedScriptLanguage(Factory()) {
// NB: The wrapped ScriptEngineFactory does not include Kotlin in its list.
override fun getNames() = listOf("kotlin", "Kotlin")

// NB: The wrapped ScriptEngineFactory does not include .kt in its list.
override fun getExtensions() = listOf("kt", "kts")

class Factory : KotlinJsr223JvmScriptEngineFactoryBase() {
override fun getScriptEngine(): ScriptEngine {
return SynchronizedScriptEngine(ScriptEngineManager().getEngineByExtension("kts"))
}
}

class SynchronizedScriptEngine(private val delegate: ScriptEngine) : ScriptEngine {
@Synchronized
@Throws(ScriptException::class)
override fun eval(s: String, scriptContext: ScriptContext): Any? = delegate.eval(s, scriptContext)

@Synchronized
@Throws(ScriptException::class)
override fun eval(reader: Reader, scriptContext: ScriptContext): Any? = delegate.eval(reader, scriptContext)

@Synchronized
@Throws(ScriptException::class)
override fun eval(s: String): Any? = delegate.eval(s)

@Synchronized
@Throws(ScriptException::class)
override fun eval(reader: Reader): Any? = delegate.eval(reader)

@Synchronized
@Throws(ScriptException::class)
override fun eval(s: String, bindings: Bindings): Any? = delegate.eval(s, bindings)

@Synchronized
@Throws(ScriptException::class)
override fun eval(reader: Reader, bindings: Bindings): Any? = delegate.eval(reader, bindings)

@Synchronized
override fun put(s: String, o: Any) = delegate.put(s, o)

@Synchronized
override fun get(s: String): Any? = delegate[s]

@Synchronized
override fun getBindings(i: Int): Bindings? = delegate.getBindings(i)

@Synchronized
override fun setBindings(bindings: Bindings, i: Int) = delegate.setBindings(bindings, i)

@Synchronized
override fun createBindings(): Bindings = delegate.createBindings()

@Synchronized
override fun getContext(): ScriptContext = delegate.context

@Synchronized
override fun setContext(scriptContext: ScriptContext) {
delegate.context = scriptContext
}

@Synchronized
override fun getFactory(): ScriptEngineFactory = delegate.factory
}
}
128 changes: 0 additions & 128 deletions src/test/java/org/scijava/plugins/scripting/kotlin/KotlinTest.java

This file was deleted.

Loading