use of org.kie.memorycompiler.resources.KiePath in project drools by kiegroup.
the class DiskResourceReader method getModifiedResourcesSinceLastMark.
public Collection<String> getModifiedResourcesSinceLastMark() {
Set<String> modifiedResources = new HashSet<String>();
Map<KiePath, Integer> newHashing = hashFiles();
for (Map.Entry<KiePath, Integer> entry : newHashing.entrySet()) {
Integer oldHashing = filesHashing.get(entry.getKey());
if (oldHashing == null || !oldHashing.equals(entry.getValue())) {
modifiedResources.add(entry.getKey().asString());
}
}
for (KiePath oldFile : filesHashing.keySet()) {
if (!newHashing.containsKey(oldFile)) {
modifiedResources.add(oldFile.asString());
}
}
return modifiedResources;
}
use of org.kie.memorycompiler.resources.KiePath in project drools by kiegroup.
the class ModelWriter method writeModel.
public Result writeModel(MemoryFileSystem srcMfs, Collection<PackageSources> packageSources) {
List<GeneratedFile> generatedFiles = new ArrayList<>();
List<String> modelFiles = new ArrayList<>();
for (PackageSources pkgSources : packageSources) {
pkgSources.collectGeneratedFiles(generatedFiles);
modelFiles.addAll(pkgSources.getModelNames());
}
List<String> sourceFiles = new ArrayList<>();
for (GeneratedFile generatedFile : generatedFiles) {
KiePath path = basePath.resolve(generatedFile.getKiePath());
sourceFiles.add(path.asString());
srcMfs.write(path, generatedFile.getData());
}
return new Result(sourceFiles, modelFiles);
}
use of org.kie.memorycompiler.resources.KiePath 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