use of org.drools.wiring.api.classloader.ProjectClassLoader in project drools by kiegroup.
the class HasKnowledgeBuilderImpl method compileAndLoadClass.
/**
* Compile the given sources and add them to given <code>Classloader</code> of the current instance.
* Returns the <code>Class</code> with the given <b>fullClassName</b>
* @param sourcesMap
* @param fullClassName
* @return
*/
@Override
public Class<?> compileAndLoadClass(Map<String, String> sourcesMap, String fullClassName) {
ClassLoader classLoader = getClassLoader();
if (!(classLoader instanceof ProjectClassLoader)) {
throw new IllegalStateException("Expected ProjectClassLoader, received " + classLoader.getClass().getName());
}
ProjectClassLoader projectClassLoader = (ProjectClassLoader) classLoader;
final Map<String, byte[]> byteCode = KieMemoryCompiler.compileNoLoad(sourcesMap, projectClassLoader, JavaConfiguration.CompilerType.ECLIPSE);
byteCode.forEach(projectClassLoader::defineClass);
try {
return projectClassLoader.loadClass(fullClassName);
} catch (Exception e) {
throw new KiePMMLException(e);
}
}
use of org.drools.wiring.api.classloader.ProjectClassLoader in project drools by kiegroup.
the class HasKnowledgeBuilderMock method compileAndLoadClass.
@Override
public Class<?> compileAndLoadClass(Map<String, String> sourcesMap, String fullClassName) {
ClassLoader classLoader = getClassLoader();
if (!(classLoader instanceof ProjectClassLoader)) {
throw new IllegalStateException("Expected ProjectClassLoader, received " + classLoader.getClass().getName());
}
ProjectClassLoader projectClassLoader = (ProjectClassLoader) classLoader;
final Map<String, byte[]> byteCode = KieMemoryCompiler.compileNoLoad(sourcesMap, projectClassLoader);
byteCode.forEach(projectClassLoader::defineClass);
try {
return projectClassLoader.loadClass(fullClassName);
} catch (Exception e) {
throw new KiePMMLException(e);
}
}
use of org.drools.wiring.api.classloader.ProjectClassLoader in project drools by kiegroup.
the class HasKnowledgeBuilderMock method compileAndLoadClass.
@Override
public Class<?> compileAndLoadClass(Map<String, String> sourcesMap, String fullClassName) {
ClassLoader classLoader = getClassLoader();
if (!(classLoader instanceof ProjectClassLoader)) {
throw new IllegalStateException("Expected ProjectClassLoader, received " + classLoader.getClass().getName());
}
ProjectClassLoader projectClassLoader = (ProjectClassLoader) classLoader;
final Map<String, byte[]> byteCode = KieMemoryCompiler.compileNoLoad(sourcesMap, projectClassLoader);
byteCode.forEach(projectClassLoader::defineClass);
try {
return projectClassLoader.loadClass(fullClassName);
} catch (Exception e) {
throw new KiePMMLException(e);
}
}
use of org.drools.wiring.api.classloader.ProjectClassLoader in project drools by kiegroup.
the class HasKnowledgeBuilderMock method compileAndLoadClass.
@Override
public Class<?> compileAndLoadClass(Map<String, String> sourcesMap, String fullClassName) {
ClassLoader classLoader = getClassLoader();
if (!(classLoader instanceof ProjectClassLoader)) {
throw new IllegalStateException("Expected ProjectClassLoader, received " + classLoader.getClass().getName());
}
ProjectClassLoader projectClassLoader = (ProjectClassLoader) classLoader;
final Map<String, byte[]> byteCode = KieMemoryCompiler.compileNoLoad(sourcesMap, projectClassLoader);
byteCode.forEach(projectClassLoader::defineClass);
try {
return projectClassLoader.loadClass(fullClassName);
} catch (Exception e) {
throw new KiePMMLException(e);
}
}
use of org.drools.wiring.api.classloader.ProjectClassLoader in project drools by kiegroup.
the class GeneratedClassNamesTest method testModuleWithDepWithClassLoader.
@Test
public void testModuleWithDepWithClassLoader() throws Exception {
ProjectClassLoader projectClassLoader = ProjectClassLoader.createProjectClassLoader(Thread.currentThread().getContextClassLoader());
testModuleWithDep(projectClassLoader);
}
Aggregations