use of org.drools.compiler.kie.util.KieJarChangeSet in project drools by kiegroup.
the class CanonicalKieModule method findChanges.
private KieJarChangeSet findChanges(InternalKieModule newKieModule) {
KieJarChangeSet result = new KieJarChangeSet();
Collection<String> oldFiles = getFileNames();
Collection<String> newFiles = newKieModule.getFileNames();
ArrayList<String> removedFiles = new ArrayList<>(oldFiles);
removedFiles.removeAll(newFiles);
if (!removedFiles.isEmpty()) {
for (String file : removedFiles) {
if (isChange(file, this)) {
result.removeFile(file);
}
}
}
for (String file : newFiles) {
if (oldFiles.contains(file) && isChange(file, this)) {
// check for modification
if (isClassChanged(newKieModule, file)) {
// parse the file to figure out the difference
result.registerChanges(file, new ResourceChangeSet(file, ChangeType.UPDATED));
}
} else if (isChange(file, ((CanonicalKieModule) newKieModule))) {
// file was added
result.addFile(file);
}
}
return result;
}
use of org.drools.compiler.kie.util.KieJarChangeSet in project drools by kiegroup.
the class CanonicalKieModule method getChanges.
@Override
public KieJarChangeSet getChanges(InternalKieModule newKieModule) {
KieJarChangeSet result = findChanges(newKieModule);
Map<String, Model> oldModels = getModels();
Map<String, Model> newModels = ((CanonicalKieModule) newKieModule).getModels();
for (Map.Entry<String, Model> entry : oldModels.entrySet()) {
Model newModel = newModels.get(entry.getKey());
if (newModel == null) {
result.registerChanges(entry.getKey(), buildAllItemsChangeSet(entry.getValue(), ChangeType.REMOVED));
continue;
}
Model oldModel = entry.getValue();
for (ResourceChangeSet changeSet : calculateResourceChangeSet(oldModel, newModel)) {
if (!changeSet.getChanges().isEmpty()) {
result.registerChanges(entry.getKey(), changeSet);
}
}
}
for (Map.Entry<String, Model> entry : newModels.entrySet()) {
if (oldModels.get(entry.getKey()) == null) {
result.registerChanges(entry.getKey(), buildAllItemsChangeSet(entry.getValue(), ChangeType.ADDED));
}
}
KieJarChangeSet internalChanges = internalKieModule.getChanges(((CanonicalKieModule) newKieModule).internalKieModule);
internalChanges.removeFile(getProjectModelResourceName());
return result.merge(internalChanges);
}
use of org.drools.compiler.kie.util.KieJarChangeSet in project drools by kiegroup.
the class ChangeSetBuilderTest method testRuleRemoval.
@Test
public void testRuleRemoval() throws Exception {
String drl1 = "package org.drools.mvel.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.drools.compiler.kie.util.KieJarChangeSet in project drools by kiegroup.
the class ChangeSetBuilderTest method testNoChanges.
@Test
public void testNoChanges() {
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, drl2);
KieJarChangeSet changes = ChangeSetBuilder.build(kieJar1, kieJar2);
assertThat(changes.getChanges().size(), is(0));
}
Aggregations