Search in sources :

Example 1 with CompilationProblemErrorResult

use of org.drools.modelcompiler.builder.errors.CompilationProblemErrorResult in project drools by kiegroup.

the class JavaParserCompiler method compileAll.

public static Map<String, Class<?>> compileAll(KnowledgeBuilderImpl kbuilder, ClassLoader classLoader, List<GeneratedClassWithPackage> classes) {
    if (classes == null || classes.isEmpty()) {
        return Collections.emptyMap();
    }
    MemoryFileSystem srcMfs = new MemoryFileSystem();
    MemoryFileSystem trgMfs = new MemoryFileSystem();
    String[] resources = writeModel(classes, srcMfs);
    CompilationResult resultCompilation = getCompiler().compile(resources, srcMfs, trgMfs, classLoader);
    CompilationProblem[] errors = resultCompilation.getErrors();
    if (errors.length != 0) {
        classes.forEach(c -> logger.error(c.toString()));
        for (CompilationProblem error : errors) {
            kbuilder.addBuilderResult(new CompilationProblemErrorResult(error));
        }
        return Collections.emptyMap();
    }
    InternalClassLoader internalClassLoader = new InternalClassLoader(classLoader, trgMfs);
    Map<String, Class<?>> result = new HashMap<>();
    for (GeneratedClassWithPackage cls : classes) {
        final String fullClassName = cls.getPackageName() + "." + cls.getGeneratedClass().getNameAsString();
        try {
            result.put(fullClassName, Class.forName(fullClassName, true, internalClassLoader));
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
    return result;
}
Also used : CompilationProblemErrorResult(org.drools.modelcompiler.builder.errors.CompilationProblemErrorResult) HashMap(java.util.HashMap) CompilationProblem(org.drools.compiler.commons.jci.problems.CompilationProblem) MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) CompilationResult(org.drools.compiler.commons.jci.compilers.CompilationResult)

Aggregations

HashMap (java.util.HashMap)1 CompilationResult (org.drools.compiler.commons.jci.compilers.CompilationResult)1 CompilationProblem (org.drools.compiler.commons.jci.problems.CompilationProblem)1 MemoryFileSystem (org.drools.compiler.compiler.io.memory.MemoryFileSystem)1 CompilationProblemErrorResult (org.drools.modelcompiler.builder.errors.CompilationProblemErrorResult)1