use of org.drools.core.rule.KieModuleMetaInfo in project drools by kiegroup.
the class KieInJarModuleMetaDataImpl method indexMetaInfo.
private void indexMetaInfo(byte[] bytes) {
KieModuleMetaInfo info = KieModuleMetaInfo.unmarshallMetaInfos(new String(bytes, UTF8_CHARSET));
typeMetaInfos.putAll(info.getTypeMetaInfos());
rulesByPackage.putAll(info.getRulesByPackage());
}
use of org.drools.core.rule.KieModuleMetaInfo in project kie-wb-common by kiegroup.
the class ClassLoaderProviderTest method getResourcesFromADroolsPRJWithError.
@Test
@Ignore("https://issues.redhat.com/browse/AF-2892")
public void getResourcesFromADroolsPRJWithError() throws Exception {
/**
* If the test fail check if the Drools core classes used, KieModuleMetaInfo and TypeMetaInfo implements Serializable
*/
Path tmpRoot = Files.createTempDirectory("repo");
Path tmp = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.KJAR_2_SINGLE_RESOURCES_WITH_ERROR);
AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.STORE_KIE_OBJECTS, KieDecorator.ENABLE_INCREMENTAL_BUILD));
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(tmp.toUri()));
CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.INSTALL, MavenCLIArgs.ALTERNATE_USER_SETTINGS + TestUtilMaven.getSettingsFile() }, Boolean.FALSE);
KieCompilationResponse res = (KieCompilationResponse) compiler.compile(req);
TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tmp, res, this.getClass(), testName);
if (!res.isSuccessful()) {
List<String> msgs = res.getMavenOutput();
for (String msg : msgs) {
logger.info(msg);
}
}
assertThat(res.isSuccessful()).isTrue();
Optional<KieModuleMetaInfo> metaDataOptional = res.getKieModuleMetaInfo();
assertThat(metaDataOptional).isPresent();
KieModuleMetaInfo kieModuleMetaInfo = metaDataOptional.get();
assertThat(kieModuleMetaInfo).isNotNull();
Optional<KieModule> kieModuleOptional = res.getKieModule();
assertThat(kieModuleOptional).isPresent();
List<String> classloaderOptional = CompilerClassloaderUtils.getStringFromTargets(tmpRoot);
assertThat(classloaderOptional).hasSize(3);
}
use of org.drools.core.rule.KieModuleMetaInfo in project kie-wb-common by kiegroup.
the class KieMetadataTest method compileAndloadKieJarSingleMetadataWithPackagedJar.
@Test
@Ignore("https://issues.redhat.com/browse/AF-2892")
public void compileAndloadKieJarSingleMetadataWithPackagedJar() throws Exception {
/**
* If the test fail check if the Drools core classes used, KieModuleMetaInfo and TypeMetaInfo implements Serializable
*/
Path tmp = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.KJAR_2_SINGLE_RESOURCES);
final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.STORE_KIE_OBJECTS, KieDecorator.STORE_BUILD_CLASSPATH, KieDecorator.ENABLE_INCREMENTAL_BUILD));
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(tmp.toUri()));
CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, Boolean.FALSE);
KieCompilationResponse res = (KieCompilationResponse) compiler.compile(req);
TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tmp, res, this.getClass(), testName);
if (!res.isSuccessful()) {
List<String> msgs = res.getMavenOutput();
for (String msg : msgs) {
logger.info(msg);
}
}
assertThat(res.isSuccessful()).isTrue();
Optional<KieModuleMetaInfo> metaDataOptional = res.getKieModuleMetaInfo();
assertThat(metaDataOptional).isPresent();
KieModuleMetaInfo kieModuleMetaInfo = metaDataOptional.get();
assertThat(kieModuleMetaInfo).isNotNull();
Optional<KieModule> kieModuleOptional = res.getKieModule();
assertThat(kieModuleOptional).isPresent();
KieModule kModule = kieModuleOptional.get();
assertThat(res.getDependenciesAsURI()).hasSize(4);
KieModuleMetaData kieModuleMetaData = new KieModuleMetaDataImpl((InternalKieModule) kModule, res.getDependenciesAsURI());
assertThat(kieModuleMetaData).isNotNull();
// comment if you want read the log file after the test run
}
use of org.drools.core.rule.KieModuleMetaInfo in project kie-wb-common by kiegroup.
the class KieMetadataTest method compileAndloadKieJarSingleMetadata.
@Test
@Ignore("https://issues.redhat.com/browse/AF-2892")
public void compileAndloadKieJarSingleMetadata() {
/**
* If the test fail check if the Drools core classes used, KieModuleMetaInfo and TypeMetaInfo implements Serializable
*/
try {
Path tmp = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.KJAR_2_SINGLE_RESOURCES);
final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING, KieDecorator.STORE_KIE_OBJECTS, KieDecorator.STORE_BUILD_CLASSPATH, KieDecorator.ENABLE_INCREMENTAL_BUILD));
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(tmp.toUri()));
CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, Boolean.FALSE);
KieCompilationResponse res = (KieCompilationResponse) compiler.compile(req);
TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tmp, res, this.getClass(), testName);
if (!res.isSuccessful()) {
List<String> msgs = res.getMavenOutput();
for (String msg : msgs) {
logger.info(msg);
}
}
assertThat(res.isSuccessful()).isTrue();
Optional<KieModuleMetaInfo> metaDataOptional = res.getKieModuleMetaInfo();
assertThat(metaDataOptional).isPresent();
KieModuleMetaInfo kieModuleMetaInfo = metaDataOptional.get();
assertThat(kieModuleMetaInfo).isNotNull();
Optional<KieModule> kieModuleOptional = res.getKieModule();
assertThat(kieModuleOptional).isPresent();
assertThat(res.getDependenciesAsURI()).hasSize(4);
// comment if you want read the log file after the test run
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.drools.core.rule.KieModuleMetaInfo in project drools by kiegroup.
the class KieMetaInfoBuilder 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);
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);
}
}
}
return new KieModuleMetaInfo(typeInfos, rulesPerPackage);
}
Aggregations