Search in sources :

Example 46 with InternalKieModule

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

the class KieUtil method buildAndInstallKieModuleIntoRepo.

public static KieModule buildAndInstallKieModuleIntoRepo(final KieBaseTestConfiguration kieBaseTestConfiguration, final ReleaseId releaseId, final KieModuleModel kieModuleModel, final Resource... resources) {
    final KieServices kieServices = KieServices.Factory.get();
    final KieFileSystem fileSystem = getKieFileSystemWithKieModule(kieModuleModel, releaseId, resources);
    final KieBuilder builder = getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, fileSystem, true);
    KieModule kieModule = builder.getKieModule();
    if (kieBaseTestConfiguration.useCanonicalModel()) {
        final File kjarFile = FileUtil.bytesToTempKJARFile(releaseId, ((InternalKieModule) kieModule).getBytes(), ".jar");
        kieModule = new CanonicalKieModule(releaseId, kieModuleModel, kjarFile);
    }
    kieServices.getRepository().addKieModule(kieModule);
    return kieModule;
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) CanonicalKieModule(org.drools.modelcompiler.CanonicalKieModule) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) CanonicalKieModule(org.drools.modelcompiler.CanonicalKieModule) KieModule(org.kie.api.builder.KieModule)

Example 47 with InternalKieModule

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

the class IncrementalCompilationTest method createAndDeployJarWithDSL.

public static KieModule createAndDeployJarWithDSL(KieServices ks, ReleaseId releaseId, String... drls) {
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.generateAndWritePomXML(releaseId);
    for (int i = 0; i < drls.length; i++) {
        String extension = i == 0 ? "dsl" : "rdslr";
        if (drls[i] != null) {
            kfs.write("src/main/resources/r" + i + "." + extension, drls[i]);
        }
    }
    KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
    if (kb.getResults().hasMessages(org.kie.api.builder.Message.Level.ERROR)) {
        for (org.kie.api.builder.Message result : kb.getResults().getMessages()) {
            System.out.println(result.getText());
        }
        return null;
    }
    InternalKieModule kieModule = (InternalKieModule) ks.getRepository().getKieModule(releaseId);
    byte[] jar = kieModule.getBytes();
    return deployJar(ks, jar);
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 48 with InternalKieModule

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

the class KieModuleDeploymentHelperImpl method internalCreateAndDeployKjarToMaven.

/**
 * Internal methods
 */
/**
 * Create a KJar and deploy it to maven.
 *
 * @param releaseId The {@link ReleaseId} of the jar.
 * @param kbaseName The name to use for the (default) {@link KieBase} in the kmodule.xml.
 * @param ksessionName The name to use for the (default) {@link KieSession} in the kmodule.xml.
 * @param resourceFilePaths A (possibly null) list of files to be added to the kjar.
 * @param classes
 * @param dependencies
 */
private synchronized void internalCreateAndDeployKjarToMaven(ReleaseId releaseId, String kbaseName, String ksessionName, List<String> resourceFilePaths, List<Class<?>> classes, List<String> dependencies) {
    InternalKieModule kjar = (InternalKieModule) internalCreateKieJar(releaseId, kbaseName, ksessionName, resourceFilePaths, classes, dependencies);
    String pomFileName = MavenRepository.toFileName(releaseId, null) + ".pom";
    File pomFile = new File(System.getProperty("java.io.tmpdir"), pomFileName);
    try {
        FileOutputStream fos = new FileOutputStream(pomFile);
        fos.write(config.pomText.getBytes(IoUtils.UTF8_CHARSET));
        fos.flush();
        fos.close();
    } catch (IOException ioe) {
        throw new RuntimeException("Unable to write pom.xml to temporary file : " + ioe.getMessage(), ioe);
    }
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(releaseId, kjar, pomFile);
}
Also used : FileOutputStream(java.io.FileOutputStream) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 49 with InternalKieModule

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

the class CommonTestMethodBase method createKJar.

public static byte[] createKJar(KieServices ks, ReleaseId releaseId, Resource pom, Resource... resources) {
    KieFileSystem kfs = ks.newKieFileSystem();
    if (pom != null) {
        kfs.write(pom);
    } else {
        kfs.generateAndWritePomXML(releaseId);
    }
    for (int i = 0; i < resources.length; i++) {
        if (resources[i] != null) {
            kfs.write(resources[i]);
        }
    }
    ks.newKieBuilder(kfs).buildAll();
    InternalKieModule kieModule = (InternalKieModule) ks.getRepository().getKieModule(releaseId);
    byte[] jar = kieModule.getBytes();
    return jar;
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 50 with InternalKieModule

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

the class CommonTestMethodBase method buildKJar.

public static byte[] buildKJar(KieServices ks, KieFileSystem kfs, ReleaseId releaseId) {
    KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
    if (kb.getResults().hasMessages(Message.Level.ERROR)) {
        for (Message result : kb.getResults().getMessages()) {
            System.out.println(result.getText());
        }
        return null;
    }
    InternalKieModule kieModule = (InternalKieModule) ks.getRepository().getKieModule(releaseId);
    byte[] jar = kieModule.getBytes();
    return jar;
}
Also used : Message(org.kie.api.builder.Message) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Aggregations

InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)88 ReleaseId (org.kie.api.builder.ReleaseId)56 KieServices (org.kie.api.KieServices)51 Test (org.junit.Test)45 KieContainer (org.kie.api.runtime.KieContainer)40 KieFileSystem (org.kie.api.builder.KieFileSystem)31 KieSession (org.kie.api.runtime.KieSession)30 KieBuilder (org.kie.api.builder.KieBuilder)28 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)28 KieScanner (org.kie.api.builder.KieScanner)19 InternalKieScanner (org.drools.compiler.kie.builder.impl.InternalKieScanner)18 File (java.io.File)14 FileOutputStream (java.io.FileOutputStream)9 IOException (java.io.IOException)9 KieModule (org.kie.api.builder.KieModule)8 ArrayList (java.util.ArrayList)7 Resource (org.kie.api.io.Resource)7 KieRepositoryImpl (org.drools.compiler.kie.builder.impl.KieRepositoryImpl)6 KieServicesImpl (org.drools.compiler.kie.builder.impl.KieServicesImpl)5 Ignore (org.junit.Ignore)4