Search in sources :

Example 6 with CompilerPlugin

use of org.ballerinalang.compiler.plugins.CompilerPlugin in project ballerina by ballerina-lang.

the class BTestRunner method runTest.

/**
 * Executes a given set of ballerina program files.
 *
 * @param sourceRoot      source root
 * @param sourceFilePaths List of @{@link Path} of ballerina files
 * @param groups          List of groups to be included/excluded
 * @param shouldIncludeGroups    flag to specify whether to include or exclude provided groups
 */
public void runTest(String sourceRoot, Path[] sourceFilePaths, List<String> groups, boolean shouldIncludeGroups) {
    outStream.println("---------------------------------------------------------------------------");
    outStream.println("    T E S T S");
    outStream.println("---------------------------------------------------------------------------");
    TesterinaRegistry.getInstance().setGroups(groups);
    TesterinaRegistry.getInstance().setShouldIncludeGroups(shouldIncludeGroups);
    Arrays.stream(sourceFilePaths).forEach(sourcePackage -> {
        // compile
        CompileResult compileResult = BCompileUtil.compile(sourceRoot == null ? programDirPath.toString() : sourceRoot, sourcePackage.toString(), CompilerPhase.CODE_GEN);
        // print errors
        for (Diagnostic diagnostic : compileResult.getDiagnostics()) {
            errStream.println(diagnostic.getKind() + ": " + diagnostic.getPosition() + " " + diagnostic.getMessage());
        }
        if (compileResult.getDiagnostics().length > 0) {
            throw new BallerinaException("[ERROR] Compilation failed.");
        }
        // set the debugger
        ProgramFile programFile = compileResult.getProgFile();
        Debugger debugger = new Debugger(programFile);
        programFile.setDebugger(debugger);
        TesterinaRegistry.getInstance().addProgramFile(programFile);
        // process the compiled files
        ServiceLoader<CompilerPlugin> processorServiceLoader = ServiceLoader.load(CompilerPlugin.class);
        processorServiceLoader.forEach(plugin -> {
            if (plugin instanceof TestAnnotationProcessor) {
                try {
                    ((TestAnnotationProcessor) plugin).packageProcessed(programFile);
                } catch (Exception e) {
                    errStream.println("[ERROR] Validation failed. Cause: " + e.getMessage());
                    throw new BallerinaException(e);
                }
            }
        });
    });
    // execute the test programs
    execute();
    // print the report
    tReport.printSummary();
}
Also used : Debugger(org.ballerinalang.util.debugger.Debugger) CompilerPlugin(org.ballerinalang.compiler.plugins.CompilerPlugin) Diagnostic(org.ballerinalang.util.diagnostic.Diagnostic) CompileResult(org.ballerinalang.launcher.util.CompileResult) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException) ProgramFile(org.ballerinalang.util.codegen.ProgramFile)

Aggregations

CompilerPlugin (org.ballerinalang.compiler.plugins.CompilerPlugin)6 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 SupportedAnnotationPackages (org.ballerinalang.compiler.plugins.SupportedAnnotationPackages)2 AnnotationAttachmentNode (org.ballerinalang.model.tree.AnnotationAttachmentNode)2 BAnnotationSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol)2 BLangAnnotationAttachment (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment)2 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Objects (java.util.Objects)1 ServiceLoader (java.util.ServiceLoader)1 BiConsumer (java.util.function.BiConsumer)1 BLangCompilerException (org.ballerinalang.compiler.BLangCompilerException)1