use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieRepositoryScannerTest method createKieJarWithJavaClass.
private InternalKieModule createKieJarWithJavaClass(KieServices ks, ReleaseId releaseId, String kbaseName, int factor) throws IOException {
String drl = "package org.kie.test.drl\n" + "import org.kie.test.Bean\n" + "global java.util.List list\n" + "rule R1\n" + "when\n" + " $b : Bean( value > 0 )\n" + "then\n" + " list.add( $b.getValue() );\n" + "end\n";
KieFileSystem kfs = createKieFileSystemWithKProject(ks, false, kbaseName, "KSession1");
kfs.writePomXML(getPom(releaseId));
kfs.write("src/main/resources/KBase1/rule1.drl", drl).write("src/main/java/org/kie/test/Bean.java", createJavaSource(factor));
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
assertTrue(kieBuilder.buildAll().getResults().getMessages().isEmpty());
return (InternalKieModule) kieBuilder.getKieModule();
}
use of org.kie.api.builder.KieBuilder 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);
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieRepositoryScannerTest method createKieJarWithType.
private InternalKieModule createKieJarWithType(KieServices ks, ReleaseId releaseId) throws IOException {
KieFileSystem kfs = createKieFileSystemWithKProject(ks);
kfs.write("src/main/resources/KBase1/r1.drl", "package org.kie.test\n" + getDRLWithType());
kfs.writePomXML(getPom(releaseId));
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
assertTrue(kieBuilder.buildAll().getResults().getMessages().isEmpty());
return (InternalKieModule) kieBuilder.getKieModule();
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieScannerIncrementalCompilationTest method createKieJarWithClass.
private InternalKieModule createKieJarWithClass(KieServices ks, ReleaseId releaseId, int value, boolean useJavaInDrl) throws IOException {
KieFileSystem kfs = createKieFileSystemWithKProject(ks, false);
kfs.writePomXML(getPom(releaseId));
if (useJavaInDrl) {
kfs.write("src/main/resources/KBase1/rule1.drl", createDRLForJavaSource());
} else {
kfs.write("src/main/resources/KBase1/rule1.drl", createDRLNotUsingJava(value));
}
kfs.write("src/main/java/org/kie/test/Value.java", createJavaSource(value));
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
assertTrue("", kieBuilder.buildAll().getResults().getMessages().isEmpty());
return (InternalKieModule) kieBuilder.getKieModule();
}
use of org.kie.api.builder.KieBuilder 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();
}
Aggregations