Search in sources :

Example 1 with PackageInfo

use of org.wso2.ballerinalang.programfile.PackageInfo in project ballerina by ballerina-lang.

the class BallerinaParserService method validateAndParse.

/**
 * Validates a given ballerina input.
 *
 * @param bFileRequest - Object which holds data about Ballerina content.
 * @return List of errors if any
 */
private JsonObject validateAndParse(BFile bFileRequest) throws InvocationTargetException, IllegalAccessException {
    final java.nio.file.Path filePath = Paths.get(bFileRequest.getFilePath(), bFileRequest.getFileName());
    final String fileName = bFileRequest.getFileName();
    final String content = bFileRequest.getContent();
    BallerinaFile bFile = ParserUtils.compile(content, filePath);
    String programDir = TextDocumentServiceUtil.getSourceRoot(filePath);
    final BLangPackage model = bFile.getBLangPackage();
    final List<Diagnostic> diagnostics = bFile.getDiagnostics();
    ErrorCategory errorCategory = ErrorCategory.NONE;
    if (!diagnostics.isEmpty()) {
        if (model == null) {
            errorCategory = ErrorCategory.SYNTAX;
        } else {
            errorCategory = ErrorCategory.SEMANTIC;
        }
    }
    JsonArray errors = new JsonArray();
    final String errorCategoryName = errorCategory.name();
    diagnostics.forEach(diagnostic -> {
        JsonObject error = new JsonObject();
        Diagnostic.DiagnosticPosition position = diagnostic.getPosition();
        if (position != null) {
            if (!diagnostic.getSource().getCompilationUnitName().equals(fileName)) {
                return;
            }
            error.addProperty("row", position.getStartLine());
            error.addProperty("column", position.getStartColumn());
            error.addProperty("type", "error");
            error.addProperty("category", errorCategoryName);
        } else {
            // position == null means it's a bug in core side.
            error.addProperty("category", ErrorCategory.RUNTIME.name());
        }
        error.addProperty("text", diagnostic.getMessage());
        errors.add(error);
    });
    JsonObject result = new JsonObject();
    result.add("errors", errors);
    Gson gson = new Gson();
    JsonElement diagnosticsJson = gson.toJsonTree(diagnostics);
    result.add("diagnostics", diagnosticsJson);
    if (model != null && bFileRequest.needTree()) {
        BLangCompilationUnit compilationUnit = model.getCompilationUnits().stream().filter(compUnit -> fileName.equals(compUnit.getName())).findFirst().get();
        JsonElement modelElement = generateJSON(compilationUnit, new HashMap<>());
        result.add("model", modelElement);
    }
    final Map<String, ModelPackage> modelPackage = new HashMap<>();
    ParserUtils.loadPackageMap("Current Package", bFile.getBLangPackage(), modelPackage);
    Optional<ModelPackage> packageInfoJson = modelPackage.values().stream().findFirst();
    if (packageInfoJson.isPresent() && bFileRequest.needPackageInfo()) {
        JsonElement packageInfo = gson.toJsonTree(packageInfoJson.get());
        result.add("packageInfo", packageInfo);
    }
    if (programDir != null) {
        result.addProperty("programDirPath", programDir);
    }
    return result;
}
Also used : BallerinaFile(org.ballerinalang.composer.service.ballerina.parser.service.model.BallerinaFile) HashMap(java.util.HashMap) Diagnostic(org.ballerinalang.util.diagnostic.Diagnostic) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) JsonArray(com.google.gson.JsonArray) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) JsonElement(com.google.gson.JsonElement) ModelPackage(org.ballerinalang.composer.service.ballerina.parser.service.model.lang.ModelPackage) BLangCompilationUnit(org.wso2.ballerinalang.compiler.tree.BLangCompilationUnit)

Example 2 with PackageInfo

use of org.wso2.ballerinalang.programfile.PackageInfo in project ballerina by ballerina-lang.

the class ErrorTableEntry method setPackageInfo.

public void setPackageInfo(PackageInfo packageInfo) {
    this.packageInfo = packageInfo;
    // Load Cache values.
    if (errorStructCPIndex < 0) {
        return;
    }
    StructureRefCPEntry structureRefCPEntry = (StructureRefCPEntry) packageInfo.getCPEntry(errorStructCPIndex);
// this.error = (StructInfo) structureRefCPEntry.getStructureTypeInfo();
}
Also used : StructureRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.StructureRefCPEntry)

Example 3 with PackageInfo

use of org.wso2.ballerinalang.programfile.PackageInfo in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

