use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class WireChannelTest method build.
private void build(KieServices ks, ReleaseId releaseId) throws IOException {
KieModuleModel kproj = ks.newKieModuleModel();
KieSessionModel ksession1 = kproj.newKieBaseModel("KBase1").newKieSessionModel("KSession1").setDefault(true);
ksession1.newChannelModel("testChannel", RecordingChannel.class.getName());
KieFileSystem kfs = ks.newKieFileSystem();
kfs.writeKModuleXML(kproj.toXML()).writePomXML(generatePomXml(releaseId)).write("src/main/resources/KBase1/rules.drl", createDRL());
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
assertTrue(kieBuilder.buildAll().getResults().getMessages().isEmpty());
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class KieFileSystemImplTest method testClone.
@Test
public void testClone() throws Exception {
KieFileSystem clonedKieFileSystem = kieFileSystem.clone();
MemoryFileSystem clonedMfs = ((KieFileSystemImpl) clonedKieFileSystem).getMfs();
Collection<String> clonedFileNames = clonedMfs.getFileNames();
assertTrue(kieFileSystem != clonedKieFileSystem);
assertTrue(kieFileSystem.getMfs() != clonedMfs);
assertEquals(kieFileSystem.getMfs().getFileNames(), clonedFileNames);
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class KieBuilderSetImplTest method testBuild.
@Test
public void testBuild() throws Exception {
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem();
kfs.write("src/main/resources/rule%201.drl", ruleContent());
final KieBuilderSetImpl kieBuilderSet = new KieBuilderSetImpl(kieBuilder(ks, kfs));
kieBuilderSet.setFiles(new String[] { "src/main/resources/rule%201.drl" });
final IncrementalResults build = kieBuilderSet.build();
assertEquals(0, build.getAddedMessages().size());
assertEquals(0, build.getRemovedMessages().size());
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class KieBuilderImpl method buildPMMLPojos.
private void buildPMMLPojos(List<String> pmmlFileNames, KieProject kProject) {
PMMLCompiler compiler = PMMLCompilerFactory.getPMMLCompiler();
System.out.println("!!!!! PMMLCompiler version = " + compiler.getCompilerVersion() + " !!!!!");
KieFileSystem javaSource = KieServices.Factory.get().newKieFileSystem();
Map<String, String> javaSources = new HashMap<>();
for (String fname : pmmlFileNames) {
Map<String, String> modelSources = null;
Resource pmmlContent = ResourceFactory.newByteArrayResource(srcMfs.getBytes(fname));
if (pmmlContent != null) {
try {
modelSources = compiler.getJavaClasses(pmmlContent.getInputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
modelSources = compiler.getJavaClasses(fname);
}
if (modelSources != null && !modelSources.isEmpty()) {
javaSources.putAll(modelSources);
}
}
for (String key : javaSources.keySet()) {
String javaCode = javaSources.get(key);
if (javaCode != null && !javaCode.trim().isEmpty()) {
Resource res = ResourceFactory.newByteArrayResource(javaCode.getBytes()).setResourceType(ResourceType.JAVA);
String sourcePath = key.replaceAll("\\.", "/") + ".java";
res.setSourcePath(sourcePath);
javaSource.write(res);
}
}
ResourceReader src = ((KieFileSystemImpl) javaSource).asMemoryFileSystem();
List<String> javaFileNames = getJavaFileNames(src);
if (javaFileNames != null && !javaFileNames.isEmpty()) {
ClassLoader classLoader = kProject.getClassLoader();
KnowledgeBuilderConfigurationImpl kconf = new KnowledgeBuilderConfigurationImpl(classLoader);
JavaDialectConfiguration javaConf = (JavaDialectConfiguration) kconf.getDialectConfiguration("java");
compileJavaClasses(javaConf, classLoader, javaFileNames, JAVA_ROOT, src);
}
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class KieFileSystemImpl method readFromByteArray.
private KieFileSystem readFromByteArray(final ByteArrayOutputStream byteArrayOutputStream) throws IOException, ClassNotFoundException {
final byte[] byteArray = byteArrayOutputStream.toByteArray();
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
final ObjectInputStream inputStream = new ObjectInputStream(byteArrayInputStream);
return (KieFileSystem) inputStream.readObject();
}
Aggregations