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"));
}
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.");
}
}
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);
}
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();
}
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());
}
Aggregations