Search in sources :

Example 11 with Message

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

the class KieModuleMetaDataTest method testGetPackageNames.

@Test
public void testGetPackageNames() {
    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write("src/main/resources/test.drl", "package org.test declare Bean end");
    final KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    final List<Message> messages = kieBuilder.buildAll().getResults().getMessages();
    assertTrue(messages.isEmpty());
    final KieModule kieModule = kieBuilder.getKieModule();
    final KieModuleMetaData kieModuleMetaData = KieModuleMetaData.Factory.newKieModuleMetaData(kieModule);
    assertFalse(kieModuleMetaData.getPackages().isEmpty());
    assertTrue(kieModuleMetaData.getPackages().contains("org.test"));
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) Test(org.junit.Test)

Example 12 with Message

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

the class KieModuleMetaDataTest method testKieMavenPluginEmptyProject.

@Test
public void testKieMavenPluginEmptyProject() {
    // According to https://bugzilla.redhat.com/show_bug.cgi?id=1049674#c2 the below is the minimal POM required to use KieMavenPlugin.
    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write("pom.xml", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<project xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\" xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "  <modelVersion>4.0.0</modelVersion>" + "  <groupId>org.kie</groupId>" + "  <artifactId>plugin-test</artifactId>" + "  <version>1.0</version>" + "  <packaging>kjar</packaging>" + "  <build>" + "    <plugins>" + "      <plugin>" + "        <groupId>org.kie</groupId>" + "        <artifactId>kie-maven-plugin</artifactId>" + "        <version>the-test-does-not-need-proper-version-here</version>" + "        <extensions>true</extensions>" + "      </plugin>" + "    </plugins>" + "  </build>" + "</project>");
    kfs.write("/src/main/resources/META-INF/kmodule.xml", "<kmodule xmlns=\"http://www.drools.org/xsd/kmodule\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>");
    final KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    final List<Message> messages = kieBuilder.buildAll().getResults().getMessages();
    assertTrue(messages.isEmpty());
    final KieModule kieModule = kieBuilder.getKieModule();
    final KieModuleMetaData kieModuleMetaData = KieModuleMetaData.Factory.newKieModuleMetaData(kieModule);
    boolean fail = false;
    for (final String packageName : kieModuleMetaData.getPackages()) {
        for (final String className : kieModuleMetaData.getClasses(packageName)) {
            try {
                kieModuleMetaData.getClass(packageName, className);
            } catch (Throwable e) {
                fail = true;
                System.out.println(e);
            }
        }
    }
    if (fail) {
        fail("See console for details.");
    }
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) Test(org.junit.Test)

Example 13 with Message

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

the class KieRepositoryScannerTest method testMissingDependency.

@Test
public void testMissingDependency() throws Exception {
    KieServices ks = KieServices.Factory.get();
    MavenRepository repository = getMavenRepository();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test", "1.0");
    ReleaseId missingDep = ks.newReleaseId("org.kie", "missing-dep", "1.0");
    KieFileSystem kfs = createKieFileSystemWithKProject(ks, false);
    kfs.writePomXML(getPom(releaseId, missingDep));
    kfs.write("src/main/resources/KBase1/rule1.drl", createDRLWithTypeDeclaration(1, 1));
    KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    List<Message> messages = kieBuilder.buildAll().getResults().getMessages();
    assertEquals(1, messages.size());
    assertTrue(messages.get(0).toString().contains("missing-dep"));
    ks.getRepository().removeKieModule(releaseId);
}
Also used : MavenRepository.getMavenRepository(org.appformer.maven.integration.MavenRepository.getMavenRepository) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) MavenRepository(org.appformer.maven.integration.MavenRepository) KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieBuilder(org.kie.api.builder.KieBuilder) Test(org.junit.Test)

Example 14 with Message

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

the class KieModuleDeploymentHelperImpl method internalCreateKieJar.

/**
 * Create a KJar for deployment;
 *
 * @param releaseId Release (deployment) id.
 * @param resourceFilePaths List of resource file paths
 * @param kbaseName The name of the {@link KieBase}
 * @param ksessionName The name of the {@link KieSession}.
 * @param dependencies List of dependencies to add
 *
 * @return The {@link InternalKieModule} which represents the KJar.
 */
