package reki;

import reki.shim.ReloadableRobot;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;

/**
 * Created by lidavidm on 2/10/16.
 */
public class RekiShim {
    public static void main(String[] args) {
        System.out.println("This is Reki!");

        ClassLoader loader = null;
        try {
            loader = new URLClassLoader(new URL[] {
                    new URL("file:////tmp/"),
            }, RekiShim.class.getClassLoader());
            Class robotClass = loader.loadClass("MyRobot");
            ReloadableRobot robot = (ReloadableRobot) robotClass.newInstance();
            robot.moveForward();
            robot.turnLeft();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
}

@@ -43,16 +43,185 @@
 Robot;%0A%0A
+import javax.lang.model.SourceVersion;%0Aimport javax.tools.*;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.io.OutputStream;%0Aimport java.io.Writer;%0A
 import j
@@ -243,32 +243,53 @@
 edURLException;%0A
+import java.net.URI;%0A
 import java.net.
@@ -329,215 +329,1772 @@
 er;%0A
-%0A/**%0A * Created by lidavidm on 2/10/16.%0A */%0Apublic class RekiShim %7B%0A    public static void main(String%5B%5D args) %7B%0A        System.out.println(%22This is Reki!%22);%0A%0A        ClassLoader loader = null;%0A        try %7B
+import java.nio.charset.Charset;%0Aimport java.nio.file.Files;%0Aimport java.nio.file.Paths;%0Aimport java.util.Arrays;%0Aimport java.util.Collections;%0Aimport java.util.Locale;%0Aimport java.util.Set;%0A%0A/**%0A * Created by lidavidm on 2/10/16.%0A */%0Apublic class RekiShim %7B%0A    static class StringFileObject extends SimpleJavaFileObject %7B%0A        private final String source;%0A%0A        protected StringFileObject(String name, String source) %7B%0A            super(URI.create(%22string:///%22 + name + Kind.SOURCE.extension), Kind.SOURCE);%0A            this.source = source;%0A        %7D%0A%0A        @Override%0A        public CharSequence getCharContent(boolean b) throws IOException %7B%0A            return this.source;%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        System.out.println(%22This is Reki!%22);%0A%0A        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();%0A        String%5B%5D options = new String%5B%5D%7B%0A                %22-cp%22, %22/tmp/server_prototype.jar%22,%0A                %22-sourcepath%22, %22/tmp%22,%0A                %22-d%22, %22/tmp%22,%0A        %7D;%0A%0A        try %7B%0A            StringFileObject code = new StringFileObject(%22MyRobot%22,%0A                    new String(Files.readAllBytes(Paths.get(%22/home/lidavidm/Code/cornell/cs6360/server_prototype/sample/MyRobot.java%22))));%0A            JavaCompiler.CompilationTask task = compiler.getTask(null, null, null,%0A                    Arrays.asList(options),%0A                    null,%0A                    Collections.singletonList(code)%0A            );%0A            if (task.call()) %7B%0A%0A            %7D%0A            else %7B%0A                System.err.println(%22Could not compile!%22);%0A                return;%0A            %7D%0A        %7D catch (IOException e) %7B%0A            e.printStackTrace();%0A        %7D%0A%0A%0A        try %7B%0A            ClassLoader loader;
 %0A   
@@ -2139,17 +2139,16 @@
 ew URL%5B%5D
- 
 %7B%0A      

Implement dynamic compilation