com.twosigma.beakerx.kernel.EvaluatorParameters Java Examples
The following examples show how to use
com.twosigma.beakerx.kernel.EvaluatorParameters.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KotlinEvaluatorTest.java From beakerx with Apache License 2.0 | 6 votes |
@Test public void javaImports_shouldBeAdjustedForKotlin() throws Exception { //given Map<String, Object> paramMap = new HashMap<>(); // This import tests both "static" removal and "object" escaping. List<String> imports = asList( "import static com.twosigma.beakerx.kotlin.evaluator.object.ImportTestHelper.staticMethod"); paramMap.put(IMPORTS, imports); EvaluatorParameters kernelParameters = new EvaluatorParameters(paramMap); //when evaluator.updateEvaluatorParameters(kernelParameters); String code = "val x = staticMethod()"; SimpleEvaluationObject seo = KernelTest.createSeo(code); TryResult evaluate = evaluator.evaluate(seo, code); //then assertThat(evaluate.result()).isNull(); }
Example #2
Source File: BaseEvaluator.java From beakerx with Apache License 2.0 | 6 votes |
public BaseEvaluator(String id, String sId, CellExecutor cellExecutor, TempFolderFactory tempFolderFactory, EvaluatorParameters evaluatorParameters, BeakerXClient beakerXClient, MagicCommandAutocompletePatterns autocompletePatterns, ClasspathScanner classpathScanner) { shellId = id; sessionId = sId; executor = cellExecutor; tempFolder = tempFolderFactory.createTempFolder(); this.classpathScanner = classpathScanner; this.beakerXClient = BeakerXClientManager.register(beakerXClient); this.autocompletePatterns = autocompletePatterns; outDir = getOrCreateFile(tempFolder.toString() + File.separator + "outDir").getPath(); classPath = new Classpath(); classPath.add(new PathToJar(outDir)); inspect = new Inspect(); executorService = Executors.newCachedThreadPool(); executorBgkService = Executors.newCachedThreadPool(); this.evaluatorParameters = evaluatorParameters; init(evaluatorParameters); }
Example #3
Source File: GroovyEvaluatorTest.java From beakerx with Apache License 2.0 | 6 votes |
@BeforeClass public static void initClassStubData() throws IOException { GroovyDefaultVariables var = new GroovyDefaultVariables(); HashMap<String, Object> params = new HashMap<>(); params.put(IMPORTS, var.getImports()); params.put(CLASSPATH, var.getClassPath()); EvaluatorParameters kernelParameters = new EvaluatorParameters(params); GroovyEvaluator groovyEvaluator = new GroovyEvaluator("123", "345", cellExecutor(), getTestTempFolderFactory(), kernelParameters, new EvaluatorTest.BeakexClientTestImpl(), new MagicCommandAutocompletePatternsMock(), new ClasspathScannerMock()); groovyEvaluator.updateEvaluatorParameters(kernelParameters); groovyClassLoader = newEvaluator(groovyEvaluator.getImports(), groovyEvaluator.getClasspath(), groovyEvaluator.getOutDir(), icz, newParentClassLoader(groovyEvaluator.getClasspath())); scriptBinding = new Binding(); scriptBinding.setVariable("beaker", groovyEvaluator.getBeakerX()); groovyKernel = new GroovyKernelMock("groovyEvaluatorTest", groovyEvaluator); KernelManager.register(groovyKernel); }
Example #4
Source File: SymjaMMAEvaluator.java From symja_android_library with GNU General Public License v3.0 | 6 votes |
public SymjaMMAEvaluator(String id, String sId, CellExecutor cellExecutor, TempFolderFactory tempFolderFactory, EvaluatorParameters evaluatorParameters, BeakerXClient beakerxClient, MagicCommandAutocompletePatterns autocompletePatterns) { super(id, sId, cellExecutor, tempFolderFactory, evaluatorParameters, beakerxClient, autocompletePatterns); gac = createAutocomplete(autocompletePatterns); outDir = envVariablesFilter(outDir, System.getenv()); EvalEngine engine = new EvalEngine(false); fEvaluator = new ExprEvaluator(engine, false, 100); fEvaluator.getEvalEngine().setFileSystemEnabled(true); // DecimalFormatSymbols usSymbols = new DecimalFormatSymbols(Locale.US); // DecimalFormat decimalFormat = new DecimalFormat("0.0####", usSymbols); fOutputFactory = OutputFormFactory.get(false, false, 5, 7); fOutputTraditionalFactory = OutputFormFactory.get(true, false, 5, 7); fInputFactory = OutputFormFactory.get(false, false, 5, 7); fInputFactory.setQuotes(true); fUsedForm = TEXFORM; }
Example #5
Source File: SQLKernelWithoutDefaultJDBCUriTest.java From beakerx with Apache License 2.0 | 6 votes |
@Override protected Kernel createKernel(String sessionId, KernelSocketsFactory kernelSocketsFactory, CloseKernelAction closeKernelAction) { EvaluatorParameters kernelParameters = getKernelParameters(name -> null); MagicCommandConfigurationMock magicCommandConfiguration = new MagicCommandConfigurationMock(); SQLEvaluator sqlEvaluator = new SQLEvaluator(sessionId, sessionId, cellExecutor(), getTestTempFolderFactory(), kernelParameters, new EvaluatorTest.BeakexClientTestImpl(), magicCommandConfiguration.patterns(), new ClasspathScannerMock()); return new SQL(sessionId, sqlEvaluator, new Configuration( kernelSocketsFactory, closeKernelAction, getCacheFolderFactory(), new CustomMagicCommandsEmptyImpl(), new BeakerXCommRepositoryMock(), BeakerXServerMock.create(), magicCommandConfiguration, new KernelTest.BeakerXJsonMock(), new RuntimetoolsMock())); }
Example #6
Source File: SQL.java From beakerx with Apache License 2.0 | 6 votes |
public static void main(final String[] args) { KernelRunner.run(() -> { String id = uuid(); CommRepository commRepository = new BeakerXCommRepository(); KernelConfigurationFile configurationFile = new KernelConfigurationFile(args); KernelSocketsFactoryImpl kernelSocketsFactory = new KernelSocketsFactoryImpl( configurationFile); EvaluatorParameters params = getKernelParameters(BeakerXSystemImpl.getINSTANCE()); NamespaceClient beakerxClient = NamespaceClient.create(id, configurationFile, commRepository); DataSourceParamResolverImpl paramResolver = new DataSourceParamResolverImpl(beakerxClient); MagicCommandConfiguration magicConfiguration = new MagicCommandConfigurationImpl(); SQLEvaluator evaluator = new SQLEvaluator(id, id, params, beakerxClient, magicConfiguration.patterns(), new ClasspathScannerImpl()); return new SQL(id, evaluator, new Configuration( kernelSocketsFactory, new SQLCustomMagicCommandsImpl(paramResolver), commRepository, new SQLBeakerXServer(new GetUrlArgHandler(beakerxClient)), magicConfiguration, new BeakerXJsonConfig())); }); }
Example #7
Source File: ScalaEvaluatorTest.java From beakerx with Apache License 2.0 | 6 votes |
@Test public void javaImports_shouldBeAdjustedForScala() throws Exception { //given Map<String, Object> paramMap = new HashMap<>(); // This import tests both "static" removal and "object" escaping. List<String> imports = Arrays.asList( "import static com.twosigma.beakerx.scala.evaluator.object.ImportTestHelper.staticMethod"); paramMap.put(IMPORTS, imports); EvaluatorParameters kernelParameters = new EvaluatorParameters(paramMap); //when scalaEvaluator.updateEvaluatorParameters(kernelParameters); String code = "val x = staticMethod()"; SimpleEvaluationObject seo = KernelTest.createSeo(code); TryResult evaluate = scalaEvaluator.evaluate(seo, code); //then assertThat(evaluate.result()).isNull(); }
Example #8
Source File: JavaEvaluatorAutocompleteTest.java From beakerx with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUpClass() throws Exception { HashMap<String, Object> map = new HashMap<>(); map.put(IMPORTS, new JavaDefaultVariables().getImports()); EvaluatorParameters kernelParameters = new EvaluatorParameters(map); evaluator = new JavaEvaluator("id", "sid", cellExecutor(), getTestTempFolderFactory(), kernelParameters, new EvaluatorTest.BeakexClientTestImpl(), new MagicCommandAutocompletePatternsMock(), new ClasspathScannerImpl() ); waitUntilTheJShellIndexingFinishes(); }
Example #9
Source File: SQLEvaluator.java From beakerx with Apache License 2.0 | 5 votes |
protected void configureSqlEvaluator(EvaluatorParameters kernelParameters) { SQLKernelParameters params = new SQLKernelParameters(kernelParameters); jdbcClient = createJdbcClient(params.getClassPath()); jdbcClient.loadDrivers(classPath.getPathsAsStrings()); queryExecutor = new QueryExecutor(jdbcClient); if (params.defaultDatasource().isPresent()) { this.defaultConnectionString = new ConnectionStringHolder(params.defaultDatasource().orElse(""), jdbcClient); } if (params.datasources().isPresent()) { this.namedConnectionString = new HashMap<>(); Scanner sc = new Scanner(params.datasources().orElse("")); while (sc.hasNext()) { String line = sc.nextLine(); int i = line.indexOf('='); if (i < 1 || i == line.length() - 1) { logger.warn("Error in datasource line, this line will be ignored: {}.", line); continue; } String name = line.substring(0, i).trim(); String value = line.substring(i + 1).trim(); if (value.startsWith("\"") && value.endsWith("\"")) { value = value.substring(1, value.length() - 1); } namedConnectionString.put(name, new ConnectionStringHolder(value, jdbcClient)); } } }
Example #10
Source File: GroovyOutputContainerTest.java From beakerx with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { BaseEvaluator evaluator = TestGroovyEvaluator.groovyEvaluator(); groovyKernel = new KernelTest("GroovyOutputContainerTest", evaluator); this.evaluator = evaluator; evaluator.updateEvaluatorParameters(new EvaluatorParameters(new HashMap())); KernelManager.register(groovyKernel); }
Example #11
Source File: GroovyCompleteHandlerTest.java From beakerx with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUpClass() { GroovyEvaluator groovyEvaluator = new GroovyEvaluator( "id", "sid", cellExecutor(), EvaluatorTest.getTestTempFolderFactory(), new EvaluatorParameters(new HashedMap()), new EvaluatorTest.BeakexClientTestImpl(), new MagicCommandAutocompletePatternsMock(), new ClasspathScannerMock() ); groovyKernel = new GroovyKernelMock("sid", groovyEvaluator); }
Example #12
Source File: SQLEvaluator.java From beakerx with Apache License 2.0 | 5 votes |
public SQLEvaluator(String id, String sId, EvaluatorParameters evaluatorParameters, BeakerXClient beakerxClient, MagicCommandAutocompletePatterns autocompletePatterns, ClasspathScanner classpathScanner) { this(id, sId, new BeakerCellExecutor("sql"), new TempFolderFactoryImpl(), evaluatorParameters, beakerxClient, autocompletePatterns, classpathScanner); }
Example #13
Source File: SQLEvaluator.java From beakerx with Apache License 2.0 | 5 votes |
public SQLEvaluator(String id, String sId, CellExecutor cellExecutor, TempFolderFactory tempFolderFactory, EvaluatorParameters evaluatorParameters, BeakerXClient beakerxClient, MagicCommandAutocompletePatterns autocompletePatterns, ClasspathScanner classpathScanner) { super(id, sId, cellExecutor, tempFolderFactory, evaluatorParameters, beakerxClient, autocompletePatterns, classpathScanner); cps = new AutocompleteClasspathScanner(); sac = createSqlAutocomplete(cps); loader = reloadClassLoader(); executorService = Executors.newSingleThreadExecutor(); }
Example #14
Source File: KotlinEvaluator.java From beakerx with Apache License 2.0 | 5 votes |
public KotlinEvaluator(String id, String sId, CellExecutor cellExecutor, TempFolderFactory tempFolderFactory, EvaluatorParameters evaluatorParameters, BeakerXClient beakerxClient, MagicCommandAutocompletePatterns autocompletePatterns, com.twosigma.beakerx.evaluator.ClasspathScanner classpathScanner) { super(id, sId, cellExecutor, tempFolderFactory, evaluatorParameters, beakerxClient, autocompletePatterns, classpathScanner); cps = new AutocompleteClasspathScanner(); createRepl(); this.kotlinAutocomplete = new KotlinAutocomplete(autocompletePatterns); }
Example #15
Source File: GroovyEvaluator.java From beakerx with Apache License 2.0 | 5 votes |
public GroovyEvaluator(String id, String sId, CellExecutor cellExecutor, TempFolderFactory tempFolderFactory, EvaluatorParameters evaluatorParameters, BeakerXClient beakerxClient, MagicCommandAutocompletePatterns autocompletePatterns, ClasspathScanner classpathScanner) { super(id, sId, cellExecutor, tempFolderFactory, evaluatorParameters, beakerxClient, autocompletePatterns, classpathScanner); reloadClassloader(); gac = createGroovyAutocomplete(new GroovyClasspathScanner(), groovyClassLoader, imports, autocompletePatterns); outDir = envVariablesFilter(outDir, System.getenv()); }
Example #16
Source File: DataSourcesMagicCommand.java From beakerx with Apache License 2.0 | 5 votes |
protected MagicCommandOutcomeItem dataSource(String source, String command) { String[] parts = command.split(" "); if (parts.length != 2) { return new MagicCommandOutput(MagicCommandOutcomeItem.Status.ERROR, WRONG_FORMAT_MSG); } else if (!parts[1].contains("jdbc:")) { return new MagicCommandOutput(MagicCommandOutcomeItem.Status.ERROR, "Incorrect jdbc url."); } String jdbc = paramResolver.resolve(parts[1]); HashMap<String, Object> params = new HashMap<>(); params.put(source, jdbc); kernel.updateEvaluatorParameters(new EvaluatorParameters(params)); return new MagicCommandOutput(MagicCommandOutcomeItem.Status.OK); }
Example #17
Source File: KotlinEvaluator.java From beakerx with Apache License 2.0 | 5 votes |
public KotlinEvaluator(String id, String sId, EvaluatorParameters evaluatorParameters, BeakerXClient beakerxClient, MagicCommandAutocompletePatterns autocompletePatterns, com.twosigma.beakerx.evaluator.ClasspathScanner classpathScanner) { this(id, sId, new BeakerCellExecutor("kotlin"), new TempFolderFactoryImpl(), evaluatorParameters, beakerxClient, autocompletePatterns, classpathScanner); }
Example #18
Source File: SQLKernelWithDefaultEnvsTest.java From beakerx with Apache License 2.0 | 5 votes |
@Override protected Kernel createKernel(String sessionId, KernelSocketsFactory kernelSocketsFactory, CloseKernelAction closeKernelAction) { EvaluatorParameters kernelParameters = getKernelParameters(name -> { if (BEAKERX_SQL_DEFAULT_JDBC.equals(name)) { return "jdbc:h2:mem:db1"; } return null; }); MagicCommandConfigurationMock magicCommandConfiguration = new MagicCommandConfigurationMock(); SQLEvaluator sqlEvaluator = new SQLEvaluator( sessionId, sessionId, cellExecutor(), getTestTempFolderFactory(), kernelParameters, new EvaluatorTest.BeakexClientTestImpl(), magicCommandConfiguration.patterns(), new ClasspathScannerMock()); Kernel sqlKernel = new SQL(sessionId, sqlEvaluator, new Configuration( kernelSocketsFactory, closeKernelAction, getCacheFolderFactory(), new CustomMagicCommandsEmptyImpl(), new BeakerXCommRepositoryMock(), BeakerXServerMock.create(), magicCommandConfiguration, new KernelTest.BeakerXJsonMock(), new RuntimetoolsMock())); return sqlKernel; }
Example #19
Source File: SQLKernelWithDefaultEnvsTest.java From beakerx with Apache License 2.0 | 5 votes |
@Test public void incorrectlyFormattedJdbcUri() { //give //when EvaluatorParameters kernelParameters = getKernelParameters(name -> { if (BEAKERX_SQL_DEFAULT_JDBC.equals(name)) { return "jdb:h2:mem:db1"; } return null; }); //then assertThat(kernelParameters.getParams().containsKey(BEAKERX_SQL_DEFAULT_JDBC)).isFalse(); }
Example #20
Source File: SQLKernelWithDefaultEnvsTest.java From beakerx with Apache License 2.0 | 5 votes |
@Test public void noDefaultJdbc() { //give //when EvaluatorParameters kernelParameters = getKernelParameters(name -> null); //then assertThat(kernelParameters.getParams().containsKey(BEAKERX_SQL_DEFAULT_JDBC)).isFalse(); }
Example #21
Source File: GroovyEvaluator.java From beakerx with Apache License 2.0 | 5 votes |
public GroovyEvaluator(String id, String sId, EvaluatorParameters evaluatorParameters, BeakerXClient beakerxClient, MagicCommandAutocompletePatterns autocompletePatterns, ClasspathScanner classpathScanner) { this(id, sId, new BeakerCellExecutor("groovy"), new TempFolderFactoryImpl(), evaluatorParameters, beakerxClient, autocompletePatterns, classpathScanner); }
Example #22
Source File: EvaluatorTest.java From beakerx with Apache License 2.0 | 5 votes |
public EvaluatorTest(String id, String sId, CellExecutor cellExecutor, EvaluatorParameters kernelParameters, BeakerXClient beakerXClient) { super(id, sId, cellExecutor, getTestTempFolderFactory(), kernelParameters, beakerXClient, new MagicCommandAutocompletePatternsMock(), new ClasspathScannerMock()); }
Example #23
Source File: ClojureEvaluator.java From beakerx with Apache License 2.0 | 5 votes |
public ClojureEvaluator(String id, String sId, EvaluatorParameters evaluatorParameters, BeakerXClient beakerxClient, MagicCommandAutocompletePatterns autocompletePatterns,ClasspathScanner classpathScanner) { this(id, sId, new BeakerCellExecutor("clojure"), new TempFolderFactoryImpl(), evaluatorParameters, beakerxClient, autocompletePatterns, classpathScanner); }
Example #24
Source File: JavaEvaluator.java From beakerx with Apache License 2.0 | 5 votes |
public JavaEvaluator(String id, String sId, EvaluatorParameters evaluatorParameters, BeakerXClient beakerxClient, MagicCommandAutocompletePatterns autocompletePatterns, ClasspathScanner classpathScanner) { this(id, sId, new BeakerCellExecutor("java`"), new TempFolderFactoryImpl(), evaluatorParameters, beakerxClient, autocompletePatterns, classpathScanner); }
Example #25
Source File: JavaEvaluator.java From beakerx with Apache License 2.0 | 5 votes |
public JavaEvaluator(String id, String sId, CellExecutor cellExecutor, TempFolderFactory tempFolderFactory, EvaluatorParameters evaluatorParameters, BeakerXClient beakerxClient, MagicCommandAutocompletePatterns autocompletePatterns, ClasspathScanner classpathScanner) { super(id, sId, cellExecutor, tempFolderFactory, evaluatorParameters, beakerxClient, autocompletePatterns, classpathScanner); loader = newClassLoader(); jac = createJavaAutocomplete(); this.jshell = newJShell(); this.sourceCodeAnalysis = this.jshell.sourceCodeAnalysis(); }
Example #26
Source File: ClojureEvaluator.java From beakerx with Apache License 2.0 | 5 votes |
public ClojureEvaluator(String id, String sId, CellExecutor cellExecutor, TempFolderFactory tempFolderFactory, EvaluatorParameters evaluatorParameters, BeakerXClient beakerxClient, MagicCommandAutocompletePatterns autocompletePatterns, ClasspathScanner classpathScanner) { super(id, sId, cellExecutor, tempFolderFactory, evaluatorParameters, beakerxClient, autocompletePatterns,classpathScanner); requirements = new ArrayList<>(); init(); }
Example #27
Source File: JavaEvaluatorAutocompleteImportTest.java From beakerx with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUpClass() throws Exception { HashMap<String, Object> map = new HashMap<>(); map.put(IMPORTS, new JavaDefaultVariables().getImports()); EvaluatorParameters kernelParameters = new EvaluatorParameters(map); evaluator = new JavaEvaluator("id", "sid", cellExecutor(), getTestTempFolderFactory(), kernelParameters, new EvaluatorTest.BeakexClientTestImpl(), new MagicCommandAutocompletePatternsMock(), new ClasspathScannerMock() ); }
Example #28
Source File: ScalaEvaluator.java From beakerx with Apache License 2.0 | 5 votes |
public ScalaEvaluator(String id, String sId, CellExecutor cellExecutor, BeakerxObjectFactory beakerxObjectFactory, TempFolderFactory tempFolderFactory, EvaluatorParameters evaluatorParameters, BeakerXClient beakerxClient, MagicCommandAutocompletePatterns autocompletePatterns, ClasspathScanner classpathScanner) { super(id, sId, cellExecutor, tempFolderFactory, evaluatorParameters, beakerxClient, autocompletePatterns,classpathScanner); this.beakerxObjectFactory = beakerxObjectFactory; this.classLoader = newClassLoader(); this.shell = createNewEvaluator(); this.scalaAutocomplete = new ScalaAutocomplete(shell, autocompletePatterns); }
Example #29
Source File: KotlinEvaluatorTest.java From beakerx with Apache License 2.0 | 5 votes |
@Test public void evaluatePlot_shouldCreatePlotObject() throws Exception { //given Map<String, Object> paramMap = new HashMap<>(); paramMap.put(IMPORTS, asList("import com.twosigma.beakerx.chart.xychart.*")); evaluator.updateEvaluatorParameters(new EvaluatorParameters(paramMap)); String code = "val plot = Plot()\n" + "plot.setTitle(\"test title\");\n" + "plot.display();"; SimpleEvaluationObject seo = KernelTest.createSeo(code); //when TryResult evaluate = evaluator.evaluate(seo, code); //then assertThat(evaluate.result()).isNull(); }
Example #30
Source File: KernelFactoryFixtureSetup.java From beakerx with Apache License 2.0 | 4 votes |
private static EvaluatorParameters getKernelParameters() { HashMap<String, Object> kernelParameters = new HashMap<>(); return new EvaluatorParameters(kernelParameters); }