public Compiler assertCompile() { try { strategy.compile(); ArrayList<URL> urls = new ArrayList<URL>(); urls.add(strategy.classOutput.getURL()); Iterator<ReadFileSystem<?>> i = strategy.classPath.iterator(); // Skip the first one that is the context classloader i.next(); while (i.hasNext()) { urls.add(i.next().getURL()); } classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), Thread.currentThread().getContextClassLoader()); return strategy.compiler; } catch (Exception e) { throw AbstractTestCase.failure(e); } }
public Compiler assertCompile() { try { strategy.compile(); ArrayList<URL> urls = new ArrayList<URL>(); urls.add(strategy.classOutput.getURL()); Iterator<ReadFileSystem<?>> i = strategy.classPath.iterator(); // Skip the first one that is the context classloader i.next(); while (i.hasNext()) { urls.add(i.next().getURL()); } classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), Thread.currentThread().getContextClassLoader()); return strategy.compiler; } catch (Exception e) { throw AbstractTestCase.failure(e); } }
@Test public void testGenerateBundle() throws Exception { CompilerAssert<File, File> compilerAssert = compiler("examples.app1"); //<1> compilerAssert.assertCompile(); //<2> ReadWriteFileSystem<File> output = compilerAssert.getClassOutput(); //<3> ClassLoader loader = new URLClassLoader(new URL[]{ output.getURL() }); //<4> Class<?> bundleClass = loader.loadClass("examples.app1.mybundle"); //<5> Method m = bundleClass.getDeclaredMethod("abc"); //<6> assertEquals(String.class, m.getReturnType()); } // end::testGenerateBundle[]
void init() { if (local == null) try { compilerAssert1.assertCompile(); compilerAssert2.assertCompile(); parent = new URLClassLoader(new URL[]{compilerAssert1.getClassOutput().getURL()}); local = new LiveClassLoader(new URL[]{compilerAssert2.getClassOutput().getURL()}, parent); } catch (IOException e) { throw failure(e); } }
void init() { if (local == null) try { compilerAssert1.assertCompile(); compilerAssert2.assertCompile(); parent = new URLClassLoader(new URL[]{compilerAssert1.getClassOutput().getURL()}); local = new LiveClassLoader(new URL[]{compilerAssert2.getClassOutput().getURL()}, parent); } catch (IOException e) { throw failure(e); } }