use of com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand in project beakerx by twosigma.
the class KernelTest method initMagicCommands.
private void initMagicCommands() {
this.magicCommandTypes = new ArrayList<>();
this.magicCommandTypes.addAll(Lists.newArrayList(new MagicCommandType(JavaScriptMagicCommand.JAVASCRIPT, "", new JavaScriptMagicCommand()), new MagicCommandType(JSMagicCommand.JAVASCRIPT, "", new JSMagicCommand()), new MagicCommandType(HtmlMagicCommand.HTML, "", new HtmlMagicCommand()), new MagicCommandType(HtmlAliasMagicCommand.HTML, "", new HtmlAliasMagicCommand()), new MagicCommandType(BashMagicCommand.BASH, "", new BashMagicCommand()), new MagicCommandType(LsMagicCommand.LSMAGIC, "", new LsMagicCommand(this.magicCommandTypes)), new MagicCommandType(ClasspathAddRepoMagicCommand.CLASSPATH_CONFIG_RESOLVER, "repoName repoURL", new ClasspathAddRepoMagicCommand(this)), new MagicCommandType(ClasspathAddJarMagicCommand.CLASSPATH_ADD_JAR, "<jar path>", new ClasspathAddJarMagicCommand(this)), new MagicCommandType(ClasspathAddMvnMagicCommand.CLASSPATH_ADD_MVN, "<group name version>", new ClasspathAddMvnMagicCommand(mavenResolverParam, this)), new MagicCommandType(ClassPathAddMvnCellMagicCommand.CLASSPATH_ADD_MVN_CELL, "<group name version>", new ClassPathAddMvnCellMagicCommand(mavenResolverParam, this)), addClasspathReset(this), addDynamic(this), addMagicCommandWhichThrowsException(), new MagicCommandType(ClasspathShowMagicCommand.CLASSPATH_SHOW, "", new ClasspathShowMagicCommand(this)), new MagicCommandType(AddStaticImportMagicCommand.ADD_STATIC_IMPORT, "<classpath>", new AddStaticImportMagicCommand(this)), new MagicCommandType(AddImportMagicCommand.IMPORT, "<classpath>", new AddImportMagicCommand(this)), new MagicCommandType(UnImportMagicCommand.UNIMPORT, "<classpath>", new UnImportMagicCommand(this)), new MagicCommandType(TimeLineModeMagicCommand.TIME_LINE, "", new TimeLineModeMagicCommand(this)), new MagicCommandType(TimeCellModeMagicCommand.TIME_CELL, "", new TimeCellModeMagicCommand(this)), new MagicCommandType(TimeItLineModeMagicCommand.TIMEIT_LINE, "", new TimeItLineModeMagicCommand(this)), new MagicCommandType(TimeItCellModeMagicCommand.TIMEIT_CELL, "", new TimeItCellModeMagicCommand(this)), new MagicCommandType(LoadMagicMagicCommand.LOAD_MAGIC, "", new LoadMagicMagicCommand(this))));
}
use of com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand in project beakerx by twosigma.
the class ClasspathAddMvnDepsMagicCommandTest method unresolvedDependency.
@Test
public void unresolvedDependency() {
// given
String allCode = CLASSPATH_ADD_MVN + " com.google.code.XXXX gson 2.6.2";
MagicCommand command = new MagicCommand(new ClasspathAddMvnMagicCommand(kernel.mavenResolverParam, kernel), allCode);
Code code = Code.createCode(allCode, singletonList(command), NO_ERRORS, new Message());
// when
code.execute(kernel, 1);
// then
List<Message> stderr = EvaluatorResultTestWatcher.getStderr(kernel.getPublishedMessages());
String text = (String) stderr.get(0).getContent().get("text");
assertThat(text).contains("Could not resolve dependencies for:");
assertThat(text).contains("com.google.code.XXXX : gson : 2.6.2");
}
use of com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand in project beakerx by twosigma.
the class ClasspathAddMvnDepsMagicCommandTest method handleClasspathReset.
@Test
public void handleClasspathReset() throws Exception {
// given
String allCode = CLASSPATH_ADD_MVN + " com.google.code.gson:gson:2.6.2";
handleClasspathAddMvnDep(allCode, "gson-2.6.2.jar");
kernel.clearMessages();
ClasspathAddMvnMagicCommand mvnMagicCommand = MagicCommandTypesFactory.getClasspathAddMvnMagicCommand(kernel);
mvnMagicCommand.addRepo("jcenter", "jcenter");
// when
String resetCode = CLASSPATH_RESET;
ClasspathResetMagicCommand resetMagicCommand = MagicCommandTypesFactory.getClasspathResetMagicCommand(kernel);
MagicCommand command = new MagicCommand(resetMagicCommand, resetCode);
Code code = Code.createCode(resetCode, singletonList(command), NO_ERRORS, new Message());
code.execute(kernel, 1);
// then
List<Message> stderr = EvaluatorResultTestWatcher.getStdouts(kernel.getPublishedMessages());
String text = (String) stderr.get(0).getContent().get("text");
assertThat(text).contains("Reset done");
boolean cache = Files.exists(Paths.get(mvnMagicCommand.getCommandParams().getPathToCache()));
Assert.assertFalse(cache);
boolean jars = Files.exists(Paths.get(mvnMagicCommand.getCommandParams().getPathToNotebookJars()));
Assert.assertFalse(jars);
Assert.assertTrue(mvnMagicCommand.getRepos().get().isEmpty());
}
use of com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand in project beakerx by twosigma.
the class ClasspathAddMvnDepsMagicCommandTest method wrongCommandFormat.
@Test
public void wrongCommandFormat() {
// given
String allCode = CLASSPATH_ADD_MVN + " com.google.code.XXXX gson";
MagicCommand command = new MagicCommand(new ClasspathAddMvnMagicCommand(kernel.mavenResolverParam, kernel), allCode);
Code code = Code.createCode(allCode, singletonList(command), NO_ERRORS, new Message());
// when
code.execute(kernel, 1);
// then
List<Message> stderr = EvaluatorResultTestWatcher.getStderr(kernel.getPublishedMessages());
String text = (String) stderr.get(0).getContent().get("text");
assertThat(text).contains(ADD_MVN_FORMAT_ERROR_MESSAGE + "\n");
}
use of com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand in project beakerx by twosigma.
the class ClasspathAddMvnDepsMagicCommandTest method handleClasspathAddMvnDep.
private void handleClasspathAddMvnDep(String allCode, String expected) throws IOException {
MagicCommand command = new MagicCommand(new ClasspathAddMvnMagicCommand(kernel.mavenResolverParam, kernel), allCode);
Code code = Code.createCode(allCode, singletonList(command), NO_ERRORS, new Message());
// when
code.execute(kernel, 1);
// then
List<Message> stderr = EvaluatorResultTestWatcher.getStdouts(kernel.getPublishedMessages());
String text = (String) stderr.get(0).getContent().get("text");
assertThat(text).contains("Added jar");
assertThat(text).contains(expected);
String mvnDir = kernel.getTempFolder().toString() + MavenJarResolver.MVN_DIR;
Stream<Path> paths = Files.walk(Paths.get(mvnDir));
Optional<Path> dep = paths.filter(file -> (file.getFileName().toFile().getName().contains("gson") || file.getFileName().toFile().getName().contains("slf4j"))).findFirst();
assertThat(dep).isPresent();
assertThat(kernel.getClasspath().get(0)).contains(mvnDir);
dep.ifPresent(path -> {
try {
FileUtils.forceDelete(path.toFile());
} catch (IOException e) {
e.printStackTrace();
}
});
}
Aggregations