use of com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput in project beakerx by twosigma.
the class ClasspathAddDynamicMagicCommand method execute.
@Override
public MagicCommandOutcomeItem execute(MagicCommandExecutionParam param) {
String command = param.getCommand();
String[] split = splitPath(command);
if (split.length < 4) {
return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, WRONG_FORMAT_MSG + CLASSPATH_ADD_DYNAMIC);
}
String codeToExecute = command.substring(command.indexOf(DYNAMIC) + DYNAMIC.length()).trim();
SimpleEvaluationObject seo = createSimpleEvaluationObject(codeToExecute, kernel, param.getCode().getMessage(), param.getExecutionCount());
TryResult either = kernel.executeCode(codeToExecute, seo);
if (either.isResult()) {
try {
Collection<String> newAddedJars = addJars(either.result());
if (newAddedJars.isEmpty()) {
return new MagicCommandOutput(MagicCommandOutput.Status.OK);
}
String textMessage = "Added jar" + (newAddedJars.size() > 1 ? "s: " : ": ") + newAddedJars;
return new MagicCommandOutput(MagicCommandOutput.Status.OK, textMessage);
} catch (Exception e) {
return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, "There occurs problem during execution of " + CLASSPATH_ADD_DYNAMIC + " : " + e.getMessage());
}
} else {
return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, "There occurs problem during execution of " + CLASSPATH_ADD_DYNAMIC + " : " + either.error());
}
}
use of com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput in project beakerx by twosigma.
the class ClasspathAddMvnMagicCommand method execute.
@Override
public MagicCommandOutcomeItem execute(MagicCommandExecutionParam param) {
String command = param.getCommand();
String[] split = MagicCommandUtils.splitPath(command);
if (!(isGradleFormat(split) || isMavenFormat(split))) {
return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, ADD_MVN_FORMAT_ERROR_MESSAGE);
}
commandParams.setRepos(getRepos().get());
MavenJarResolver classpathAddMvnCommand = new MavenJarResolver(commandParams, pomFactory);
MvnLoggerWidget progress = new MvnLoggerWidget(param.getCode().getMessage());
AddMvnCommandResult result = retrieve(getDependency(split), classpathAddMvnCommand, progress);
if (result.isJarRetrieved()) {
return handleAddedJars(classpathAddMvnCommand.getPathToMavenRepo() + "/*");
}
return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, result.getErrorMessage());
}
use of com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput in project beakerx by twosigma.
the class ClasspathResetMagicCommand method execute.
@Override
public MagicCommandOutcomeItem execute(MagicCommandExecutionParam param) {
String command = param.getCommand();
String[] split = splitPath(command);
if (split.length != 2) {
return new MagicCommandOutput(Status.ERROR, WRONG_FORMAT_MSG + CLASSPATH_RESET);
}
ClasspathAddMvnMagicCommand mvnMagicCommand = MagicCommandTypesFactory.getClasspathAddMvnMagicCommand(kernel);
mvnMagicCommand.resetRepo();
try {
FileUtils.deleteQuietly(new File(mvnMagicCommand.getCommandParams().getPathToCache()));
FileUtils.deleteQuietly(new File(mvnMagicCommand.getCommandParams().getPathToNotebookJars()));
} catch (Exception e) {
return new MagicCommandOutput(Status.ERROR, e.getMessage());
}
return new MagicCommandOutput(Status.OK, "Reset done, please restart the kernel.");
}
use of com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput in project beakerx by twosigma.
the class LoadMagicMagicCommand method execute.
@Override
public MagicCommandOutcomeItem execute(MagicCommandExecutionParam param) {
String command = param.getCommand();
String[] split = splitPath(command);
if (split.length != 2) {
return new MagicCommandOutput(ERROR, WRONG_FORMAT_MSG + LOAD_MAGIC);
}
String clazzName = split[1];
try {
Class<?> aClass = this.kernel.loadClass(clazzName);
Object instance = aClass.newInstance();
if (instance instanceof MagicCommandFunctionality) {
MagicCommandFunctionality commandFunctionality = (MagicCommandFunctionality) instance;
kernel.registerMagicCommandType(new MagicCommandType(commandFunctionality.getMagicCommandName(), "", commandFunctionality));
return new MagicCommandOutput(OK, "Magic command " + commandFunctionality.getMagicCommandName() + " was successfully added.");
} else {
return new MagicCommandOutput(ERROR, "Magic command have to implement " + MagicCommandFunctionality.class + " interface.");
}
} catch (Exception e) {
return new MagicCommandOutput(ERROR, e.toString());
}
}
Aggregations