public CommandInvoker<C, P> getInvoker() throws CommandException { final T command = baseShellCommand.createCommand(); return getInvoker(command); }
public void open(CommandContext<? super P> consumer) throws CommandException { // Java is fine with that but not intellij.... CommandContext<P> consumer2 = (CommandContext<P>)consumer; open2(consumer2); }
protected Completer getCompleter(final RuntimeContext context) throws CommandException { final T command = createCommand(); if (command instanceof Completer) { command.context = context; return (Completer)command; } else { return null; } }
public void testCompile() throws Exception { Compiler compiler = new Compiler(); List<JavaClassFileObject> files = compiler.compile("A", "public class A implements java.util.concurrent.Callable<String> {\n" + "public String call() {\n" + "return \"hello\";\n" + "}\n" + "}"); assertEquals(1, files.size()); LoadingClassLoader loader = new LoadingClassLoader(Thread.currentThread().getContextClassLoader(), files); Class<?> A = loader.findClass("A"); Callable<String> asCallable = (Callable<String>)A.newInstance(); String ret = asCallable.call(); assertEquals("hello", ret); }
public void testCompilationFailure() throws Exception { Compiler compiler = new Compiler(); try { compiler.compile("foo.A", "package foo;\n public class A {"); } catch (CompilationFailureException e) { List<Diagnostic<? extends JavaFileObject>> errors = e.getErrors(); assertEquals(1, errors.size()); Diagnostic<? extends JavaFileObject> error = errors.get(0); assertEndsWith("/foo/A.java", error.getSource().getName()); } } }
LoadingClassLoader(ClassLoader parent, Iterable<JavaClassFileObject> files) { super(parent); // HashMap<String, byte[]> definitions = new HashMap<String,byte[]>(); for (JavaClassFileObject definition : files) { definitions.put(definition.getClassName(), definition.getBytes()); } // this.definitions = definitions; this.classes = new HashMap<String, Class<?>>(); }
@Override public void init() { compiler = new JavaCompiler(getContext().getLoader()); }
private <C extends BaseCommand> ClassShellCommand<C> make(Class<C> clazz) throws IntrospectionException { return new ClassShellCommand<C>(clazz); }
JavaCompiler(ClassLoader loader) { this.compiler = new org.crsh.lang.impl.java.Compiler(loader); this.loader = loader; }
@Override public void destroy(ShellSession session) { compiler.destroy(session); } }
public void open(CommandContext<? super P> consumer) { // Java is fine with that but not intellij.... CommandContext<P> consumer2 = (CommandContext<P>)consumer; open2(consumer2); }
@Override public void init(ShellSession session) { compiler.init(session); }
private <C, P, PC extends Pipe<C, P>> CommandMatch<C, P> getPipeInvoker(final org.crsh.cli.impl.invocation.CommandInvoker<Instance<T>, PC> invoker) { return new PipeCommandMatch<T, C, P, PC>(this, invoker); }
private <P> CommandMatch<Void, P> getProducerInvoker(final org.crsh.cli.impl.invocation.CommandInvoker<Instance<T>, ?> invoker, final Class<P> producedType) { return new ProducerCommandMatch<T, P>(this, invoker, producedType); }
public ProducerCommandMatch(ClassShellCommand<T> shellCommand, CommandInvoker<Instance<T>, ?> invoker, Class<P> producedType) { super(shellCommand); // this.invoker = invoker; this.producedType = producedType; this.name = shellCommand.getDescriptor().getName(); }
public void testSimple() throws Exception { assertEquals("hello", assertOk("java_command")); assertEquals("def", groovyShell.getVariable("abc")); }
public void testImportFromJar() throws Exception { doTestImport(new ClassLoaderFactory() { @Override public ClassLoader getClassLoader(JavaArchive jar) throws Exception { File tmp = File.createTempFile("crash", ".jar"); assertTrue(tmp.delete()); jar.as(ZipExporter.class).exportTo(tmp); return new URLClassLoader(new URL[]{tmp.toURI().toURL()}); } }); }
public void testCompilationFailure() { lifeCycle.bindJava("foo", "public class foo extends BaseCommand {}"); assertInternalError("foo"); }
public <B extends BaseCommand> String execute(Class<B> commandClass, String... args) throws IntrospectionException, IOException, CommandException { return execute(new ClassShellCommand<B>(commandClass), args); }
public void testImportFromFolder() throws Exception { doTestImport(new ClassLoaderFactory() { @Override public ClassLoader getClassLoader(JavaArchive jar) throws Exception { File tmp = File.createTempFile("root", "tmp"); assertTrue(tmp.delete()); assertTrue(tmp.mkdir()); tmp.deleteOnExit(); jar.as(ExplodedExporter.class).exportExploded(tmp, "root"); URL url = new File(tmp, "root").toURI().toURL(); return new URLClassLoader(new URL[]{url}); } }); }