use of org.apache.sling.commons.compiler.JavaCompiler in project sling by apache.
the class SightlyJavaCompilerServiceTest method getInstancePojoTest.
private void getInstancePojoTest(String className) throws Exception {
RenderContextImpl renderContext = Mockito.mock(RenderContextImpl.class);
JavaCompiler javaCompiler = Mockito.mock(JavaCompiler.class);
CompilationResult compilationResult = Mockito.mock(CompilationResult.class);
when(compilationResult.getErrors()).thenReturn(new ArrayList<CompilerMessage>());
when(javaCompiler.compile(Mockito.any(CompilationUnit[].class), Mockito.any(Options.class))).thenReturn(compilationResult);
when(classLoaderWriter.getClassLoader().loadClass(className)).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return MockPojo.class;
}
});
Whitebox.setInternalState(compiler, "classLoaderWriter", classLoaderWriter);
Whitebox.setInternalState(compiler, "javaCompiler", javaCompiler);
Whitebox.setInternalState(compiler, "scriptingResourceResolverProvider", scriptingResourceResolverProvider);
Object obj = compiler.getResourceBackedUseObject(renderContext, className);
assertTrue("Expected to obtain a " + MockPojo.class.getName() + " object.", obj instanceof MockPojo);
}
use of org.apache.sling.commons.compiler.JavaCompiler in project sling by apache.
the class JspcMojo method initServletContext.
// ---------- Additional Settings ------------------------------------------
private void initServletContext() throws IOException, DependencyResolutionRequiredException {
if (loader == null) {
initClassLoader();
}
context = new JspCServletContext(getLog(), new URL("file:" + uriSourceRoot.replace('\\', '/') + '/'));
tldLocationsCache = new JspCTldLocationsCache(context, true, loader);
JavaCompiler compiler = new EclipseJavaCompiler();
ClassLoaderWriter writer = new JspCClassLoaderWriter(loader, new File(outputDirectory));
IOProvider ioProvider = new JspCIOProvider(loader, compiler, writer);
rctxt = new JspRuntimeContext(context, this, ioProvider);
jspConfig = new JspConfig(context);
tagPluginManager = new TagPluginManager(context);
}
Aggregations