use of com.twosigma.beakerx.kernel.PathToJar in project beakerx by twosigma.
the class ClasspathMagicCommandTest method showClasspath.
@Test
public void showClasspath() {
// given
kernel.addJarsToClasspath(asList(new PathToJar(CLASSPATH_TO_JAR_PATH)));
Code code = CodeFactory.create("%classpath", new Message(), kernel);
// when
code.execute(kernel, 1);
// then
List<Message> std = EvaluatorResultTestWatcher.getStdouts(kernel.getPublishedMessages());
String text = (String) std.get(0).getContent().get("text");
assertThat(text).contains(FOO_JAR);
}
use of com.twosigma.beakerx.kernel.PathToJar in project beakerx by twosigma.
the class SQLEvaluator method configureSqlEvaluator.
protected void configureSqlEvaluator(EvaluatorParameters kernelParameters) {
SQLKernelParameters params = new SQLKernelParameters(kernelParameters);
Optional<Collection<String>> cp = params.getClassPath();
if (cp.isPresent()) {
if (cp.get() == null || cp.get().isEmpty()) {
classPath = new Classpath();
} else {
for (String line : cp.get()) {
if (!line.trim().isEmpty()) {
classPath.add(new PathToJar(line));
}
}
}
jdbcClient.loadDrivers(classPath.getPathsAsStrings());
}
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));
}
}
}
use of com.twosigma.beakerx.kernel.PathToJar in project beakerx by twosigma.
the class ClasspathMagicCommandTest method showClasspathShouldNotContainDuplication.
@Test
public void showClasspathShouldNotContainDuplication() throws Exception {
// given
kernel.addJarsToClasspath(asList(new PathToJar(CLASSPATH_TO_JAR_PATH)));
kernel.clearMessages();
// when
kernel.addJarsToClasspath(asList(new PathToJar(CLASSPATH_TO_JAR_PATH)));
Code code = CodeFactory.create("%classpath", new Message(), kernel);
code.execute(kernel, 1);
// then
List<Message> std = EvaluatorResultTestWatcher.getStdouts(kernel.getPublishedMessages());
String text = (String) std.get(0).getContent().get("text");
assertThat(text).contains(FOO_JAR);
}
use of com.twosigma.beakerx.kernel.PathToJar in project beakerx by twosigma.
the class ClasspathMagicCommand method handlePath.
private Collection<String> handlePath(String path) {
List<String> addedJarsName = Lists.newLinkedList();
Path currentPath = Paths.get(path);
List<Path> paths = this.kernel.addJarsToClasspath(singletonList(new PathToJar(path)));
if (!paths.isEmpty()) {
addedJarsName.add(currentPath.getFileName().toString());
}
return addedJarsName;
}
use of com.twosigma.beakerx.kernel.PathToJar in project beakerx by twosigma.
the class GroovyEvaluatorMagicCommandsTest method addJarToClasspath.
@Test
public void addJarToClasspath() throws Exception {
// given
String code = "" + "import com.example.Demo;\n" + "Demo demo = new Demo();\n" + "demo.getObjectTest()\n";
TryResult seo = runCode(code);
assertThat(seo.error()).contains("unable to resolve class");
// when
PathToJar path = new PathToJar(SRC_TEST_RESOURCES + "demo.jar");
groovyEvaluator.addJarsToClasspath(singletonList(path));
// then
TryResult seo2 = runCode(code);
assertThat(seo2.result()).isEqualTo("Demo_test_123");
}
Aggregations