Hi,

With new Kie API, the way that we build KieBuilder, Session, KieBase is a bit different as we did before.

We can now create a KieFileSystem, add resources (drl, ....) and create a KieBuilder from the KieSystem

        KieFileSystem kfs = kieServices.newKieFileSystem()
                .write("src/main/resources/temp.drl", packages)
                .writeKModuleXML(createKieProjectWithPackages(kieServices).toXML());

        kieBuilder = kieServices.newKieBuilder(kfs).buildAll();

That works fine for Java standalone projects (or in a JEE container or Web Container (Tomcat, Jetty) - I hope ?) but not in a OSGI environment.

In consequence the following step fails in my code :

kieServices.newKieContainer(kieServices.getRepository().getDefaultReleaseId()).newKieSession();

Caused by: java.lang.RuntimeException: Cannot find KieModule: org.default:artifact:1.0.0-SNAPSHOT
at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:75)

as getKieModule(ReleaseId releaseId, byte[] pomXml) return null

The following code should be imporved as until now we don't check classpath

    public KieModule getKieModule(ReleaseId releaseId, byte[] pomXml) {
        VersionRange versionRange = new VersionRange(releaseId.getVersion());

        KieModule kieModule = kieModuleRepo.load(releaseId, versionRange);
        if ( kieModule == null ) {
            log.debug( "KieModule Lookup. ReleaseId {} was not in cache, checking classpath",
                    releaseId.toExternalForm() );
            kieModule = checkClasspathForKieModule(releaseId);
        }

        if ( kieModule == null ) {
            log.debug( "KieModule Lookup. ReleaseId {} was not in cache, checking maven repository",
                    releaseId.toExternalForm() );
            kieModule =
loadKieModuleFromMavenRepo
loadKieModuleFromMavenRepo(releaseId, pomXml);
        }

        return kieModule;
    }

and loadKieModuleFromMavenRepo() does not find the resource as it has been created from scratch

Regards,

--
Charles Moulliard
Apache Committer / Sr. Enterprise Architect (RedHat)
Twitter : @cmoulliard | Blog : http://cmoulliard.blogspot.com