Package org.kie.internal.builder

Examples of org.kie.internal.builder.CompositeKnowledgeBuilder


                        "then\n" +
                        "  list.add( $i + $j );\n" +
                        "end\n";

        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
        CompositeKnowledgeBuilder ckb = kbuilder.batch();

        ckb.add( ResourceFactory.newByteArrayResource( str3.getBytes() ), ResourceType.DRL )
                .add( ResourceFactory.newByteArrayResource( str1.getBytes() ), ResourceType.DRL )
                .add( ResourceFactory.newByteArrayResource( str2.getBytes() ), ResourceType.DRL )
                .build();

        assertTrue( kbuilder.hasErrors() );
View Full Code Here


        PackageBuilderConfiguration pconf = new PackageBuilderConfiguration(kieProject.getClonedClassLoader());
        pconf.setCompilationCache(kModule.getCompilationCache(kBaseModel.getName()));

        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(pconf);
        CompositeKnowledgeBuilder ckbuilder = kbuilder.batch();

        Map<String, InternalKieModule> assets = new HashMap<String, InternalKieModule>();

        for (String include : getTransitiveIncludes(kieProject, kBaseModel)) {
            if (StringUtils.isEmpty(include)) {
                continue;
            }
            InternalKieModule includeModule = kieProject.getKieModuleForKBase(include);
            if (includeModule == null) {
                log.error("Unable to build KieBase, could not find include: " + include);
                return null;
            }
            addFiles(assets,
                    kieProject.getKieBaseModel(include),
                    includeModule);
        }

        addFiles(assets,
                kBaseModel,
                kModule);

        if (assets.isEmpty()) {
            if (kModule instanceof FileKieModule) {
                log.warn("No files found for KieBase " + kBaseModel.getName() + ", searching folder " + kModule.getFile());
            } else {
                log.warn("No files found for KieBase " + kBaseModel.getName());
            }
        } else {
            for (Map.Entry<String, InternalKieModule> entry : assets.entrySet()) {
                addFile(ckbuilder, entry.getValue(), entry.getKey());
            }
        }

        ckbuilder.build();

        if (kbuilder.hasErrors()) {
            for (KnowledgeBuilderError error : kbuilder.getErrors()) {
                messages.addMessage(error);
            }
View Full Code Here

                kbasesToRemove.add( kbaseName );
            } else {
                // attaching the builder to the kbase
                KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder( (KnowledgeBase) kBaseEntry.getValue() );
                PackageBuilder pkgbuilder = kbuilder instanceof PackageBuilder ? ((PackageBuilder) kbuilder) : ((KnowledgeBuilderImpl)kbuilder).getPackageBuilder();
                CompositeKnowledgeBuilder ckbuilder = kbuilder.batch();
                int fileCount = 0;
               
                // remove resources first
                for( ResourceChangeSet rcs : cs.getChanges().values() ) {
                    if( rcs.getChangeType().equals( ChangeType.REMOVED ) ) {
                        String resourceName = rcs.getResourceName();
                        if( KieBuilderImpl.filterFileInKBase( kieBaseModel, resourceName ) && ! resourceName.endsWith( ".properties" ) ) {
                            pkgbuilder.removeObjectsGeneratedFromResource( currentKM.getResource( resourceName ) );
                        }
                    }
                }
               
                // then update and add new resources
                for( ResourceChangeSet rcs : cs.getChanges().values() ) {
                    if( ! rcs.getChangeType().equals( ChangeType.REMOVED ) ) {
                        String resourceName = rcs.getResourceName();
                        if( KieBuilderImpl.filterFileInKBase( kieBaseModel, resourceName ) && ! resourceName.endsWith( ".properties" ) ) {
                            fileCount += AbstractKieModule.addFile( ckbuilder,
                                                                    newKM,
                                                                    resourceName ) ? 1 : 0;
                        }
                    }
                }
                if( fileCount > 0 ) {
                    ckbuilder.build();
                }
            }
        }

        for (String kbaseToRemove : kbasesToRemove) {
View Full Code Here

                kbasesToRemove.add( kbaseName );
            } else {
                // attaching the builder to the kbase
                KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder( (KnowledgeBase) kBaseEntry.getValue() );
                PackageBuilder pkgbuilder = kbuilder instanceof PackageBuilder ? ((PackageBuilder) kbuilder) : ((KnowledgeBuilderImpl)kbuilder).getPackageBuilder();
                CompositeKnowledgeBuilder ckbuilder = kbuilder.batch();
                int fileCount = 0;
               
                // remove resources first
                for( ResourceChangeSet rcs : cs.getChanges().values() ) {
                    if( rcs.getChangeType().equals( ChangeType.REMOVED ) ) {
                        String resourceName = rcs.getResourceName();
                        if( KieBuilderImpl.filterFileInKBase( kieBaseModel, resourceName ) && ! resourceName.endsWith( ".properties" ) ) {
                            pkgbuilder.removeObjectsGeneratedFromResource( currentKM.getResource( resourceName ) );
                        }
                    }
                }
               
                // then update and add new resources
                for( ResourceChangeSet rcs : cs.getChanges().values() ) {
                    if( ! rcs.getChangeType().equals( ChangeType.REMOVED ) ) {
                        String resourceName = rcs.getResourceName();
                        if( KieBuilderImpl.filterFileInKBase( kieBaseModel, resourceName ) && ! resourceName.endsWith( ".properties" ) ) {
                            fileCount += AbstractKieModule.addFile( ckbuilder,
                                                                    newKM,
                                                                    resourceName ) ? 1 : 0;
                        }
                    }
                }
                if( fileCount > 0 ) {
                    ckbuilder.build();
                }
            }
        }

        for (String kbaseToRemove : kbasesToRemove) {
View Full Code Here

        PackageBuilderConfiguration pconf = new PackageBuilderConfiguration(kieProject.getClonedClassLoader());
        pconf.setCompilationCache(kModule.getCompilationCache(kBaseModel.getName()));

        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(pconf);
        CompositeKnowledgeBuilder ckbuilder = kbuilder.batch();

        Map<String, InternalKieModule> assets = new HashMap<String, InternalKieModule>();

        for (String include : getTransitiveIncludes(kieProject, kBaseModel)) {
            if (StringUtils.isEmpty(include)) {
                continue;
            }
            InternalKieModule includeModule = kieProject.getKieModuleForKBase(include);
            if (includeModule == null) {
                log.error("Unable to build KieBase, could not find include: " + include);
                return null;
            }
            addFiles(assets,
                    kieProject.getKieBaseModel(include),
                    includeModule);
        }

        addFiles(assets,
                kBaseModel,
                kModule);

        if (assets.isEmpty()) {
            if (kModule instanceof FileKieModule) {
                log.warn("No files found for KieBase " + kBaseModel.getName() + ", searching folder " + kModule.getFile());
            } else {
                log.warn("No files found for KieBase " + kBaseModel.getName());
            }
        } else {
            for (Map.Entry<String, InternalKieModule> entry : assets.entrySet()) {
                addFile(ckbuilder, entry.getValue(), entry.getKey());
            }
        }

        ckbuilder.build();

        if (kbuilder.hasErrors()) {
            for (KnowledgeBuilderError error : kbuilder.getErrors()) {
                messages.addMessage(error);
            }
View Full Code Here

        List<KnowledgeBuilderError> currentErrors = new ArrayList<KnowledgeBuilderError>();

        InternalKieModule kieModule = (InternalKieModule) kieBuilder.getKieModuleIgnoringErrors();
        for (KieBaseModel kBaseModel : kieModule.getKieModuleModel().getKieBaseModels().values()) {
            KnowledgeBuilder kBuilder = kieModule.getKnowledgeBuilderForKieBase( kBaseModel.getName() );
            CompositeKnowledgeBuilder ckbuilder = kBuilder.batch();

            PackageBuilder pkgBuilder = ((KnowledgeBuilderImpl)kBuilder).getPackageBuilder();
            Set<String> wrongResources = resourcesWithErrors.get(kBaseModel.getName());
            for ( String resourceName : wrongResources ) {
                pkgBuilder.removeObjectsGeneratedFromResource(new DummyResource(resourceName));
                addResource(ckbuilder, kBaseModel, kieModule, resourceName);
            }

            boolean modified = false;
            for (String file : files) {
                String resourceName = file.startsWith(KieBuilderImpl.RESOURCES_ROOT) ?
                        file.substring(KieBuilderImpl.RESOURCES_ROOT.length()) :
                        file;

                if ( wrongResources.contains(resourceName) ) {
                    modified = true;
                } else {
                    // remove the objects generated by the old Resource
                    modified = pkgBuilder.removeObjectsGeneratedFromResource(new DummyResource(resourceName)) || modified;
                    // add the modified Resource
                    modified = addResource(ckbuilder, kBaseModel, kieModule, resourceName) || modified;
                }
            }

            if (modified) {
                ckbuilder.build();
                resourcesWithErrors.put(kBaseModel.getName(), findResourcesWithErrors(kBuilder));
                if ( kBuilder.hasErrors() ) {
                    currentErrors.addAll(kBuilder.getErrors());
                    kBuilder.undo();
                } else {
View Full Code Here

        List<KnowledgeBuilderError> currentErrors = new ArrayList<KnowledgeBuilderError>();

        InternalKieModule kieModule = (InternalKieModule) kieBuilder.getKieModuleIgnoringErrors();
        for (KieBaseModel kBaseModel : kieModule.getKieModuleModel().getKieBaseModels().values()) {
            KnowledgeBuilder kBuilder = kieModule.getKnowledgeBuilderForKieBase( kBaseModel.getName() );
            CompositeKnowledgeBuilder ckbuilder = kBuilder.batch();

            boolean modified = false;
            PackageBuilder pkgBuilder = ((KnowledgeBuilderImpl)kBuilder).getPackageBuilder();
            Set<String> wrongResources = resourcesWithErrors.get(kBaseModel.getName());
            for ( String resourceName : wrongResources ) {
                modified = pkgBuilder.removeObjectsGeneratedFromResource(new DummyResource(resourceName)) || modified;
                modified = addResource(ckbuilder, kBaseModel, kieModule, resourceName) || modified;
            }

            for (String file : filesToBuild) {
                if ( wrongResources.contains(file) ) {
                    modified = true;
                } else {
                    // remove the objects generated by the old Resource
                    modified = pkgBuilder.removeObjectsGeneratedFromResource(new DummyResource(file)) || modified;
                    // add the modified Resource
                    modified = addResource(ckbuilder, kBaseModel, kieModule, file) || modified;
                }
            }

            if (modified) {
                ckbuilder.build();
                resourcesWithErrors.put(kBaseModel.getName(), findResourcesWithErrors(kBuilder));
                if ( kBuilder.hasErrors() ) {
                    currentErrors.addAll(kBuilder.getErrors());
                    kBuilder.undo();
                } else {
View Full Code Here

                kbasesToRemove.add( kbaseName );
            } else {
                // attaching the builder to the kbase
                KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder( (KnowledgeBase) kBaseEntry.getValue() );
                PackageBuilder pkgbuilder = kbuilder instanceof PackageBuilder ? ((PackageBuilder) kbuilder) : ((KnowledgeBuilderImpl)kbuilder).getPackageBuilder();
                CompositeKnowledgeBuilder ckbuilder = kbuilder.batch();
                List<String> modifiedClasses = new ArrayList<String>();
                int fileCount = 0;

                // then update and add new resources
                for ( ResourceChangeSet rcs : cs.getChanges().values() ) {
                    if ( rcs.getChangeType() != ChangeType.REMOVED ) {
                        String resourceName = rcs.getResourceName();
                        if ( !resourceName.endsWith( ".properties" ) && filterFileInKBase(newKM, kieBaseModel, resourceName) ) {
                            Resource resource = currentKM.getResource(resourceName);
                            List<ResourceChange> changes = rcs.getChanges();
                            if ( ! changes.isEmpty() ) {
                                // we need to deal with individual parts of the resource
                                fileCount += AbstractKieModule.updateResource( ckbuilder,
                                                                               newKM,
                                                                               resourceName,
                                                                               rcs ) ? 1 : 0;
                            } else {
                                // the whole resource has to handled
                                if( rcs.getChangeType() == ChangeType.UPDATED ) {
                                    pkgbuilder.removeObjectsGeneratedFromResource( resource );
                                }
                                fileCount += newKM.addResourceToCompiler(ckbuilder, resourceName) ? 1 : 0;
                            }
                        } else if ( resourceName.endsWith( ".class" ) ) {
                            modifiedClasses.add(resourceName);
                            fileCount++;
                        }
                    }

                    KieBase kBase = kBaseEntry.getValue();
                    for ( ResourceChangeSet.RuleLoadOrder loadOrder : rcs.getLoadOrder() ) {
                        Rule rule = (Rule) ((KnowledgePackageImp)kBase.getKiePackage( loadOrder.getPkgName() )).getRule( loadOrder.getRuleName() );
                        if ( rule != null ) {
                            // rule can be null, if it didn't exist before
                            rule.setLoadOrder( loadOrder.getLoadOrder() );
                        }
                    }
                }

                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" ) && filterFileInKBase(newKM, kieBaseModel, resourceName) ) {
                                pkgbuilder.removeObjectsGeneratedFromResource( currentKM.getResource( resourceName ) );
                            }
                        }
                    }

                    if( fileCount > 0 ) {
                        Set<String> modifiedPackages = new HashSet<String>();
                        if (!modifiedClasses.isEmpty()) {
                            ClassLoader rootClassLoader = pkgbuilder.getRootClassLoader();
                            if ( rootClassLoader instanceof ProjectClassLoader ) {
                                ProjectClassLoader projectClassLoader = (ProjectClassLoader) rootClassLoader;
                                projectClassLoader.reinitTypes();
                                for (String resourceName : modifiedClasses) {
                                    String className = convertResourceToClassName( resourceName );
                                    byte[] bytes = newKM.getBytes(resourceName);
                                    Class<?> clazz = projectClassLoader.defineClass(className, resourceName, bytes);
                                    modifiedPackages.add(clazz.getPackage().getName());
                                }
                                pkgbuilder.setAllRuntimesDirty(modifiedPackages);
                            }
                        }

                        ckbuilder.build();

                        PackageBuilderErrors errors = pkgbuilder.getErrors();
                        if ( !errors.isEmpty() ) {
                            for ( KnowledgeBuilderError error : errors.getErrors() ) {
                                results.addMessage(error);
View Full Code Here

        PackageBuilderConfiguration pconf = new PackageBuilderConfiguration(kieProject.getClonedClassLoader());
        pconf.setCompilationCache(kModule.getCompilationCache(kBaseModel.getName()));

        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(pconf);
        CompositeKnowledgeBuilder ckbuilder = kbuilder.batch();

        Map<String, InternalKieModule> assets = new HashMap<String, InternalKieModule>();

        for (String include : getTransitiveIncludes(kieProject, kBaseModel)) {
            if (StringUtils.isEmpty(include)) {
                continue;
            }
            InternalKieModule includeModule = kieProject.getKieModuleForKBase(include);
            if (includeModule == null) {
                log.error("Unable to build KieBase, could not find include: " + include);
                return null;
            }
            addFiles(assets,
                    kieProject.getKieBaseModel(include),
                    includeModule);
        }

        addFiles(assets,
                kBaseModel,
                kModule);

        if (assets.isEmpty()) {
            if (kModule instanceof FileKieModule) {
                log.warn("No files found for KieBase " + kBaseModel.getName() + ", searching folder " + kModule.getFile());
            } else {
                log.warn("No files found for KieBase " + kBaseModel.getName());
            }
        } else {
            for (Map.Entry<String, InternalKieModule> entry : assets.entrySet()) {
                entry.getValue().addResourceToCompiler(ckbuilder, entry.getKey());
            }
        }

        ckbuilder.build();

        if (kbuilder.hasErrors()) {
            for (KnowledgeBuilderError error : kbuilder.getErrors()) {
                messages.addMessage(error);
            }
View Full Code Here

        return Collections.emptyList();
    }

  private KnowledgeBuilder compositeBuild(List<ResourceDescr> resources, Map<Resource, ResourceDescr> resourceMap) throws CoreException {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(getBuilderConfiguration(resources));
    CompositeKnowledgeBuilder compositeKBuilder = kbuilder.batch();
    for (ResourceDescr resourceDescr : resources) {
      Resource resource = resourceDescr.getContentAsDroolsResource();
      resourceMap.put(resource, resourceDescr);
      compositeKBuilder.add(resource, resourceDescr.getType());
    }
    try {
      compositeKBuilder.build();
    } catch (DecisionTableParseException dtpe) {
      // swallow
    }
    return kbuilder;
  }
View Full Code Here

TOP

Related Classes of org.kie.internal.builder.CompositeKnowledgeBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.