public void visit(BLangPackage pkgNode) {
    if (pkgNode.completedPhases.contains(CompilerPhase.CODE_GEN)) {
        if (!buildCompiledPackage) {
            programFile.packageInfoMap.put(pkgNode.symbol.pkgID.bvmAlias(), pkgNode.symbol.packageInfo);
        }
        return;
    }
    // TODO Improve this design without if/else
    PackageInfo packageInfo = new PackageInfo();
    pkgNode.symbol.packageInfo = packageInfo;
    if (buildCompiledPackage) {
        // Generating the BALO
        pkgNode.imports.forEach(impPkgNode -> {
            int impPkgNameCPIndex = addUTF8CPEntry(packageInfo, impPkgNode.symbol.name.value);
            // TODO Improve the import package version once it is available
            int impPkgVersionCPIndex = addUTF8CPEntry(packageInfo, PackageID.DEFAULT.version.value);
            ImportPackageInfo importPkgInfo = new ImportPackageInfo(impPkgNameCPIndex, impPkgVersionCPIndex);
            packageInfo.importPkgInfoSet.add(importPkgInfo);
            packageFile.packageInfo = packageInfo;
        });
    } else {
        // Generating a BALX
        // first visit all the imports
        pkgNode.imports.forEach(impPkgNode -> genNode(impPkgNode, this.env));
        // TODO We need to create identifier for both name and the version
        programFile.packageInfoMap.put(pkgNode.symbol.pkgID.bvmAlias(), packageInfo);
    }
    // Add the current package to the program file
    BPackageSymbol pkgSymbol = pkgNode.symbol;
    currentPkgID = pkgSymbol.pkgID;
    currentPkgInfo = packageInfo;
    currentPkgInfo.nameCPIndex = addUTF8CPEntry(currentPkgInfo, currentPkgID.bvmAlias());
    currentPkgInfo.versionCPIndex = addUTF8CPEntry(currentPkgInfo, currentPkgID.version.value);
    // Insert the package reference to the constant pool of the current package
    currentPackageRefCPIndex = addPackageRefCPEntry(currentPkgInfo, currentPkgID);
    // This attribute keep track of line numbers
    int lineNoAttrNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.LINE_NUMBER_TABLE_ATTRIBUTE.value());
    lineNoAttrInfo = new LineNumberTableAttributeInfo(lineNoAttrNameIndex);
    // This attribute keep package-level variable information
    int pkgVarAttrNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE.value());
    currentPkgInfo.addAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE, new LocalVariableAttributeInfo(pkgVarAttrNameIndex));
    pkgNode.globalVars.forEach(this::createPackageVarInfo);
    pkgNode.structs.forEach(this::createStructInfoEntry);
    pkgNode.enums.forEach(this::createEnumInfoEntry);
    pkgNode.connectors.forEach(this::createConnectorInfoEntry);
    pkgNode.functions.forEach(this::createFunctionInfoEntry);
    pkgNode.services.forEach(this::createServiceInfoEntry);
    pkgNode.functions.forEach(this::createFunctionInfoEntry);
    pkgNode.transformers.forEach(this::createTransformerInfoEntry);
    // Visit package builtin function
    visitBuiltinFunctions(pkgNode.initFunction);
    visitBuiltinFunctions(pkgNode.startFunction);
    visitBuiltinFunctions(pkgNode.stopFunction);
    pkgNode.topLevelNodes.stream().filter(pkgLevelNode -> pkgLevelNode.getKind() != NodeKind.VARIABLE && pkgLevelNode.getKind() != NodeKind.XMLNS).forEach(pkgLevelNode -> genNode((BLangNode) pkgLevelNode, this.env));
    currentPkgInfo.addAttributeInfo(AttributeInfo.Kind.LINE_NUMBER_TABLE_ATTRIBUTE, lineNoAttrInfo);
    currentPackageRefCPIndex = -1;
    currentPkgID = null;
    pkgNode.completedPhases.add(CompilerPhase.CODE_GEN);
}
Also used : BLangMapLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangMapLiteral) BLangReturn(org.wso2.ballerinalang.compiler.tree.statements.BLangReturn) REF_OFFSET(org.wso2.ballerinalang.programfile.ProgramFileConstants.REF_OFFSET) UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) FloatCPEntry(org.wso2.ballerinalang.programfile.cpentries.FloatCPEntry) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BLangXMLTextLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLTextLiteral) Map(java.util.Map) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex) SymbolKind(org.ballerinalang.model.symbols.SymbolKind) BLangWhile(org.wso2.ballerinalang.compiler.tree.statements.BLangWhile) PackageVarInfo(org.wso2.ballerinalang.programfile.PackageVarInfo) BEnumType(org.wso2.ballerinalang.compiler.semantics.model.types.BEnumType) LocalVariableInfo(org.wso2.ballerinalang.programfile.LocalVariableInfo) AttributeInfo(org.wso2.ballerinalang.programfile.attributes.AttributeInfo) TypeDescriptor(org.wso2.ballerinalang.compiler.util.TypeDescriptor) PackageID(org.ballerinalang.model.elements.PackageID) ImportPackageInfo(org.wso2.ballerinalang.programfile.ImportPackageInfo) BLangXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS) BLangXMLNSStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangXMLNSStatement) BLangArrayAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangArrayAccessExpr) BLangIf(org.wso2.ballerinalang.compiler.tree.statements.BLangIf) BLangInvokableNode(org.wso2.ballerinalang.compiler.tree.BLangInvokableNode) ForkJoinCPEntry(org.wso2.ballerinalang.programfile.cpentries.ForkJoinCPEntry) BLangForeach(org.wso2.ballerinalang.compiler.tree.statements.BLangForeach) BLangTypeInit(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeInit) BLangAnnotAttachmentAttributeValue(org.wso2.ballerinalang.compiler.tree.expressions.BLangAnnotAttachmentAttributeValue) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangXMLCommentLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLCommentLiteral) StructureRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.StructureRefCPEntry) BLangFunctionVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangFunctionVarRef) LineNumberTableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LineNumberTableAttributeInfo) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) TreeBuilder(org.ballerinalang.model.TreeBuilder) ErrorTableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ErrorTableAttributeInfo) ActionRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.ActionRefCPEntry) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangUnaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangUnaryExpr) PackageFile(org.wso2.ballerinalang.programfile.CompiledBinaryFile.PackageFile) DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) REG(org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.REG) BLangPackageXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS.BLangPackageXMLNS) BLangForkJoin(org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin) BLangStructFieldAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess.BLangStructFieldAccessExpr) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) BLangThrow(org.wso2.ballerinalang.compiler.tree.statements.BLangThrow) WorkerInfo(org.wso2.ballerinalang.programfile.WorkerInfo) FIELD(org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD) BOOL_OFFSET(org.wso2.ballerinalang.programfile.ProgramFileConstants.BOOL_OFFSET) BLangBracedOrTupleExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangBracedOrTupleExpr) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) BLangAttachedFunctionInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BLangAttachedFunctionInvocation) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) ForkjoinInfo(org.wso2.ballerinalang.programfile.ForkjoinInfo) Name(org.ballerinalang.model.Name) BAttachedFunction(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol.BAttachedFunction) BLangWorkerReceive(org.wso2.ballerinalang.compiler.tree.statements.BLangWorkerReceive) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BXMLNSSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol) BStructType(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) PACKAGE(org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) BLangTransformerInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BLangTransformerInvocation) BLangIsAssignableExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIsAssignableExpr) IntegerCPEntry(org.wso2.ballerinalang.programfile.cpentries.IntegerCPEntry) Collectors(java.util.stream.Collectors) BLangTransformer(org.wso2.ballerinalang.compiler.tree.BLangTransformer) ProgramFile(org.wso2.ballerinalang.programfile.CompiledBinaryFile.ProgramFile) BLangCatch(org.wso2.ballerinalang.compiler.tree.statements.BLangCatch) BLangEnum(org.wso2.ballerinalang.compiler.tree.BLangEnum) NodeKind(org.ballerinalang.model.tree.NodeKind) InstructionCodes(org.wso2.ballerinalang.programfile.InstructionCodes) BLangActionInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BLangActionInvocation) Instruction(org.wso2.ballerinalang.programfile.Instruction) Entry(java.util.Map.Entry) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) BLangXMLSequenceLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLSequenceLiteral) AttributeInfoPool(org.wso2.ballerinalang.programfile.attributes.AttributeInfoPool) TransformerRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.TransformerRefCPEntry) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) BLangNodeVisitor(org.wso2.ballerinalang.compiler.tree.BLangNodeVisitor) BLangTransaction(org.wso2.ballerinalang.compiler.tree.statements.BLangTransaction) Stack(java.util.Stack) TypeTags(org.wso2.ballerinalang.compiler.util.TypeTags) BLangMatch(org.wso2.ballerinalang.compiler.tree.statements.BLangMatch) BLangJSONArrayLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral.BLangJSONArrayLiteral) BLangTernaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTernaryExpr) InstructionFactory(org.wso2.ballerinalang.programfile.InstructionFactory) BLangRecordKeyValue(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangRecordKeyValue) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) WorkerDataChannelRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.WorkerDataChannelRefCPEntry) BLangFieldVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangFieldVarRef) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) FieldType(org.wso2.ballerinalang.compiler.util.FieldType) AttachedFunctionInfo(org.wso2.ballerinalang.programfile.AttachedFunctionInfo) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) ConnectorInfo(org.wso2.ballerinalang.programfile.ConnectorInfo) SymbolTable(org.wso2.ballerinalang.compiler.semantics.model.SymbolTable) StringCPEntry(org.wso2.ballerinalang.programfile.cpentries.StringCPEntry) Arrays(java.util.Arrays) BLangStreamLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangStreamLiteral) BMapType(org.wso2.ballerinalang.compiler.semantics.model.types.BMapType) BLangTableLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangTableLiteral) BLangBreak(org.wso2.ballerinalang.compiler.tree.statements.BLangBreak) BConnectorType(org.wso2.ballerinalang.compiler.semantics.model.types.BConnectorType) BLangTryCatchFinally(org.wso2.ballerinalang.compiler.tree.statements.BLangTryCatchFinally) BLangVariableReference(org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference) BLangAnnotAttachmentAttribute(org.wso2.ballerinalang.compiler.tree.expressions.BLangAnnotAttachmentAttribute) StructInfo(org.wso2.ballerinalang.programfile.StructInfo) BLangBinaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr) BLangEnumeratorAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess.BLangEnumeratorAccessExpr) CompilerPhase(org.ballerinalang.compiler.CompilerPhase) STRING_OFFSET(org.wso2.ballerinalang.programfile.ProgramFileConstants.STRING_OFFSET) BLangAnnotAttribute(org.wso2.ballerinalang.compiler.tree.BLangAnnotAttribute) ErrorTableEntry(org.wso2.ballerinalang.programfile.ErrorTableEntry) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol) BLangLambdaFunction(org.wso2.ballerinalang.compiler.tree.expressions.BLangLambdaFunction) BLangStructLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangStructLiteral) ConstantPool(org.wso2.ballerinalang.programfile.cpentries.ConstantPool) ResourceInfo(org.wso2.ballerinalang.programfile.ResourceInfo) CodeAttributeInfo(org.wso2.ballerinalang.programfile.attributes.CodeAttributeInfo) ParamDefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo) BLangAnnotation(org.wso2.ballerinalang.compiler.tree.BLangAnnotation) BLangXMLAttribute(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttribute) BLangAbort(org.wso2.ballerinalang.compiler.tree.statements.BLangAbort) BLangLocalXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS.BLangLocalXMLNS) ServiceInfo(org.wso2.ballerinalang.programfile.ServiceInfo) BLangPackageVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangPackageVarRef) ArrayList(java.util.ArrayList) BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) BLangArrayLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral) StructFieldInfo(org.wso2.ballerinalang.programfile.StructFieldInfo) BArrayType(org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangXMLProcInsLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLProcInsLiteral) EnumInfo(org.wso2.ballerinalang.programfile.EnumInfo) BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) BLangForever(org.wso2.ballerinalang.compiler.tree.statements.BLangForever) ActionInfo(org.wso2.ballerinalang.programfile.ActionInfo) BLangJSONAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangJSONAccessExpr) SymTag(org.wso2.ballerinalang.compiler.semantics.model.symbols.SymTag) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) BLangEnumerator(org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator) EnumeratorInfo(org.wso2.ballerinalang.programfile.EnumeratorInfo) BLangXMLAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangXMLAccessExpr) PackageInfo(org.wso2.ballerinalang.programfile.PackageInfo) INT_OFFSET(org.wso2.ballerinalang.programfile.ProgramFileConstants.INT_OFFSET) BLangTypeConversionExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr) WorkerDataChannelInfo(org.wso2.ballerinalang.programfile.WorkerDataChannelInfo) FunctionFlags(org.ballerinalang.util.FunctionFlags) BLangXMLAttributeAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttributeAccess) LineNumberInfo(org.wso2.ballerinalang.programfile.LineNumberInfo) TransactionStatus(org.ballerinalang.util.TransactionStatus) TransformerInfo(org.wso2.ballerinalang.programfile.TransformerInfo) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) BLangImportPackage(org.wso2.ballerinalang.compiler.tree.BLangImportPackage) OperatorKind(org.ballerinalang.model.tree.OperatorKind) BLangFail(org.wso2.ballerinalang.compiler.tree.statements.BLangFail) BLangJSONLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangJSONLiteral) LocalVariableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BLangLock(org.wso2.ballerinalang.compiler.tree.statements.BLangLock) BLangRecordKey(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangRecordKey) DefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.DefaultValueAttributeInfo) BLOB_OFFSET(org.wso2.ballerinalang.programfile.ProgramFileConstants.BLOB_OFFSET) BLangAnnotationAttachment(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) List(java.util.List) FLOAT_OFFSET(org.wso2.ballerinalang.programfile.ProgramFileConstants.FLOAT_OFFSET) DefaultValue(org.wso2.ballerinalang.programfile.DefaultValue) Optional(java.util.Optional) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) FunctionRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.FunctionRefCPEntry) LOCAL(org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.LOCAL) BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction) BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt) BFunctionPointerInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BFunctionPointerInvocation) BLangTypeofExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeofExpr) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) CallableUnitInfo(org.wso2.ballerinalang.programfile.CallableUnitInfo) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangLocalVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangLocalVarRef) PackageRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.PackageRefCPEntry) BLangStringTemplateLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangStringTemplateLiteral) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BLangIntRangeExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangIntRangeExpression) FunctionInfo(org.wso2.ballerinalang.programfile.FunctionInfo) XMLConstants(javax.xml.XMLConstants) BLangMapAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangMapAccessExpr) VarTypeCountAttributeInfo(org.wso2.ballerinalang.programfile.attributes.VarTypeCountAttributeInfo) BLangNext(org.wso2.ballerinalang.compiler.tree.statements.BLangNext) Symbols(org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols) BLangAwaitExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangAwaitExpr) BLangXMLElementLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLElementLiteral) BLangWorkerSend(org.wso2.ballerinalang.compiler.tree.statements.BLangWorkerSend) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BLangConnector(org.wso2.ballerinalang.compiler.tree.BLangConnector) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) TypeRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.TypeRefCPEntry) ImportPackageInfo(org.wso2.ballerinalang.programfile.ImportPackageInfo) BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) LineNumberTableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LineNumberTableAttributeInfo) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) LocalVariableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo) ImportPackageInfo(org.wso2.ballerinalang.programfile.ImportPackageInfo) PackageInfo(org.wso2.ballerinalang.programfile.PackageInfo) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 4 with PackageInfo

