3636
3737import javax .script .ScriptEngine ;
3838
39+ import org .scijava .log .LogService ;
40+ import org .scijava .plugin .Parameter ;
3941import org .scijava .plugin .Plugin ;
4042import org .scijava .script .AdaptedScriptLanguage ;
4143import org .scijava .script .ScriptLanguage ;
5658@ Plugin (type = ScriptLanguage .class , name = "Scala" )
5759public class ScalaScriptLanguage extends AdaptedScriptLanguage {
5860
61+ @ Parameter
62+ private LogService log ;
63+
5964 public ScalaScriptLanguage () {
6065 super ("scala" );
6166 }
@@ -69,13 +74,16 @@ public ScriptEngine getScriptEngine() {
6974 new NewLinePrintWriter (new ConsoleWriter (), true ));
7075 }
7176
72- /**
73- * Uses ClassLoader to generate a string of the current classpath separated by
74- * OS specific separator.
75- */
76- private static String getClasspath () {
77- return Arrays .stream (((URLClassLoader ) ClassLoader .getSystemClassLoader ())
78- .getURLs ()).map (url -> url .getPath ()).collect (Collectors .joining (System
79- .getProperty ("path.separator" )));
77+ /** Retrieves the current classpath as a string. */
78+ private String getClasspath () {
79+ final ClassLoader cl = ClassLoader .getSystemClassLoader ();
80+ if (!(cl instanceof URLClassLoader )) {
81+ log .warn ("Cannot retrieve classpath from class loader of type '" +
82+ cl .getClass ().getName () + "'" );
83+ return System .getProperty ("java.class.path" );
84+ }
85+ return Arrays .stream (((URLClassLoader ) cl ).getURLs ()).map (//
86+ url -> url .getPath () //
87+ ).collect (Collectors .joining (System .getProperty ("path.separator" )));
8088 }
8189}
0 commit comments