private synchronized KieModule internalCreateKieJar(ReleaseId releaseId, String kbaseName, String ksessionName, List<String> resourceFilePaths, List<Class<?>> classes, List<String> dependencies) {
    ReleaseId[] releaseIds = {};
    if (dependencies != null && dependencies.size() > 0) {
        List<ReleaseId> depReleaseIds = new ArrayList<ReleaseId>();
        for (String dep : dependencies) {
            String[] gav = dep.split(":");
            if (gav.length != 3) {
                throw new IllegalArgumentException("Dependendency id '" + dep + "' does not conform to the format <groupId>:<artifactId>:<version> (Classifiers are not accepted).");
            }
            depReleaseIds.add(new ReleaseIdImpl(gav[0], gav[1], gav[2]));
        }
        releaseIds = depReleaseIds.toArray(new ReleaseId[depReleaseIds.size()]);
    }
    config.pomText = getPomText(releaseId, releaseIds);
    KieFileSystem kfs = createKieFileSystemWithKProject(kbaseName, ksessionName);
    kfs.writePomXML(this.config.pomText);
    List<KJarResource> resourceFiles = loadResources(resourceFilePaths);
    for (KJarResource resource : resourceFiles) {
        kfs.write("src/main/resources/" + kbaseName + "/" + resource.name, resource.content);
    }
    if (classes != null) {
        for (Class<?> userClass : classes) {
            addClass(userClass, kfs);
        }
    }
    KieBuilder kieBuilder = config.getKieServicesInstance().newKieBuilder(kfs);
    int buildMsgs = 0;
    for (Message buildMsg : kieBuilder.buildAll().getResults().getMessages()) {
        System.out.println(buildMsg.getPath() + " : " + buildMsg.getText());
        ++buildMsgs;
    }
    if (buildMsgs > 0) {
        throw new RuntimeException("Unable to build KieModule, see the " + buildMsgs + " messages above.");
    }
    return (InternalKieModule) kieBuilder.getKieModule();
}
Also used : ReleaseIdImpl(org.drools.compiler.kproject.ReleaseIdImpl) KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) ArrayList(java.util.ArrayList) ReleaseId(org.kie.api.builder.ReleaseId) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 15 with Message

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

the class GuidedScoreCardIntegrationJavaClassesOnClassPathTest method testIncrementalCompilation.

@Test
public void testIncrementalCompilation() throws Exception {
    String xml1_1 = Helper.createEmptyGuidedScoreCardXML();
    String xml1_2 = Helper.createGuidedScoreCardXML();
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write("pom.xml", Helper.getPom());
    kfs.write("src/main/resources/META-INF/kmodule.xml", Helper.getKModule());
    kfs.write("src/main/resources/sc1.scgd", xml1_1);
    // Add empty Score Card
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    final List<Message> messages = kieBuilder.getResults().getMessages();
    Helper.dumpMessages(messages);
    assertEquals(0, messages.size());
    // Update with complete Score Card
    kfs.write("src/main/resources/sc1.scgd", xml1_2);
    IncrementalResults results = ((InternalKieBuilder) kieBuilder).incrementalBuild();
    final List<Message> addedMessages = results.getAddedMessages();
    final List<Message> removedMessages = results.getRemovedMessages();
    Helper.dumpMessages(addedMessages);
    assertEquals(0, addedMessages.size());
    Helper.dumpMessages(removedMessages);
    assertEquals(0, removedMessages.size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieServices(org.kie.api.KieServices) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Aggregations

Message (org.kie.api.builder.Message)33 KieBuilder (org.kie.api.builder.KieBuilder)30 KieFileSystem (org.kie.api.builder.KieFileSystem)26 Test (org.junit.Test)21 KieServices (org.kie.api.KieServices)19 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)10 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)7 KieBase (org.kie.api.KieBase)6 ReleaseId (org.kie.api.builder.ReleaseId)5 KieModule (org.kie.api.builder.KieModule)4 KieModuleModel (org.kie.api.builder.model.KieModuleModel)4 IncrementalResults (org.kie.internal.builder.IncrementalResults)4 Before (org.junit.Before)3 Resource (org.kie.api.io.Resource)3 KieSession (org.kie.api.runtime.KieSession)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)1 MavenRepository (org.appformer.maven.integration.MavenRepository)1 MavenRepository.getMavenRepository (org.appformer.maven.integration.MavenRepository.getMavenRepository)1