use of org.wso2.ballerinalang.programfile.PackageInfo in project carbon-business-process by wso2.

the class BPELPackageManagementServiceSkeleton method getPackageInfo.

private PackageType getPackageInfo(BPELPackageInfo packageInfo, int maxRemainingPackages) throws PackageManagementException {
    PackageType bpelPackage = new PackageType();
    bpelPackage.setName(packageInfo.getName());
    bpelPackage.setState(convertToPackageStatusType(packageInfo.getStatus()));
    bpelPackage.setVersions(getAllVersionsOfPackage(packageInfo, maxRemainingPackages));
    bpelPackage.setErrorLog(packageInfo.getCauseForDeploymentFailure());
    return bpelPackage;
}
Also used : PackageType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.PackageType)

Example 5 with PackageInfo

use of org.wso2.ballerinalang.programfile.PackageInfo in project carbon-business-process by wso2.

the class BPELPackageManagementServiceSkeleton method getAllVersionsOfPackage.

private Versions_type0 getAllVersionsOfPackage(BPELPackageInfo packageInfo, int maxRemainingPackages) throws PackageManagementException {
    Versions_type0 versionsList = new Versions_type0();
    List<String> versions = packageInfo.getAvailableVersions();
    Collections.reverse(versions);
    int count = 0;
    int startIndex = maxRemainingPackages < 0 ? versions.size() + maxRemainingPackages : 0;
    int endIndex = versions.size() - 1;
    for (int i = startIndex; i <= endIndex && Math.abs(maxRemainingPackages) > count; i++) {
        String version = versions.get(i);
        Version_type0 packageVersion = new Version_type0();
        packageVersion.setName(version);
        packageVersion.setProcesses(getProcessesForPackage(version));
        if (version.equals(packageInfo.getName() + "-" + packageInfo.getLatestVersion())) {
            packageVersion.setIsLatest(true);
        } else {
            packageVersion.setIsLatest(false);
        }
        versionsList.addVersion(packageVersion);
        count++;
    }
    return versionsList;
}
Also used : Version_type0(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.Version_type0) Versions_type0(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.Versions_type0)

Aggregations

BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)3 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)2 StructureRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.StructureRefCPEntry)2 UTF8CPEntry (org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 Stack (java.util.Stack)1 Collectors (java.util.stream.Collectors)1 XMLConstants (javax.xml.XMLConstants)1 CompilerPhase (org.ballerinalang.compiler.CompilerPhase)1 BallerinaFile (org.ballerinalang.composer.service.ballerina.parser.service.model.BallerinaFile)1