Search in sources :

Example 1 with ClasspathAddMvnMagicCommand

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))));
}
Also used : ClasspathAddMvnMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand) UnImportMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.UnImportMagicCommand) ClasspathAddRepoMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddRepoMagicCommand) AddImportMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.AddImportMagicCommand) HtmlAliasMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.HtmlAliasMagicCommand) HtmlMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.HtmlMagicCommand) TimeLineModeMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.TimeLineModeMagicCommand) TimeItLineModeMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.TimeItLineModeMagicCommand) JavaScriptMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.JavaScriptMagicCommand) TimeItCellModeMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.TimeItCellModeMagicCommand) LoadMagicMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.LoadMagicMagicCommand) AddStaticImportMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.AddStaticImportMagicCommand) BashMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.BashMagicCommand) ClassPathAddMvnCellMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClassPathAddMvnCellMagicCommand) MagicCommandType(com.twosigma.beakerx.kernel.magic.command.MagicCommandType) JSMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.JSMagicCommand) ClasspathShowMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathShowMagicCommand) TimeCellModeMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.TimeCellModeMagicCommand) ClasspathAddJarMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddJarMagicCommand) LsMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.LsMagicCommand)

Example 2 with ClasspathAddMvnMagicCommand

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");
}
Also used : ClasspathAddMvnMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand) Message(com.twosigma.beakerx.message.Message) ClasspathResetMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathResetMagicCommand) ClasspathAddMvnMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand) Code(com.twosigma.beakerx.kernel.Code) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 3 with ClasspathAddMvnMagicCommand

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());
}
Also used : ClasspathAddMvnMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand) Message(com.twosigma.beakerx.message.Message) ClasspathResetMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathResetMagicCommand) ClasspathResetMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathResetMagicCommand) ClasspathAddMvnMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand) Code(com.twosigma.beakerx.kernel.Code) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 4 with ClasspathAddMvnMagicCommand

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");
}
Also used : ClasspathAddMvnMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand) Message(com.twosigma.beakerx.message.Message) ClasspathResetMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathResetMagicCommand) ClasspathAddMvnMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand) Code(com.twosigma.beakerx.kernel.Code) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 5 with ClasspathAddMvnMagicCommand

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();
        }
    });
}
Also used : ClasspathAddMvnMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand) Path(java.nio.file.Path) CLASSPATH_RESET(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathResetMagicCommand.CLASSPATH_RESET) Enumeration(java.util.Enumeration) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest) After(org.junit.After) ZipFile(java.util.zip.ZipFile) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) ClasspathResetMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathResetMagicCommand) Before(org.junit.Before) Files(java.nio.file.Files) FileOutputStream(java.io.FileOutputStream) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) IOException(java.io.IOException) KernelTest(com.twosigma.beakerx.KernelTest) Message(com.twosigma.beakerx.message.Message) File(java.io.File) List(java.util.List) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) CLASSPATH_ADD_MVN(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand.CLASSPATH_ADD_MVN) ClasspathAddMvnMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand) EvaluatorResultTestWatcher(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher) Optional(java.util.Optional) ADD_MVN_FORMAT_ERROR_MESSAGE(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand.ADD_MVN_FORMAT_ERROR_MESSAGE) Assert(org.junit.Assert) Code(com.twosigma.beakerx.kernel.Code) MagicCommandOutcomeItem(com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutcomeItem) InputStream(java.io.InputStream) Message(com.twosigma.beakerx.message.Message) ClasspathResetMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathResetMagicCommand) ClasspathAddMvnMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand) IOException(java.io.IOException) Code(com.twosigma.beakerx.kernel.Code)

Aggregations

ClasspathAddMvnMagicCommand (com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand)6 KernelTest (com.twosigma.beakerx.KernelTest)4 EvaluatorTest (com.twosigma.beakerx.evaluator.EvaluatorTest)4 Code (com.twosigma.beakerx.kernel.Code)4 ClasspathResetMagicCommand (com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathResetMagicCommand)4 Message (com.twosigma.beakerx.message.Message)4 Test (org.junit.Test)4 EvaluatorResultTestWatcher (com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher)1 MagicCommandType (com.twosigma.beakerx.kernel.magic.command.MagicCommandType)1 AddImportMagicCommand (com.twosigma.beakerx.kernel.magic.command.functionality.AddImportMagicCommand)1 AddStaticImportMagicCommand (com.twosigma.beakerx.kernel.magic.command.functionality.AddStaticImportMagicCommand)1 BashMagicCommand (com.twosigma.beakerx.kernel.magic.command.functionality.BashMagicCommand)1 ClassPathAddMvnCellMagicCommand (com.twosigma.beakerx.kernel.magic.command.functionality.ClassPathAddMvnCellMagicCommand)1 ClasspathAddJarMagicCommand (com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddJarMagicCommand)1 ADD_MVN_FORMAT_ERROR_MESSAGE (com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand.ADD_MVN_FORMAT_ERROR_MESSAGE)1 CLASSPATH_ADD_MVN (com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand.CLASSPATH_ADD_MVN)1 ClasspathAddRepoMagicCommand (com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddRepoMagicCommand)1 CLASSPATH_RESET (com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathResetMagicCommand.CLASSPATH_RESET)1 ClasspathShowMagicCommand (com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathShowMagicCommand)1 HtmlAliasMagicCommand (com.twosigma.beakerx.kernel.magic.command.functionality.HtmlAliasMagicCommand)1