Search in sources :

Example 41 with InternalKieModule

use of org.drools.compiler.kie.builder.impl.InternalKieModule in project jbpm by kiegroup.

the class BusinessRuleTaskTest method createAndDeployJar.

private byte[] createAndDeployJar(KieServices ks, ReleaseId releaseId, Resource... resources) throws Exception {
    KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId);
    for (int i = 0; i < resources.length; i++) {
        if (resources[i] != null) {
            kfs.write(resources[i]);
        }
    }
    KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    ((InternalKieBuilder) kieBuilder).buildAll(o -> true);
    Results results = kieBuilder.getResults();
    if (results.hasMessages(Message.Level.ERROR)) {
        throw new IllegalStateException(results.getMessages(Message.Level.ERROR).toString());
    }
    InternalKieModule kieModule = (InternalKieModule) ks.getRepository().getKieModule(releaseId);
    byte[] pomXmlContent = IOUtils.toByteArray(kieModule.getPomAsStream());
    File pom = new File("target", UUID.randomUUID().toString());
    Files.write(pom.toPath(), pomXmlContent);
    KieMavenRepository.getKieMavenRepository().installArtifact(releaseId, kieModule, pom);
    byte[] jar = kieModule.getBytes();
    return jar;
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) Results(org.kie.api.builder.Results) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 42 with InternalKieModule

use of org.drools.compiler.kie.builder.impl.InternalKieModule in project jbpm by kiegroup.

the class RuntimeDataServiceEJBIntegrationTest method deployKjar.

protected static void deployKjar() {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION);
    List<String> processes = new ArrayList<String>();
    processes.add("processes/EmptyHumanTask.bpmn");
    processes.add("processes/humanTask.bpmn");
    processes.add("processes/SimpleHTProcess.bpmn2");
    InternalKieModule kJar1 = createKieJar(ks, releaseId, processes);
    File pom = new File("target/kmodule", "pom.xml");
    pom.getParentFile().mkdir();
    try {
        FileOutputStream fs = new FileOutputStream(pom);
        fs.write(getPom(releaseId).getBytes());
        fs.close();
    } catch (Exception e) {
    }
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(releaseId, kJar1, pom);
}
Also used : FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 43 with InternalKieModule

use of org.drools.compiler.kie.builder.impl.InternalKieModule in project jbpm by kiegroup.

the class UserTaskServiceEJBIntegrationTest method deployKjar.

protected static void deployKjar() {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION);
    List<String> processes = new ArrayList<String>();
    processes.add("processes/EmptyHumanTask.bpmn");
    processes.add("processes/humanTask.bpmn");
    InternalKieModule kJar1 = createKieJar(ks, releaseId, processes);
    File pom = new File("target/kmodule", "pom.xml");
    pom.getParentFile().mkdir();
    try {
        FileOutputStream fs = new FileOutputStream(pom);
        fs.write(getPom(releaseId).getBytes());
        fs.close();
    } catch (Exception e) {
    }
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(releaseId, kJar1, pom);
}
Also used : FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 44 with InternalKieModule

use of org.drools.compiler.kie.builder.impl.InternalKieModule in project jbpm by kiegroup.

the class AbstractTestSupport method createKieJar.

protected static InternalKieModule createKieJar(KieServices ks, ReleaseId releaseId, List<String> resources, Map<String, String> extraResources) {
    KieFileSystem kfs = createKieFileSystemWithKProject(ks);
    kfs.writePomXML(getPom(releaseId));
    for (String resource : resources) {
        kfs.write("src/main/resources/KBase-test/" + resource, ResourceFactory.newClassPathResource(resource));
    }
    if (extraResources != null) {
        for (Map.Entry<String, String> entry : extraResources.entrySet()) {
            kfs.write(entry.getKey(), ResourceFactory.newByteArrayResource(entry.getValue().getBytes()));
        }
    }
    kfs.write("src/main/resources/forms/DefaultProcess.ftl", ResourceFactory.newClassPathResource("repo/globals/forms/DefaultProcess.ftl"));
    KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    if (!kieBuilder.buildAll().getResults().getMessages().isEmpty()) {
        for (Message message : kieBuilder.buildAll().getResults().getMessages()) {
            logger.error("Error Message: ({}) {}", message.getPath(), message.getText());
        }
        throw new RuntimeException("There are errors builing the package, please check your knowledge assets!");
    }
    return (InternalKieModule) kieBuilder.getKieModule();
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) KieBuilder(org.kie.api.builder.KieBuilder) Map(java.util.Map) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 45 with InternalKieModule

use of org.drools.compiler.kie.builder.impl.InternalKieModule in project jbpm by kiegroup.

the class DeploymentServiceEJBIntegrationTest method deployKjar.

protected static void deployKjar() {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION);
    List<String> processes = new ArrayList<String>();
    processes.add("processes/customtask.bpmn");
    processes.add("processes/humanTask.bpmn");
    processes.add("processes/signal.bpmn");
    processes.add("processes/import.bpmn");
    processes.add("processes/callactivity.bpmn");
    InternalKieModule kJar1 = createKieJar(ks, releaseId, processes);
    File pom = new File("target/kmodule", "pom.xml");
    pom.getParentFile().mkdir();
    try {
        FileOutputStream fs = new FileOutputStream(pom);
        fs.write(getPom(releaseId).getBytes());
        fs.close();
    } catch (Exception e) {
    }
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(releaseId, kJar1, pom);
    ReleaseId releaseIdSupport = ks.newReleaseId(GROUP_ID, "support", VERSION);
    List<String> processesSupport = new ArrayList<String>();
    processesSupport.add("processes/support.bpmn");
    InternalKieModule kJar2 = createKieJar(ks, releaseIdSupport, processesSupport);
    File pom2 = new File("target/kmodule2", "pom.xml");
    pom2.getParentFile().mkdir();
    try {
        FileOutputStream fs = new FileOutputStream(pom2);
        fs.write(getPom(releaseIdSupport).getBytes());
        fs.close();
    } catch (Exception e) {
    }
    repository.installArtifact(releaseIdSupport, kJar2, pom2);
    ReleaseId releaseId3 = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, "1.1.0-SNAPSHOT");
    InternalKieModule kJar3 = createKieJar(ks, releaseId3, processes);
    File pom3 = new File("target/kmodule3", "pom.xml");
    pom3.getParentFile().mkdirs();
    try {
        FileOutputStream fs = new FileOutputStream(pom3);
        fs.write(getPom(releaseId3).getBytes());
        fs.close();
    } catch (Exception e) {
    }
    repository = getKieMavenRepository();
    repository.installArtifact(releaseId3, kJar3, pom3);
}
Also used : FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Aggregations

InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)201 ReleaseId (org.kie.api.builder.ReleaseId)125 KieServices (org.kie.api.KieServices)120 Test (org.junit.Test)86 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)72 File (java.io.File)62 ArrayList (java.util.ArrayList)57 KieContainer (org.kie.api.runtime.KieContainer)57 KieBuilder (org.kie.api.builder.KieBuilder)55 KieFileSystem (org.kie.api.builder.KieFileSystem)54 FileOutputStream (java.io.FileOutputStream)53 KieMavenRepository (org.kie.scanner.KieMavenRepository)51 KieSession (org.kie.api.runtime.KieSession)43 HashMap (java.util.HashMap)28 Before (org.junit.Before)28 KieModule (org.kie.api.builder.KieModule)24 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)23 KieScanner (org.kie.api.builder.KieScanner)20 InternalKieScanner (org.drools.compiler.kie.builder.impl.InternalKieScanner)18 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)17