Search in sources :

Example 6 with KieJarChangeSet

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;
}
Also used : KieJarChangeSet(org.drools.compiler.kie.util.KieJarChangeSet) ArrayList(java.util.ArrayList) ResourceChangeSet(org.kie.internal.builder.ResourceChangeSet)

Example 7 with KieJarChangeSet

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);
}
Also used : KieJarChangeSet(org.drools.compiler.kie.util.KieJarChangeSet) ModelComponent.areEqualInModel(org.drools.model.impl.ModelComponent.areEqualInModel) KieBaseModel(org.kie.api.builder.model.KieBaseModel) PomModel(org.kie.util.maven.support.PomModel) Model(org.drools.model.Model) KieModuleModel(org.kie.api.builder.model.KieModuleModel) ResourceChangeSet(org.kie.internal.builder.ResourceChangeSet) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 8 with KieJarChangeSet

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());
}
Also used : KieJarChangeSet(org.drools.compiler.kie.util.KieJarChangeSet) ResourceChangeSet(org.kie.internal.builder.ResourceChangeSet) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) Test(org.junit.Test)

Example 9 with KieJarChangeSet

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));
}
Also used : KieJarChangeSet(org.drools.compiler.kie.util.KieJarChangeSet) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) Test(org.junit.Test)

Aggregations

KieJarChangeSet (org.drools.compiler.kie.util.KieJarChangeSet)9 ResourceChangeSet (org.kie.internal.builder.ResourceChangeSet)7 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 KieBaseModel (org.kie.api.builder.model.KieBaseModel)3 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 KieBaseModelImpl (org.drools.compiler.kproject.models.KieBaseModelImpl)2 KieBase (org.kie.api.KieBase)2 ResourceChange (org.kie.internal.builder.ResourceChange)2 InputStream (java.io.InputStream)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 UUID (java.util.UUID)1