Search in sources :

Example 6 with SourceFile

use of platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.SourceFile in project L42 by ElvisResearchGroup.

the class CompilationInMemoryTest method test1.

@Test
public void test1() throws Throwable {
    SourceFile file = new SourceFile("math.Calculator", "package math;" + "public class Calculator { " + "  public void testAdd() { " + "    System.out.println(200+300); " + "  }" + "  public static void main(String[] args) { " + "    Calculator cal = new Calculator(); " + "    cal.testAdd(); " + "  } " + "} ");
    List<SourceFile> files = Arrays.asList(file);
    ClassLoader classes = InMemoryJavaCompiler.compile(ClassLoader.getSystemClassLoader(), files);
    RunningUtils.runMain(classes, "math.Calculator");
    RunningUtils.runMainStrictSecurity(classes, "math.Calculator", 1000);
}
Also used : SourceFile(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.SourceFile) Test(org.junit.Test)

Example 7 with SourceFile

use of platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.SourceFile in project L42 by ElvisResearchGroup.

the class CompilationInMemoryTest method testExt.

@Test
public void testExt() throws Throwable {
    SourceFile file = new SourceFile("math.Calculator", "package math;" + "public class Calculator { " + "  public static void main(String[] args) { " + TestClass.class.getCanonicalName() + " cal = new " + TestClass.class.getCanonicalName() + "(); " + "    cal.testMeth(); " + "  } " + "} ");
    List<SourceFile> files = Arrays.asList(file);
    ClassLoader classes = InMemoryJavaCompiler.compile(ClassLoader.getSystemClassLoader(), files);
    RunningUtils.runMain(classes, "math.Calculator");
    RunningUtils.runMainStrictSecurity(classes, "math.Calculator", 1000);
}
Also used : SourceFile(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.SourceFile) Test(org.junit.Test)

Example 8 with SourceFile

use of platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.SourceFile in project L42 by ElvisResearchGroup.

the class CompilationInMemoryTest method test2bis.

@Test
public void test2bis() throws Throwable {
    SourceFile file = new SourceFile("math.Calculator", "package math;" + "public class Calculator { " + "  public static void main(String[] args) { " + "    Calculator2 cal = new Calculator2(); " + "    cal.testAdd(); " + "  } " + "} " + "class Calculator2 { " + "  public void testAdd() { " + "    System.out.println(200+300); " + "  }} ");
    List<SourceFile> files = Arrays.asList(file);
    ClassLoader classes = InMemoryJavaCompiler.compile(ClassLoader.getSystemClassLoader(), files);
    RunningUtils.runMain(classes, "math.Calculator");
    RunningUtils.runMainStrictSecurity(classes, "math.Calculator", 1000);
}
Also used : SourceFile(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.SourceFile) Test(org.junit.Test)

Example 9 with SourceFile

use of platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.SourceFile in project L42 by ElvisResearchGroup.

the class CompilationInMemoryTest method test2Files.

@Test
public void test2Files() throws Throwable {
    SourceFile[] file = { new SourceFile("math.Calculator", "package math;" + "class Calculator2 { " + "  public void testAdd() { " + "    System.out.println(200+300); " + "  }} "), new SourceFile("math.Calculator", "package math;" + "public class Calculator { " + "  public static void main(String[] args) { " + "    Calculator2 cal = new Calculator2(); " + "    cal.testAdd(); " + "  } " + "} ") };
    List<SourceFile> files = Arrays.asList(file);
    ClassLoader classes = InMemoryJavaCompiler.compile(ClassLoader.getSystemClassLoader(), files);
    RunningUtils.runMain(classes, "math.Calculator");
    RunningUtils.runMainStrictSecurity(classes, "math.Calculator", 1000);
}
Also used : SourceFile(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.SourceFile) Test(org.junit.Test)

Aggregations

SourceFile (platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.SourceFile)9 Test (org.junit.Test)8 MapClassLoader (platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.MapClassLoader)2 Method (java.lang.reflect.Method)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 ClassFile (platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.ClassFile)1 Facade (reduction.Facade)1