Giter Site home page Giter Site logo

scripting-scala's Introduction

Scala Scripting

This library provides a JSR-223-compliant scripting plugin for the Scala language.

It is implemented as a ScriptLanguage plugin for the SciJava Common platform, which means that in addition to being usable directly as a javax.script.ScriptEngineFactory, it also provides some functionality on top, such as the ability to generate lines of script code based on SciJava events.

For a complete list of scripting languages available as part of the SciJava platform, see the Scripting page on the SciJava Common wiki.

scripting-scala's People

Contributors

ctrueden avatar dscho avatar jpsacha avatar keithschulze avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scripting-scala's Issues

Scala 2.12.0-M4 dependency

Just a question as to why scripting-scala depends on the pre-release 2.12.0-M4 version of Scala? Looking at the repo, it seems it was introduced for JSR-223 script engine capatibility; however, as far as I can tell this is available in Scala 2.11 too. Thanks in advance.

MissingCoreLibraryException when running script in FIJI

Cannot evaluate scripts in FIJI without explicitly adding each Scala library and each library used in script to java.class.path

Example of FIJI error

[ERROR] java.util.concurrent.ExecutionException: dotty.tools.dotc.MissingCoreLibraryException: Could not find package scala from compiler core libraries.
Make sure the compiler core libraries are on the classpath.
   
	at java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.util.concurrent.FutureTask.get(FutureTask.java:192)
	at org.scijava.ui.swing.script.TextEditor.evalScript(TextEditor.java:3439)
	at org.scijava.ui.swing.script.TextEditor.access$600(TextEditor.java:208)
	at org.scijava.ui.swing.script.TextEditor$5.execute(TextEditor.java:2761)
	at org.scijava.ui.swing.script.TextEditor$Executer$1.run(TextEditor.java:2526)
Caused by: dotty.tools.dotc.MissingCoreLibraryException: Could not find package scala from compiler core libraries.
Make sure the compiler core libraries are on the classpath.

	at dotty.tools.dotc.core.Denotations$.select$1(Denotations.scala:1318)
	at dotty.tools.dotc.core.Denotations$.recurSimple$1(Denotations.scala:1346)
	at dotty.tools.dotc.core.Denotations$.recur$1(Denotations.scala:1348)
	at dotty.tools.dotc.core.Denotations$.staticRef(Denotations.scala:1352)
	at dotty.tools.dotc.core.Symbols$.requiredPackage(Symbols.scala:865)
	at dotty.tools.dotc.core.Definitions.ScalaPackageVal(Definitions.scala:230)
	at dotty.tools.dotc.core.Definitions.ScalaPackageClass(Definitions.scala:233)
	at dotty.tools.dotc.core.Definitions.AnyClass(Definitions.scala:293)
	at dotty.tools.dotc.core.Definitions.syntheticScalaClasses(Definitions.scala:1957)
	at dotty.tools.dotc.core.Definitions.syntheticCoreClasses(Definitions.scala:1970)
	at dotty.tools.dotc.core.Definitions.init(Definitions.scala:1987)
	at dotty.tools.dotc.core.Contexts$ContextBase.initialize(Contexts.scala:868)
	at dotty.tools.repl.ReplDriver.setupRootCtx(ReplDriver.scala:92)
	at dotty.tools.repl.ReplDriver.initialCtx(ReplDriver.scala:84)
	at dotty.tools.repl.ReplDriver.resetToInitial(ReplDriver.scala:110)
	at dotty.tools.repl.ReplDriver.<init>(ReplDriver.scala:125)
	at dotty.tools.repl.ScriptEngine.<init>(ScriptEngine.scala:28)
	at dotty.tools.repl.ScriptEngine$Factory.getScriptEngine(ScriptEngine.scala:93)
	at org.scijava.plugins.scripting.scala.ScalaAdaptedScriptEngineFactory.getScriptEngine(ScalaAdaptedScriptEngineFactory.scala:53)
	at org.scijava.plugins.scripting.scala.ScalaAdaptedScriptEngineFactory.getScriptEngine(ScalaAdaptedScriptEngineFactory.scala:53)
	at org.scijava.script.AdaptedScriptLanguage.getScriptEngine(AdaptedScriptLanguage.java:138)
	at org.scijava.script.ScriptModule.getEngine(ScriptModule.java:114)
	at org.scijava.script.ScriptModule.run(ScriptModule.java:142)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:163)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:124)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:63)
	at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:225)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:750)

