public GremlinJythonScriptEngine(final Customizer... customizers) { this.pyScriptEngine = (PyScriptEngine) new PyScriptEngineFactory().getScriptEngine(); final List<Customizer> listOfCustomizers = new ArrayList<>(Arrays.asList(customizers)); // always need this plugin for a scriptengine to be "Gremlin-enabled" CoreGremlinPlugin.instance().getCustomizers("gremlin-jython").ifPresent(c -> listOfCustomizers.addAll(Arrays.asList(c))); final List<ImportCustomizer> importCustomizers = listOfCustomizers.stream() .filter(p -> p instanceof ImportCustomizer) .map(p -> (ImportCustomizer) p) .collect(Collectors.toList()); try { for (ImportCustomizer ic : importCustomizers) { for (Class<?> c : ic.getClassImports()) { if (null == c.getDeclaringClass()) this.pyScriptEngine.eval("from " + c.getPackage().getName() + " import " + c.getSimpleName()); else this.pyScriptEngine.eval("from " + c.getPackage().getName() + "." + c.getDeclaringClass().getSimpleName() + " import " + c.getSimpleName()); } for (Method m : ic.getMethodImports()) { this.pyScriptEngine.eval(SymbolHelper.toPython(m.getName()) + " = " + m.getDeclaringClass().getSimpleName() + "." + m.getName()); } // enums need to import after methods for some reason or else label comes in as a PyReflectedFunction for (Enum e : ic.getEnumImports()) { this.pyScriptEngine.eval(SymbolHelper.toPython(e.name()) + " = " + e.getDeclaringClass().getSimpleName() + "." + e.name()); } } loadSugar(); } catch (Exception ex) { throw new IllegalStateException(ex); } }
CoreGremlinPlugin.instance().getCustomizers("gremlin-groovy").ifPresent(c -> listOfCustomizers.addAll(Arrays.asList(c)));
CoreGremlinPlugin.instance().getCustomizers("gremlin-groovy").ifPresent(c -> listOfCustomizers.addAll(Arrays.asList(c)));