use of org.drools.compiler.builder.InternalKnowledgeBuilder in project drools by kiegroup.
the class MarshallingKieMetaInfoBuilder method generateKieModuleMetaInfo.
public KieModuleMetaInfo generateKieModuleMetaInfo(ResourceStore trgMfs) {
Map<String, TypeMetaInfo> typeInfos = new HashMap<>();
Map<String, Set<String>> rulesPerPackage = new HashMap<>();
KieModuleModel kieModuleModel = kModule.getKieModuleModel();
for (String kieBaseName : kieModuleModel.getKieBaseModels().keySet()) {
KnowledgeBuilder kBuilder = kModule.getKnowledgeBuilderForKieBase(kieBaseName);
KieModuleCache.KModuleCache.Builder _kmoduleCacheBuilder = createCacheBuilder();
KieModuleCache.CompilationData.Builder _compData = createCompilationData();
for (KiePackage kPkg : kBuilder.getKnowledgePackages()) {
PackageRegistry pkgRegistry = ((InternalKnowledgeBuilder) kBuilder).getPackageRegistry(kPkg.getName());
JavaDialectRuntimeData runtimeData = (JavaDialectRuntimeData) pkgRegistry.getDialectRuntimeRegistry().getDialectData("java");
List<String> types = new ArrayList<>();
for (FactType factType : kPkg.getFactTypes()) {
Class<?> typeClass = ((ClassDefinition) factType).getDefinedClass();
TypeDeclaration typeDeclaration = pkgRegistry.getPackage().getTypeDeclaration(typeClass);
if (typeDeclaration != null) {
typeInfos.put(typeClass.getName(), new TypeMetaInfo(typeDeclaration));
}
String className = factType.getName();
String internalName = className.replace('.', '/') + ".class";
if (trgMfs != null) {
byte[] bytes = runtimeData.getBytecode(internalName);
if (bytes != null) {
trgMfs.write(internalName, bytes, true);
}
}
types.add(internalName);
}
Set<String> rules = rulesPerPackage.get(kPkg.getName());
if (rules == null) {
rules = new HashSet<>();
}
for (Rule rule : kPkg.getRules()) {
rules.add(rule.getName());
}
if (!rules.isEmpty()) {
rulesPerPackage.put(kPkg.getName(), rules);
}
addToCompilationData(_compData, runtimeData, types);
}
_kmoduleCacheBuilder.addCompilationData(_compData.build());
if (trgMfs != null) {
writeCompilationDataToTrg(_kmoduleCacheBuilder.build(), kieBaseName, trgMfs);
}
}
return new KieModuleMetaInfo(typeInfos, rulesPerPackage);
}
Aggregations