Search in sources :

Example 61 with InternalKieModule

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

the class KieModuleBuilderTest method createKieJarWithPomDependencies.

private InternalKieModule createKieJarWithPomDependencies(KieServices ks, ReleaseId releaseId, String pom) throws IOException {
    KieFileSystem kfs = createKieFileSystemWithKProject(ks, false);
    kfs.writePomXML(pom);
    kfs.write("src/main/java/org/kie/test/Bean.java", createJavaSource(3));
    KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    assertTrue(kieBuilder.buildAll().getResults().getMessages().isEmpty());
    return (InternalKieModule) kieBuilder.getKieModule();
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 62 with InternalKieModule

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

the class KieModuleMavenTest method testKieModuleFromMavenWithTransitiveDependencies.

@Test
public void testKieModuleFromMavenWithTransitiveDependencies() throws Exception {
    final KieServices ks = new KieServicesImpl() {

        @Override
        public KieRepository getRepository() {
            // override repository to not store the artifact on deploy to trigger load from maven repo
            return new KieRepositoryImpl();
        }
    };
    ReleaseId dependency = ks.newReleaseId("org.drools", "drools-core", "5.5.0.Final");
    ReleaseId releaseId = ks.newReleaseId("org.kie", "maven-test", "1.0-SNAPSHOT");
    String pomText = getPom(releaseId, dependency);
    InternalKieModule kJar1 = createKieJar(ks, releaseId, pomText, true, "rule1", "rule2");
    File pomFile = new File(System.getProperty("java.io.tmpdir"), MavenRepository.toFileName(releaseId, null) + ".pom");
    try {
        FileOutputStream fos = new FileOutputStream(pomFile);
        fos.write(pomText.getBytes());
        fos.flush();
        fos.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    KieMavenRepository.getKieMavenRepository().installArtifact(releaseId, kJar1, pomFile);
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    Collection<ReleaseId> expectedDependencies = new HashSet<ReleaseId>();
    expectedDependencies.add(ks.newReleaseId("org.drools", "knowledge-api", "5.5.0.Final"));
    expectedDependencies.add(ks.newReleaseId("org.drools", "knowledge-internal-api", "5.5.0.Final"));
    expectedDependencies.add(ks.newReleaseId("org.drools", "drools-core", "5.5.0.Final"));
    expectedDependencies.add(ks.newReleaseId("org.mvel", "mvel2", "2.1.3.Final"));
    expectedDependencies.add(ks.newReleaseId("org.slf4j", "slf4j-api", "1.6.4"));
    Collection<ReleaseId> dependencies = ((InternalKieModule) ((KieContainerImpl) kieContainer).getKieModuleForKBase("KBase1")).getJarDependencies(DependencyFilter.TAKE_ALL_FILTER);
    assertNotNull(dependencies);
    assertEquals(5, dependencies.size());
    boolean matchedAll = dependencies.containsAll(expectedDependencies);
    assertTrue(matchedAll);
}
Also used : KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) IOException(java.io.IOException) KieRepositoryImpl(org.drools.compiler.kie.builder.impl.KieRepositoryImpl) FileOutputStream(java.io.FileOutputStream) KieServicesImpl(org.drools.compiler.kie.builder.impl.KieServicesImpl) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 63 with InternalKieModule

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

the class KieModuleMavenTest method testResourceTypeInKieModuleReleaseId.

@Test
public void testResourceTypeInKieModuleReleaseId() throws Exception {
    final KieServices ks = new KieServicesImpl() {

        @Override
        public KieRepository getRepository() {
            // override repository to not store the artifact on deploy to trigger load from maven repo
            return new KieRepositoryImpl();
        }
    };
    ReleaseId releaseId = ks.newReleaseId("org.kie", "maven-test.drl", "1.0-SNAPSHOT");
    InternalKieModule kJar1 = createKieJar(ks, releaseId, true, "rule1", "rule2");
    String pomText = getPom(releaseId);
    File pomFile = new File(System.getProperty("java.io.tmpdir"), MavenRepository.toFileName(releaseId, null) + ".pom");
    try {
        FileOutputStream fos = new FileOutputStream(pomFile);
        fos.write(pomText.getBytes());
        fos.flush();
        fos.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    KieMavenRepository.getKieMavenRepository().installArtifact(releaseId, kJar1, pomFile);
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    KieBase kieBase = kieContainer.getKieBase("KBase1");
    assertNotNull(kieBase);
    assertEquals("There must be one package built", 1, kieBase.getKiePackages().size());
    ClassLoader classLoader = kieContainer.getClassLoader();
    assertEnumerationSize(1, classLoader.getResources("KBase1/org/test"));
    assertEnumerationSize(1, classLoader.getResources("META-INF/maven/org.kie/maven-test.drl"));
}
Also used : KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) IOException(java.io.IOException) KieBase(org.kie.api.KieBase) KieRepositoryImpl(org.drools.compiler.kie.builder.impl.KieRepositoryImpl) FileOutputStream(java.io.FileOutputStream) KieServicesImpl(org.drools.compiler.kie.builder.impl.KieServicesImpl) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 64 with InternalKieModule

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

the class KieModuleMetaDataTest method testKieModuleMetaDataInMemory.

private void testKieModuleMetaDataInMemory(boolean useTypeDeclaration) throws Exception {
    KieServices ks = KieServices.Factory.get();
    ReleaseId dependency = ks.newReleaseId("org.drools", "drools-core", "5.5.0.Final");
    ReleaseId releaseId = ks.newReleaseId("org.kie", "metadata-test", "1.0-SNAPSHOT");
    InternalKieModule kieModule = createKieJarWithClass(ks, releaseId, useTypeDeclaration, 2, 7, dependency);
    KieModuleMetaData kieModuleMetaData = KieModuleMetaData.Factory.newKieModuleMetaData(kieModule);
    checkDroolsCoreDep(kieModuleMetaData);
    Collection<String> testClasses = kieModuleMetaData.getClasses("org.kie.test");
    assertEquals(1, testClasses.size());
    assertEquals("Bean", testClasses.iterator().next());
    Class<?> beanClass = kieModuleMetaData.getClass("org.kie.test", "Bean");
    assertNotNull(beanClass.getMethod("getValue"));
    TypeMetaInfo beanTypeInfo = kieModuleMetaData.getTypeMetaInfo(beanClass);
    assertNotNull(beanTypeInfo);
    assertTrue(beanTypeInfo.isEvent());
    Role role = beanClass.getAnnotation(Role.class);
    assertNotNull(role);
    assertEquals(Role.Type.EVENT, role.value());
    assertEquals(useTypeDeclaration, beanTypeInfo.isDeclaredType());
}
Also used : Role(org.kie.api.definition.type.Role) TypeMetaInfo(org.drools.core.rule.TypeMetaInfo) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 65 with InternalKieModule

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

the class KieModuleMetaDataTest method testKieModuleMetaDataInMemoryUsingPOM.

private void testKieModuleMetaDataInMemoryUsingPOM(boolean useTypeDeclaration) throws Exception {
    // Build a KieModule jar, deploy it into local Maven repository
    KieServices ks = KieServices.Factory.get();
    ReleaseId dependency = ks.newReleaseId("org.drools", "drools-core", "5.5.0.Final");
    ReleaseId releaseId = ks.newReleaseId("org.kie", "metadata-test", "1.0-SNAPSHOT");
    InternalKieModule kieModule = createKieJarWithClass(ks, releaseId, useTypeDeclaration, 2, 7, dependency);
    String pomText = getPom(dependency);
    File pomFile = new File(System.getProperty("java.io.tmpdir"), MavenRepository.toFileName(releaseId, null) + ".pom");
    try {
        FileOutputStream fos = new FileOutputStream(pomFile);
        fos.write(pomText.getBytes());
        fos.flush();
        fos.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    KieMavenRepository.getKieMavenRepository().installArtifact(releaseId, kieModule, pomFile);
    // Build a second KieModule, depends on the first KieModule jar which we have deployed into Maven
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "metadata-test-using-pom", "1.0-SNAPSHOT");
    String pomText2 = getPom(releaseId2, releaseId);
    File pomFile2 = new File(System.getProperty("java.io.tmpdir"), MavenRepository.toFileName(releaseId2, null) + ".pom");
    try {
        FileOutputStream fos = new FileOutputStream(pomFile2);
        fos.write(pomText2.getBytes());
        fos.flush();
        fos.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    KieModuleMetaData kieModuleMetaData = KieModuleMetaData.Factory.newKieModuleMetaData(pomFile2);
    // checkDroolsCoreDep(kieModuleMetaData);
    Collection<String> testClasses = kieModuleMetaData.getClasses("org.kie.test");
    assertEquals(1, testClasses.size());
    assertEquals("Bean", testClasses.iterator().next());
    Class<?> beanClass = kieModuleMetaData.getClass("org.kie.test", "Bean");
    assertNotNull(beanClass.getMethod("getValue"));
    if (useTypeDeclaration) {
        assertTrue(kieModuleMetaData.getTypeMetaInfo(beanClass).isEvent());
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) IOException(java.io.IOException) File(java.io.File) 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