use of org.kie.internal.builder.ResourceChangeSet in project drools by kiegroup.
the class ChangeSetBuilderTest method testRemoved.
@Test
public void testRemoved() {
String drl1 = "package org.drools\n" + "rule R1 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
String drl2 = "package org.drools\n" + "rule R2 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
InternalKieModule kieJar1 = createKieJar(drl1, drl2);
InternalKieModule kieJar2 = createKieJar(drl1);
KieJarChangeSet changes = ChangeSetBuilder.build(kieJar1, kieJar2);
String removedFile = (String) kieJar1.getFileNames().toArray()[1];
assertThat(changes.getChanges().size(), is(1));
ResourceChangeSet cs = changes.getChanges().get(removedFile);
assertThat(cs, not(nullValue()));
assertThat(cs.getChangeType(), is(ChangeType.REMOVED));
}
use of org.kie.internal.builder.ResourceChangeSet in project drools by kiegroup.
the class ChangeSetBuilderTest method testRuleRemoval.
@Test
public void testRuleRemoval() throws Exception {
String drl1 = "package org.drools.compiler\n" + "rule R1 when\n" + " $m : Message()\n" + "then\n" + "end\n";
String drl2 = "rule R2 when\n" + " $m : Message( message == \"Hi Universe\" )\n" + "then\n" + "end\n";
String drl3 = "rule R3 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
InternalKieModule kieJar1 = createKieJar(drl1 + drl2 + drl3);
InternalKieModule kieJar2 = createKieJar(drl1 + drl3);
KieJarChangeSet changes = ChangeSetBuilder.build(kieJar1, kieJar2);
assertEquals(1, changes.getChanges().size());
ResourceChangeSet rcs = changes.getChanges().values().iterator().next();
assertEquals(1, rcs.getChanges().size());
assertEquals(ChangeType.REMOVED, rcs.getChanges().get(0).getChangeType());
}
use of org.kie.internal.builder.ResourceChangeSet in project drools by kiegroup.
the class KieBaseUpdater method updateResourcesIncrementally.
private int updateResourcesIncrementally(KnowledgeBuilderImpl kbuilder, CompositeKnowledgeBuilder ckbuilder) {
int fileCount = ctx.modifiedClasses.size();
for (ResourceChangeSet rcs : ctx.cs.getChanges().values()) {
if (rcs.getChangeType() != ChangeType.REMOVED) {
String resourceName = rcs.getResourceName();
if (!resourceName.endsWith(".properties") && isFileInKBase(ctx.newKM, ctx.newKieBaseModel, resourceName)) {
List<ResourceChange> changes = rcs.getChanges();
if (!changes.isEmpty()) {
// we need to deal with individual parts of the resource
fileCount += AbstractKieModule.updateResource(ckbuilder, ctx.newKM, resourceName, rcs) ? 1 : 0;
} else {
// the whole resource has to handled
if (rcs.getChangeType() == ChangeType.UPDATED) {
Resource resource = ctx.currentKM.getResource(resourceName);
kbuilder.removeObjectsGeneratedFromResource(resource);
}
fileCount += ctx.newKM.addResourceToCompiler(ckbuilder, ctx.newKieBaseModel, resourceName, rcs) ? 1 : 0;
}
}
}
for (ResourceChangeSet.RuleLoadOrder loadOrder : rcs.getLoadOrder()) {
KnowledgePackageImpl pkg = (KnowledgePackageImpl) ctx.kBase.getKiePackage(loadOrder.getPkgName());
if (pkg != null) {
RuleImpl rule = pkg.getRule(loadOrder.getRuleName());
if (rule != null) {
// rule can be null, if it didn't exist before
rule.setLoadOrder(loadOrder.getLoadOrder());
}
}
}
}
return fileCount;
}
use of org.kie.internal.builder.ResourceChangeSet in project drools by kiegroup.
the class KieBaseUpdater method run.
@Override
public void run() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(ctx.kBase, ctx.newKM.getBuilderConfiguration(ctx.newKieBaseModel));
KnowledgeBuilderImpl pkgbuilder = (KnowledgeBuilderImpl) kbuilder;
CompositeKnowledgeBuilder ckbuilder = kbuilder.batch();
boolean shouldRebuild = applyResourceChanges(pkgbuilder, ckbuilder);
// remove resources first
for (ResourceChangeSet rcs : ctx.cs.getChanges().values()) {
if (rcs.getChangeType() == ChangeType.REMOVED) {
String resourceName = rcs.getResourceName();
if (!resourceName.endsWith(".properties") && isFileInKBase(ctx.currentKM, ctx.currentKieBaseModel, resourceName)) {
pkgbuilder.removeObjectsGeneratedFromResource(ctx.currentKM.getResource(resourceName));
}
}
}
// remove all ObjectTypeNodes for the modified classes
if (ctx.modifyingUsedClass) {
for (Class<?> cls : ctx.modifiedClasses) {
clearInstancesOfModifiedClass(cls);
}
}
if (shouldRebuild) {
// readd unchanged dsl files to the kbuilder
for (String dslFile : ctx.unchangedResources) {
if (isFileInKBase(ctx.newKM, ctx.newKieBaseModel, dslFile)) {
ctx.newKM.addResourceToCompiler(ckbuilder, ctx.newKieBaseModel, dslFile);
}
}
rebuildAll(pkgbuilder, ckbuilder);
}
ctx.kBase.setResolvedReleaseId(ctx.newReleaseId);
for (InternalWorkingMemory wm : ctx.kBase.getWorkingMemories()) {
wm.notifyWaitOnRest();
}
}
use of org.kie.internal.builder.ResourceChangeSet in project drools by kiegroup.
the class ChangeSetBuilderTest method testRemoved.
@Test
public void testRemoved() {
String drl1 = "package org.drools\n" + "rule R1 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
String drl2 = "package org.drools\n" + "rule R2 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
InternalKieModule kieJar1 = createKieJar(drl1, drl2);
InternalKieModule kieJar2 = createKieJar(drl1);
KieJarChangeSet changes = ChangeSetBuilder.build(kieJar1, kieJar2);
String removedFile = (String) kieJar1.getFileNames().toArray()[1];
assertThat(changes.getChanges().size(), is(1));
ResourceChangeSet cs = changes.getChanges().get(removedFile);
assertThat(cs, not(nullValue()));
assertThat(cs.getChangeType(), is(ChangeType.REMOVED));
}
Aggregations