Search in sources :

Example 1 with CompilationProblem

use of org.kie.internal.jci.CompilationProblem in project drools by kiegroup.

the class RuleErrorTest method testNewLineInMessage.

@Test
public void testNewLineInMessage() {
    CompilationProblem[] probs = new CompilationProblem[3];
    probs[0] = new MockCompilationProblem();
    probs[1] = new MockCompilationProblem();
    probs[2] = new MockCompilationProblem();
    DescrBuildError err = new DescrBuildError(new RuleDescr("ruleName"), new AndDescr(), probs, "IM IN YR EROR");
    assertNotNull(err.toString());
    String msg = err.getMessage();
    assertTrue(msg.indexOf("IM IN YR EROR") != -1);
    System.err.println(msg);
    assertEquals("IM IN YR EROR problem\nproblem\nproblem", msg);
}
Also used : DescrBuildError(org.drools.compiler.compiler.DescrBuildError) AndDescr(org.drools.drl.ast.descr.AndDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) CompilationProblem(org.kie.internal.jci.CompilationProblem) Test(org.junit.Test)

Example 2 with CompilationProblem

use of org.kie.internal.jci.CompilationProblem in project drools by kiegroup.

the class ProjectJavaCompiler method compileAll.

public List<KnowledgeBuilderResult> compileAll(ProjectClassLoader projectClassLoader, List<String> classList, MemoryResourceReader src) {
    List<KnowledgeBuilderResult> results = new ArrayList<KnowledgeBuilderResult>();
    if (classList.isEmpty()) {
        return results;
    }
    final String[] classes = new String[classList.size()];
    classList.toArray(classes);
    CompilationResult result = compiler.compile(classes, src, new ProjectResourceStore(projectClassLoader), projectClassLoader);
    if (result.getErrors().length > 0) {
        Map<String, ErrorHandler> errorHandlerMap = new HashMap<String, ErrorHandler>();
        for (int i = 0; i < result.getErrors().length; i++) {
            final CompilationProblem err = new CompilationProblemAdapter(result.getErrors()[i]);
            ErrorHandler handler = errorHandlerMap.get(err.getFileName());
            if (handler == null) {
                handler = new SrcErrorHandler("Src compile error");
                errorHandlerMap.put(err.getFileName(), handler);
            }
            handler.addError(err);
        }
        for (ErrorHandler handler : errorHandlerMap.values()) {
            if (handler.isInError()) {
                results.add(handler.getError());
            }
        }
    }
    return results;
}
Also used : SrcErrorHandler(org.drools.compiler.builder.impl.errors.SrcErrorHandler) ErrorHandler(org.drools.compiler.builder.impl.errors.ErrorHandler) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CompilationProblem(org.kie.internal.jci.CompilationProblem) SrcErrorHandler(org.drools.compiler.builder.impl.errors.SrcErrorHandler) CompilationResult(org.kie.memorycompiler.CompilationResult) KnowledgeBuilderResult(org.kie.internal.builder.KnowledgeBuilderResult) CompilationProblemAdapter(org.drools.compiler.kie.builder.impl.CompilationProblemAdapter)

Example 3 with CompilationProblem

use of org.kie.internal.jci.CompilationProblem in project drools by kiegroup.

the class SrcError method toString.

public String toString() {
    final StringBuilder buf = new StringBuilder();
    buf.append(this.message);
    buf.append(" : ");
    buf.append("\n");
    if (this.object instanceof CompilationProblem[]) {
        final CompilationProblem[] problem = (CompilationProblem[]) this.object;
        for (CompilationProblem aProblem : problem) {
            buf.append("\t");
            buf.append(aProblem);
            buf.append("\n");
        }
    } else if (this.object != null) {
        buf.append(this.object);
    }
    return buf.toString();
}
Also used : CompilationProblem(org.kie.internal.jci.CompilationProblem)

Example 4 with CompilationProblem

use of org.kie.internal.jci.CompilationProblem in project drools by kiegroup.

the class JavaDialect method compileAll.

/**
 * This actually triggers the compiling of all the resources.
 * Errors are mapped back to the element that originally generated the semantic
 * code.
 */
public void compileAll() {
    if (this.generatedClassList.isEmpty()) {
        this.errorHandlers.clear();
        return;
    }
    final String[] classes = new String[this.generatedClassList.size()];
    this.generatedClassList.toArray(classes);
    File dumpDir = this.configuration.getPackageBuilderConfiguration().getDumpDir();
    if (dumpDir != null) {
        dumpResources(classes, dumpDir);
    }
    final CompilationResult result = this.compiler.compile(classes, this.src, this.packageStoreWrapper, rootClassLoader);
    // this will sort out the errors based on what class/file they happened in
    if (result.getErrors().length > 0) {
        for (int i = 0; i < result.getErrors().length; i++) {
            final CompilationProblem err = new CompilationProblemAdapter(result.getErrors()[i]);
            final ErrorHandler handler = this.errorHandlers.get(err.getFileName());
            handler.addError(err);
        }
        final Collection errors = this.errorHandlers.values();
        for (Object error : errors) {
            final ErrorHandler handler = (ErrorHandler) error;
            if (handler.isInError()) {
                this.results.add(handler.getError());
            }
        }
    }
    // We've compiled everthing, so clear it for the next set of additions
    this.generatedClassList.clear();
    this.errorHandlers.clear();
}
Also used : RuleErrorHandler(org.drools.compiler.builder.impl.errors.RuleErrorHandler) SrcErrorHandler(org.drools.compiler.builder.impl.errors.SrcErrorHandler) FunctionErrorHandler(org.drools.compiler.builder.impl.errors.FunctionErrorHandler) ErrorHandler(org.drools.compiler.builder.impl.errors.ErrorHandler) RuleInvokerErrorHandler(org.drools.compiler.builder.impl.errors.RuleInvokerErrorHandler) Collection(java.util.Collection) CompilationResult(org.kie.memorycompiler.CompilationResult) CompilationProblem(org.kie.internal.jci.CompilationProblem) File(java.io.File) CompilationProblemAdapter(org.drools.compiler.kie.builder.impl.CompilationProblemAdapter)

Aggregations

CompilationProblem (org.kie.internal.jci.CompilationProblem)4 ErrorHandler (org.drools.compiler.builder.impl.errors.ErrorHandler)2 SrcErrorHandler (org.drools.compiler.builder.impl.errors.SrcErrorHandler)2 CompilationProblemAdapter (org.drools.compiler.kie.builder.impl.CompilationProblemAdapter)2 CompilationResult (org.kie.memorycompiler.CompilationResult)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 FunctionErrorHandler (org.drools.compiler.builder.impl.errors.FunctionErrorHandler)1 RuleErrorHandler (org.drools.compiler.builder.impl.errors.RuleErrorHandler)1 RuleInvokerErrorHandler (org.drools.compiler.builder.impl.errors.RuleInvokerErrorHandler)1 DescrBuildError (org.drools.compiler.compiler.DescrBuildError)1 AndDescr (org.drools.drl.ast.descr.AndDescr)1 RuleDescr (org.drools.drl.ast.descr.RuleDescr)1 Test (org.junit.Test)1 KnowledgeBuilderResult (org.kie.internal.builder.KnowledgeBuilderResult)1