Search in sources :

Example 96 with ReleaseId

use of org.kie.api.builder.ReleaseId in project drools by kiegroup.

the class DrlxCompiler method compileSingleSource.

public static CompiledUnit compileSingleSource(Reader source) {
    CompilationUnit compilationUnit = JavaParser.parse(source);
    ClassOrInterfaceDeclaration unitClass = (ClassOrInterfaceDeclaration) compilationUnit.getType(0);
    String pkg = compilationUnit.getPackageDeclaration().map(PackageDeclaration::getNameAsString).orElse("defaultpkg");
    String unit = unitClass.getNameAsString();
    KieServices ks = KieServices.get();
    ReleaseId releaseId = ks.newReleaseId(pkg, unit, "1.0");
    KieFileSystem kfs = createKieFileSystem(ks, releaseId);
    String unitPath = pkg.replace(".", "/") + "/" + unit;
    String javaPath = "src/main/java/" + unitPath + ".java";
    String drlPath = "src/main/resources/" + unitPath + ".drl";
    kfs.write(drlPath, toDrl(compilationUnit)).write(javaPath, toJava(compilationUnit));
    KieContainer kieContainer = createKieContainer(ks, kfs, releaseId);
    return new CompiledUnit(kieContainer, pkg + "." + unit);
}
Also used : CompilationUnit(org.drools.javaparser.ast.CompilationUnit) KieFileSystem(org.kie.api.builder.KieFileSystem) ClassOrInterfaceDeclaration(org.drools.javaparser.ast.body.ClassOrInterfaceDeclaration) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieContainer(org.kie.api.runtime.KieContainer)

Example 97 with ReleaseId

use of org.kie.api.builder.ReleaseId in project drools by kiegroup.

the class BaseModelTest method getKieContainer.

protected KieContainer getKieContainer(KieModuleModel model, KieFile... stringRules) {
    KieServices ks = KieServices.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "kjar-test-" + UUID.randomUUID(), "1.0");
    KieBuilder kieBuilder = createKieBuilder(ks, model, releaseId, stringRules);
    return ks.newKieContainer(releaseId);
}
Also used : KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieBuilder(org.kie.api.builder.KieBuilder)

Example 98 with ReleaseId

use of org.kie.api.builder.ReleaseId in project drools by kiegroup.

the class KieRepositoryTest method testRemoveKieModuleSnapshot.

/**
 * Tests removing a KieModule with a SNAPSHOT ReleaseId from KieRepository.
 */
@Test
public void testRemoveKieModuleSnapshot() {
    final ReleaseId releaseId = kieServices.newReleaseId(TestConstants.PACKAGE_TESTCOVERAGE, TEST_ARTIFACT_ID, TEST_ARTIFACT_VERSION_SNAPSHOT);
    this.testKieModuleRemoval(releaseId);
}
Also used : ReleaseId(org.kie.api.builder.ReleaseId) Test(org.junit.Test)

Example 99 with ReleaseId

use of org.kie.api.builder.ReleaseId in project drools by kiegroup.

the class KieRepositoryTest method testAddKieModuleSnapshot.

/**
 * Tests adding a KieModule with a SNAPSHOT ReleaseId to KieRepository.
 */
@Test
public void testAddKieModuleSnapshot() {
    final ReleaseId releaseId = kieServices.newReleaseId(TestConstants.PACKAGE_TESTCOVERAGE, TEST_ARTIFACT_ID, TEST_ARTIFACT_VERSION_SNAPSHOT);
    this.testKieModuleAddition(releaseId);
}
Also used : ReleaseId(org.kie.api.builder.ReleaseId) Test(org.junit.Test)

Example 100 with ReleaseId

use of org.kie.api.builder.ReleaseId in project drools by kiegroup.

the class BuildtimeUtil method generateKJarFromKieBuilder.

public static void generateKJarFromKieBuilder(final KieBuilder kieBuilder, final boolean useCanonicalModel) throws IOException {
    final ReleaseId releaseId = kieBuilder.getKieModule().getReleaseId();
    final InternalKieModule kieModule = (InternalKieModule) kieBuilder.getKieModule();
    final File kjarFile = bytesToTempFile(releaseId, kieModule.getBytes(), ".jar");
    final KieModule zipKieModule;
    if (useCanonicalModel) {
        zipKieModule = new CanonicalKieModule(releaseId, kieModule.getKieModuleModel(), kjarFile);
    } else {
        zipKieModule = new ZipKieModule(releaseId, kieModule.getKieModuleModel(), kjarFile);
    }
    KieServices.get().getRepository().addKieModule(zipKieModule);
}
Also used : ZipKieModule(org.drools.compiler.kie.builder.impl.ZipKieModule) CanonicalKieModule(org.drools.modelcompiler.CanonicalKieModule) ReleaseId(org.kie.api.builder.ReleaseId) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) CanonicalKieModule(org.drools.modelcompiler.CanonicalKieModule) ZipKieModule(org.drools.compiler.kie.builder.impl.ZipKieModule) KieModule(org.kie.api.builder.KieModule) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Aggregations

ReleaseId (org.kie.api.builder.ReleaseId)273 Test (org.junit.Test)219 KieServices (org.kie.api.KieServices)214 KieContainer (org.kie.api.runtime.KieContainer)176 KieSession (org.kie.api.runtime.KieSession)137 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)117 KieModule (org.kie.api.builder.KieModule)84 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)73 KieFileSystem (org.kie.api.builder.KieFileSystem)64 KieModuleModel (org.kie.api.builder.model.KieModuleModel)40 KieBuilder (org.kie.api.builder.KieBuilder)34 ArrayList (java.util.ArrayList)32 Message (org.drools.compiler.Message)32 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)27 Resource (org.kie.api.io.Resource)23 Results (org.kie.api.builder.Results)20 KieBaseModel (org.kie.api.builder.model.KieBaseModel)20 InternalKieScanner (org.drools.compiler.kie.builder.impl.InternalKieScanner)18 KieScanner (org.kie.api.builder.KieScanner)18 IncrementalResults (org.kie.internal.builder.IncrementalResults)18