// have to save for later removal to avoid iteration errors
kbasesToRemove.add( kbaseName );
} else {
// attaching the builder to the kbase
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder((KnowledgeBase) kBaseEntry.getValue());
KnowledgeBuilderImpl pkgbuilder = (KnowledgeBuilderImpl)kbuilder;
CompositeKnowledgeBuilder ckbuilder = kbuilder.batch();
boolean modifyingUsedClass = false;
for (String modifiedClass : modifiedClasses) {
if ( pkgbuilder.isClassInUse( convertResourceToClassName(modifiedClass) ) ) {
modifyingUsedClass = true;
break;
}
}
boolean shouldRebuild = modifyingUsedClass;
if (modifyingUsedClass) {
// there are modified classes used by this kbase, so it has to be completely updated
updateAllResources(currentKM, newKM, kieBaseModel, pkgbuilder, ckbuilder);
} else {
// there are no modified classes used by this kbase, so update it incrementally
shouldRebuild = updateResourcesIncrementally(currentKM, newKM, cs, modifiedClasses, kBaseEntry,
kieBaseModel, pkgbuilder, ckbuilder) > 0;
}
pkgbuilder.startPackageUpdate();
try {
// remove resources first
for ( ResourceChangeSet rcs : cs.getChanges().values() ) {
if ( rcs.getChangeType() == ChangeType.REMOVED ) {
String resourceName = rcs.getResourceName();
if ( !resourceName.endsWith( ".properties" ) && isFileInKBase(newKM, kieBaseModel, resourceName) ) {
pkgbuilder.removeObjectsGeneratedFromResource( currentKM.getResource( resourceName ) );
}
}
}
if ( shouldRebuild ) {
rebuildAll(newReleaseId, results, newKM, modifiedClasses, kieBaseModel, pkgbuilder, ckbuilder);
}
} finally {
pkgbuilder.completePackageUpdate();
}
}
}
for (String kbaseToRemove : kbasesToRemove) {