Search in sources :

Example 6 with ProjectClassLoader

use of org.drools.wiring.api.classloader.ProjectClassLoader in project drools by kiegroup.

the class HasKnowledgeBuilderImpl method compileAndLoadClass.

/**
 * Compile the given sources and add them to given <code>Classloader</code> of the current instance.
 * Returns the <code>Class</code> with the given <b>fullClassName</b>
 * @param sourcesMap
 * @param fullClassName
 * @return
 */
@Override
public Class<?> compileAndLoadClass(Map<String, String> sourcesMap, String fullClassName) {
    ClassLoader classLoader = getClassLoader();
    if (!(classLoader instanceof ProjectClassLoader)) {
        throw new IllegalStateException("Expected ProjectClassLoader, received " + classLoader.getClass().getName());
    }
    ProjectClassLoader projectClassLoader = (ProjectClassLoader) classLoader;
    final Map<String, byte[]> byteCode = KieMemoryCompiler.compileNoLoad(sourcesMap, projectClassLoader, JavaConfiguration.CompilerType.ECLIPSE);
    byteCode.forEach(projectClassLoader::defineClass);
    try {
        return projectClassLoader.loadClass(fullClassName);
    } catch (Exception e) {
        throw new KiePMMLException(e);
    }
}
Also used : ProjectClassLoader(org.drools.wiring.api.classloader.ProjectClassLoader) ProjectClassLoader(org.drools.wiring.api.classloader.ProjectClassLoader) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException)

Example 7 with ProjectClassLoader

use of org.drools.wiring.api.classloader.ProjectClassLoader in project drools by kiegroup.

the class HasKnowledgeBuilderMock method compileAndLoadClass.

@Override
public Class<?> compileAndLoadClass(Map<String, String> sourcesMap, String fullClassName) {
    ClassLoader classLoader = getClassLoader();
    if (!(classLoader instanceof ProjectClassLoader)) {
        throw new IllegalStateException("Expected ProjectClassLoader, received " + classLoader.getClass().getName());
    }
    ProjectClassLoader projectClassLoader = (ProjectClassLoader) classLoader;
    final Map<String, byte[]> byteCode = KieMemoryCompiler.compileNoLoad(sourcesMap, projectClassLoader);
    byteCode.forEach(projectClassLoader::defineClass);
    try {
        return projectClassLoader.loadClass(fullClassName);
    } catch (Exception e) {
        throw new KiePMMLException(e);
    }
}
Also used : ProjectClassLoader(org.drools.wiring.api.classloader.ProjectClassLoader) ProjectClassLoader(org.drools.wiring.api.classloader.ProjectClassLoader) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException)

Example 8 with ProjectClassLoader

use of org.drools.wiring.api.classloader.ProjectClassLoader in project drools by kiegroup.

the class HasKnowledgeBuilderMock method compileAndLoadClass.

@Override
public Class<?> compileAndLoadClass(Map<String, String> sourcesMap, String fullClassName) {
    ClassLoader classLoader = getClassLoader();
    if (!(classLoader instanceof ProjectClassLoader)) {
        throw new IllegalStateException("Expected ProjectClassLoader, received " + classLoader.getClass().getName());
    }
    ProjectClassLoader projectClassLoader = (ProjectClassLoader) classLoader;
    final Map<String, byte[]> byteCode = KieMemoryCompiler.compileNoLoad(sourcesMap, projectClassLoader);
    byteCode.forEach(projectClassLoader::defineClass);
    try {
        return projectClassLoader.loadClass(fullClassName);
    } catch (Exception e) {
        throw new KiePMMLException(e);
    }
}
Also used : ProjectClassLoader(org.drools.wiring.api.classloader.ProjectClassLoader) ProjectClassLoader(org.drools.wiring.api.classloader.ProjectClassLoader) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException)

Example 9 with ProjectClassLoader

use of org.drools.wiring.api.classloader.ProjectClassLoader in project drools by kiegroup.

the class HasKnowledgeBuilderMock method compileAndLoadClass.

@Override
public Class<?> compileAndLoadClass(Map<String, String> sourcesMap, String fullClassName) {
    ClassLoader classLoader = getClassLoader();
    if (!(classLoader instanceof ProjectClassLoader)) {
        throw new IllegalStateException("Expected ProjectClassLoader, received " + classLoader.getClass().getName());
    }
    ProjectClassLoader projectClassLoader = (ProjectClassLoader) classLoader;
    final Map<String, byte[]> byteCode = KieMemoryCompiler.compileNoLoad(sourcesMap, projectClassLoader);
    byteCode.forEach(projectClassLoader::defineClass);
    try {
        return projectClassLoader.loadClass(fullClassName);
    } catch (Exception e) {
        throw new KiePMMLException(e);
    }
}
Also used : ProjectClassLoader(org.drools.wiring.api.classloader.ProjectClassLoader) ProjectClassLoader(org.drools.wiring.api.classloader.ProjectClassLoader) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException)

Example 10 with ProjectClassLoader

use of org.drools.wiring.api.classloader.ProjectClassLoader in project drools by kiegroup.

the class GeneratedClassNamesTest method testModuleWithDepWithClassLoader.

@Test
public void testModuleWithDepWithClassLoader() throws Exception {
    ProjectClassLoader projectClassLoader = ProjectClassLoader.createProjectClassLoader(Thread.currentThread().getContextClassLoader());
    testModuleWithDep(projectClassLoader);
}
Also used : ProjectClassLoader(org.drools.wiring.api.classloader.ProjectClassLoader) Test(org.junit.Test)

Aggregations

ProjectClassLoader (org.drools.wiring.api.classloader.ProjectClassLoader)21 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)4 JavaDialectRuntimeData (org.drools.core.rule.JavaDialectRuntimeData)3 Dialect (org.drools.compiler.compiler.Dialect)2 KieContainerImpl (org.drools.compiler.kie.builder.impl.KieContainerImpl)2 KieProject (org.drools.compiler.kie.builder.impl.KieProject)2 KieServices (org.kie.api.KieServices)2 KieFileSystem (org.kie.api.builder.KieFileSystem)2 ByteString (com.google.protobuf.ByteString)1 JCodeModel (com.sun.codemodel.JCodeModel)1 BadCommandLineException (com.sun.tools.xjc.BadCommandLineException)1 ErrorReceiver (com.sun.tools.xjc.ErrorReceiver)1 Model (com.sun.tools.xjc.model.Model)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1