use of org.kie.memorycompiler.resources.MemoryResourceStore in project drools by kiegroup.
the class JavaCompilerI18NTest method testi18NFile.
@Test
public void testi18NFile() throws Exception {
String fileStr = "com/myspace/test/あ.java";
List<String> classes = new ArrayList<>();
classes.add(fileStr);
MemoryResourceReader reader = new MemoryResourceReader();
MemoryResourceStore store = new MemoryResourceStore();
String fileContents = "package com.myspace.test; public class あ { }";
reader.add(fileStr, fileContents.getBytes());
EclipseJavaCompilerSettings settings = new EclipseJavaCompilerSettings();
settings.setSourceVersion("1.5");
settings.setTargetVersion("1.5");
EclipseJavaCompiler compiler = new EclipseJavaCompiler(settings, "");
CompilationResult res = compiler.compile(classes.toArray(new String[classes.size()]), reader, store);
assertEquals(res.getErrors().length, 0);
}
use of org.kie.memorycompiler.resources.MemoryResourceStore in project drools by kiegroup.
the class KieMemoryCompiler method compileNoLoad.
/**
* Compile the given sources and returns the generated byte codes.
* Additional compiler settings can be provided using JavaCompilerSettings
*
* @param classNameSourceMap
* @param classLoader
* @param compilerSettings
* @return
*/
public static Map<String, byte[]> compileNoLoad(Map<String, String> classNameSourceMap, ClassLoader classLoader, JavaCompilerSettings compilerSettings, JavaConfiguration.CompilerType compilerType) {
MemoryResourceReader reader = new MemoryResourceReader();
MemoryResourceStore store = new MemoryResourceStore();
String[] classNames = new String[classNameSourceMap.size()];
int i = 0;
for (Map.Entry<String, String> entry : classNameSourceMap.entrySet()) {
classNames[i] = toJavaSource(entry.getKey());
reader.add(classNames[i], entry.getValue().getBytes());
i++;
}
JavaConfiguration javaConfiguration = new JavaConfiguration();
javaConfiguration.setCompiler(compilerType);
javaConfiguration.setJavaLanguageLevel(findJavaVersion());
JavaCompiler compiler = JavaCompilerFactory.loadCompiler(javaConfiguration);
CompilationResult res = compilerSettings == null ? compiler.compile(classNames, reader, store, classLoader) : compiler.compile(classNames, reader, store, classLoader, compilerSettings);
if (res.getErrors().length > 0) {
throw new KieMemoryCompilerException(Arrays.toString(res.getErrors()));
}
Map<String, byte[]> toReturn = new HashMap<>();
for (Map.Entry<KiePath, byte[]> entry : store.getResources().entrySet()) {
toReturn.put(toClassName(entry.getKey().asString()), entry.getValue());
}
return toReturn;
}
Aggregations