Internal `ServiceConfigurationError` when Script Engine is created

When javax.script.ScriptEngineManager is attempting to list available script engines, numerous ServiceConfigurationError are internally generated resulting in printouts to standard error output that look like:

ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider org.scijava.plugins.scripting.scala.ScalaScriptLanguage could not be instantiated
ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider dotty.tools.repl.ScriptEngine$Factory could not be instantiated

While the code still works and test are passing this is producing confusing printouts and slows down the execution of the scripts, tests are running about twice as long as without that issue.

The issue was introduced after META-INF/services/javax.script.ScriptEngineFactory was added #1.

eval should sometimes make an entry in the ENGINE_SCOPE bindings

scripting-scala's eval function does not quite match the JSR233 implementations for Nashorn and Jython. Specifically, eval should make an entry in the ScriptContext.ENGINE_SCOPE bindings whenever it receives a string that causes a new variable or method to be defined.

For example, this should cause a new variable called twelve to be defined:

eval("val twelve = 12")

I exercise several JSR233 implementations in a test suite here, and highlight this issue here.

The scripting-java and scripting-clojure projects probably suffer from the same bug.

ScriptREPL is not usable - problem with variables named as Scala keywords

Cannot evaluate any Scala code in ScriptREPL due to error:

-- [E032] Syntax Error: --------------------------------------------------------
212 |val object : org.scijava.object.DefaultObjectService = {
    |    ^^^^^^
    |    pattern expected
    |
    | longer explanation available when compiling with `-explain`
java.lang.ClassNotFoundException: rs$line$0
	at dotty.tools.repl.AbstractFileClassLoader.findClass(AbstractFileClassLoader.scala:51)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
...

One of the variables passed from ScriptREPL to ScalaAdaptedScriptEngine is called object leading to internal error in binding variables.

The can be addressed, on Scala side, using name in backticks while binding. In this case Scala variable would be called `object`.

Tests on Windows fail with: "InvalidPathException: Illegal char <:> at index 2: /C:/Users/..."

Constructor of SciJavaScriptEngine fails on Windows creating ReplDriver. The classPath has extra "/" at the beginning resulting in error:

ava.nio.file.InvalidPathException: Illegal char <:> at index 2: /C:/Users/...jar

	at sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
	at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
	at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
	at sun.nio.fs.WindowsPath.parse(WindowsPath.java:94)
	at sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:255)
	at java.nio.file.Paths.get(Paths.java:84)
	at dotty.tools.dotc.core.MacroClassLoader$.$anonfun$1(MacroClassLoader.scala:25)
	at scala.collection.immutable.List.map(List.scala:246)
	at dotty.tools.dotc.core.MacroClassLoader$.makeMacroClassLoader(MacroClassLoader.scala:25)
	at dotty.tools.dotc.core.MacroClassLoader$.init(MacroClassLoader.scala:19)
	at dotty.tools.dotc.Driver.setup(Driver.scala:77)
	at dotty.tools.repl.ReplDriver.setupRootCtx(ReplDriver.scala:88)
	at dotty.tools.repl.ReplDriver.initialCtx(ReplDriver.scala:84)
	at dotty.tools.repl.ReplDriver.resetToInitial(ReplDriver.scala:110)
	at dotty.tools.repl.ReplDriver.<init>(ReplDriver.scala:125)
	at dotty.tools.repl.SciJavaScriptEngine.<init>(SciJavaScriptEngine.scala:37)
	at dotty.tools.repl.SciJavaScriptEngine$Factory.getScriptEngine(SciJavaScriptEngine.scala:102)
	at org.scijava.plugins.scripting.scala.ScalaAdaptedScriptEngineFactory.getScriptEngine(ScalaAdaptedScriptEngineFactory.scala:55)
	at org.scijava.plugins.scripting.scala.ScalaAdaptedScriptEngineFactory.getScriptEngine(ScalaAdaptedScriptEngineFactory.scala:55)
	at org.scijava.script.AdaptedScriptLanguage.getScriptEngine(AdaptedScriptLanguage.java:138)
	at org.scijava.plugins.scripting.scala.ScalaTest.issue9(ScalaTest.java:340)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	...

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.