Search in sources :

Example 26 with KieFileSystem

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());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieBuilder(org.kie.api.builder.KieBuilder) KieSessionModel(org.kie.api.builder.model.KieSessionModel)

Example 27 with KieFileSystem

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);
}
Also used : MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) KieFileSystem(org.kie.api.builder.KieFileSystem) Test(org.junit.Test)

Example 28 with KieFileSystem

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());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Example 29 with KieFileSystem

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);
    }
}
Also used : ResourceReader(org.drools.compiler.commons.jci.readers.ResourceReader) DiskResourceReader(org.drools.compiler.commons.jci.readers.DiskResourceReader) KieFileSystem(org.kie.api.builder.KieFileSystem) HashMap(java.util.HashMap) KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) PMMLCompiler(org.drools.compiler.compiler.PMMLCompiler) Resource(org.kie.api.io.Resource) PMMLResource(org.drools.compiler.compiler.PMMLResource) IOException(java.io.IOException) JavaDialectConfiguration(org.drools.compiler.rule.builder.dialect.java.JavaDialectConfiguration)

Example 30 with KieFileSystem

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();
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

KieFileSystem (org.kie.api.builder.KieFileSystem)297 KieServices (org.kie.api.KieServices)241 Test (org.junit.Test)211 KieBuilder (org.kie.api.builder.KieBuilder)179 KieSession (org.kie.api.runtime.KieSession)101 KieModuleModel (org.kie.api.builder.model.KieModuleModel)79 KieContainer (org.kie.api.runtime.KieContainer)74 ReleaseId (org.kie.api.builder.ReleaseId)64 Results (org.kie.api.builder.Results)60 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)53 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)39 KieBase (org.kie.api.KieBase)38 IncrementalResults (org.kie.internal.builder.IncrementalResults)36 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)32 KieBaseModel (org.kie.api.builder.model.KieBaseModel)31 ArrayList (java.util.ArrayList)30 Message (org.kie.api.builder.Message)26 KieModule (org.kie.api.builder.KieModule)22 Message (org.drools.compiler.Message)20 Resource (org.kie.api.io.Resource)18