Search in sources :

Example 1 with ProjectClassLoader

use of org.drools.core.common.ProjectClassLoader in project drools by kiegroup.

the class CanonicalKieModule method createKieBase.

@Override
public InternalKnowledgeBase createKieBase(KieBaseModelImpl kBaseModel, KieProject kieProject, ResultsImpl messages, KieBaseConfiguration conf) {
    this.moduleClassLoader = ((ProjectClassLoader) kieProject.getClassLoader());
    KieBaseConfiguration kBaseConf = getKieBaseConfiguration(kBaseModel, moduleClassLoader, conf);
    CanonicalKiePackages kpkgs = pkgsInKbase.computeIfAbsent(kBaseModel.getName(), k -> createKiePackages(kBaseModel, kBaseConf));
    return new KieBaseBuilder(kBaseModel, kBaseConf).createKieBase(kpkgs);
}
Also used : ProjectClassLoader(org.drools.core.common.ProjectClassLoader) KieBaseConfiguration(org.kie.api.KieBaseConfiguration) KieBaseBuilder(org.drools.modelcompiler.builder.KieBaseBuilder)

Example 2 with ProjectClassLoader

use of org.drools.core.common.ProjectClassLoader in project drools by kiegroup.

the class ScenarioRunner4JUnitTest method setUp.

@Before
public void setUp() throws Exception {
    ksession = mock(StatefulKnowledgeSessionImpl.class);
    KnowledgeBaseImpl knowledgeBase = mock(KnowledgeBaseImpl.class);
    when(ksession.getKieBase()).thenReturn(knowledgeBase);
    ProjectClassLoader classLoader = ProjectClassLoader.createProjectClassLoader();
    when(knowledgeBase.getRootClassLoader()).thenReturn(classLoader);
}
Also used : ProjectClassLoader(org.drools.core.common.ProjectClassLoader) StatefulKnowledgeSessionImpl(org.drools.core.impl.StatefulKnowledgeSessionImpl) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) Before(org.junit.Before)

Example 3 with ProjectClassLoader

use of org.drools.core.common.ProjectClassLoader in project drools by kiegroup.

the class ScenarioRunnerTest method setUp.

@Before
public void setUp() throws Exception {
    ksession = mock(KieSession.class);
    KnowledgeBaseImpl knowledgeBase = mock(KnowledgeBaseImpl.class);
    when(ksession.getKieBase()).thenReturn(knowledgeBase);
    ProjectClassLoader classLoader = ProjectClassLoader.createProjectClassLoader();
    when(knowledgeBase.getRootClassLoader()).thenReturn(classLoader);
}
Also used : ProjectClassLoader(org.drools.core.common.ProjectClassLoader) KieSession(org.kie.api.runtime.KieSession) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) Before(org.junit.Before)

Example 4 with ProjectClassLoader

use of org.drools.core.common.ProjectClassLoader in project drools by kiegroup.

the class PersisterHelper method loadStrategiesIndex.

private static void loadStrategiesIndex(MarshallerReaderContext context, ProtobufMessages.Header _header) throws IOException, ClassNotFoundException {
    for (ProtobufMessages.Header.StrategyIndex _entry : _header.getStrategyList()) {
        ObjectMarshallingStrategy strategyObject = context.resolverStrategyFactory.getStrategyObject(_entry.getName());
        if (strategyObject == null) {
            throw new IllegalStateException("No strategy of type " + _entry.getName() + " available.");
        }
        context.usedStrategies.put(_entry.getId(), strategyObject);
        Context ctx = strategyObject.createContext();
        context.strategyContexts.put(strategyObject, ctx);
        if (_entry.hasData() && ctx != null) {
            ClassLoader classLoader = null;
            if (context.classLoader != null) {
                classLoader = context.classLoader;
            } else if (context.kBase != null) {
                classLoader = context.kBase.getRootClassLoader();
            }
            if (classLoader instanceof ProjectClassLoader) {
                readRuntimeDefinedClasses(_header, (ProjectClassLoader) classLoader);
            }
            ctx.read(new DroolsObjectInputStream(_entry.getData().newInput(), classLoader));
        }
    }
}
Also used : Context(org.kie.api.marshalling.ObjectMarshallingStrategy.Context) ProjectClassLoader(org.drools.core.common.ProjectClassLoader) DroolsObjectInputStream(org.drools.core.common.DroolsObjectInputStream) Header(org.drools.core.marshalling.impl.ProtobufMessages.Header) ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) ProjectClassLoader(org.drools.core.common.ProjectClassLoader)

Example 5 with ProjectClassLoader

use of org.drools.core.common.ProjectClassLoader in project drools by kiegroup.

the class StandaloneTest method init.

@Before
public void init() {
    ProjectClassLoader loader = ProjectClassLoader.createProjectClassLoader();
    factory = new StandaloneTraitFactory(loader);
}
Also used : ProjectClassLoader(org.drools.core.common.ProjectClassLoader) StandaloneTraitFactory(org.drools.core.util.StandaloneTraitFactory) Before(org.junit.Before)

Aggregations

ProjectClassLoader (org.drools.core.common.ProjectClassLoader)13 Before (org.junit.Before)3 ArrayList (java.util.ArrayList)2 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)2 ByteString (com.google.protobuf.ByteString)1 XStream (com.thoughtworks.xstream.XStream)1 ExplicitTypePermission (com.thoughtworks.xstream.security.ExplicitTypePermission)1 IOException (java.io.IOException)1 ObjectInput (java.io.ObjectInput)1 ObjectOutput (java.io.ObjectOutput)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 DialectConfiguration (org.drools.compiler.compiler.DialectConfiguration)1 KieContainerImpl (org.drools.compiler.kie.builder.impl.KieContainerImpl)1 KieProject (org.drools.compiler.kie.builder.impl.KieProject)1 ResultsImpl (org.drools.compiler.kie.builder.impl.ResultsImpl)1 DroolsCompilerComponentFactory (org.drools.compiler.rule.builder.DroolsCompilerComponentFactory)1