use of org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment in project ballerina by ballerina-lang.
the class CompilerPluginRunner method notifyProcessors.
private void notifyProcessors(List<BLangAnnotationAttachment> attachments, BiConsumer<CompilerPlugin, List<AnnotationAttachmentNode>> notifier) {
Map<CompilerPlugin, List<AnnotationAttachmentNode>> attachmentMap = new HashMap<>();
for (BLangAnnotationAttachment attachment : attachments) {
DefinitionID aID = new DefinitionID(attachment.annotationSymbol.pkgID.getName().value, attachment.annotationName.value);
if (!processorMap.containsKey(aID)) {
continue;
}
List<CompilerPlugin> procList = processorMap.get(aID);
procList.forEach(proc -> {
List<AnnotationAttachmentNode> attachmentNodes = attachmentMap.computeIfAbsent(proc, k -> new ArrayList<>());
attachmentNodes.add(attachment);
});
}
for (CompilerPlugin processor : attachmentMap.keySet()) {
notifier.accept(processor, Collections.unmodifiableList(attachmentMap.get(processor)));
}
}
use of org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
public void visit(BLangAnnotationAttachment annAttachmentNode) {
BSymbol symbol = this.symResolver.resolveAnnotation(annAttachmentNode.pos, env, names.fromString(annAttachmentNode.pkgAlias.getValue()), names.fromString(annAttachmentNode.getAnnotationName().getValue()));
if (symbol == this.symTable.notFoundSymbol) {
this.dlog.error(annAttachmentNode.pos, DiagnosticCode.UNDEFINED_ANNOTATION, annAttachmentNode.getAnnotationName().getValue());
return;
}
// Validate Attachment Point against the Annotation Definition.
BAnnotationSymbol annotationSymbol = (BAnnotationSymbol) symbol;
annAttachmentNode.annotationSymbol = annotationSymbol;
if (annotationSymbol.getAttachmentPoints() != null && annotationSymbol.getAttachmentPoints().size() > 0) {
BLangAnnotationAttachmentPoint[] attachmentPointsArrray = new BLangAnnotationAttachmentPoint[annotationSymbol.getAttachmentPoints().size()];
Optional<BLangAnnotationAttachmentPoint> matchingAttachmentPoint = Arrays.stream(annotationSymbol.getAttachmentPoints().toArray(attachmentPointsArrray)).filter(attachmentPoint -> attachmentPoint.equals(annAttachmentNode.attachmentPoint)).findAny();
if (!matchingAttachmentPoint.isPresent()) {
String msg = annAttachmentNode.attachmentPoint.getAttachmentPoint().getValue();
this.dlog.error(annAttachmentNode.pos, DiagnosticCode.ANNOTATION_NOT_ALLOWED, annotationSymbol, msg);
}
}
// Validate Annotation Attachment data struct against Annotation Definition struct.
validateAnnotationAttachmentExpr(annAttachmentNode, annotationSymbol);
}
use of org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method processDeployment.
/**
* Process annotations and create deployment model object.
*
* @param attachmentNode annotation attachment node.
* @return Deployment model object
*/
DeploymentModel processDeployment(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
DeploymentModel deploymentModel = new DeploymentModel();
List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
DeploymentConfiguration deploymentConfiguration = DeploymentConfiguration.valueOf(keyValue.getKey().toString());
String annotationValue = resolveValue(keyValue.getValue().toString());
switch(deploymentConfiguration) {
case name:
deploymentModel.setName(getValidName(annotationValue));
break;
case labels:
deploymentModel.setLabels(getMap(((BLangRecordLiteral) keyValue.valueExpr).keyValuePairs));
break;
case enableLiveness:
deploymentModel.setEnableLiveness(annotationValue);
break;
case livenessPort:
deploymentModel.setLivenessPort(Integer.parseInt(annotationValue));
break;
case initialDelaySeconds:
deploymentModel.setInitialDelaySeconds(Integer.parseInt(annotationValue));
break;
case periodSeconds:
deploymentModel.setPeriodSeconds(Integer.parseInt(annotationValue));
break;
case username:
deploymentModel.setUsername(annotationValue);
break;
case env:
deploymentModel.setEnv(getMap(((BLangRecordLiteral) keyValue.valueExpr).keyValuePairs));
break;
case password:
deploymentModel.setPassword(annotationValue);
break;
case baseImage:
deploymentModel.setBaseImage(annotationValue);
break;
case push:
deploymentModel.setPush(Boolean.valueOf(annotationValue));
break;
case buildImage:
deploymentModel.setBuildImage(Boolean.valueOf(annotationValue));
break;
case image:
deploymentModel.setImage(annotationValue);
break;
case dockerHost:
deploymentModel.setDockerHost(annotationValue);
break;
case dockerCertPath:
deploymentModel.setDockerCertPath(annotationValue);
break;
case imagePullPolicy:
deploymentModel.setImagePullPolicy(annotationValue);
break;
case replicas:
deploymentModel.setReplicas(Integer.parseInt(annotationValue));
break;
default:
break;
}
}
return deploymentModel;
}
use of org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method processIngressAnnotation.
/**
* Process annotations and create Ingress model object.
*
* @param serviceName Ballerina service name
* @param attachmentNode annotation attachment node.
* @return Ingress model object
*/
IngressModel processIngressAnnotation(String serviceName, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
IngressModel ingressModel = new IngressModel();
List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
IngressConfiguration ingressConfiguration = IngressConfiguration.valueOf(keyValue.getKey().toString());
String annotationValue = resolveValue(keyValue.getValue().toString());
switch(ingressConfiguration) {
case name:
ingressModel.setName(getValidName(annotationValue));
break;
case labels:
ingressModel.setLabels(getMap(((BLangRecordLiteral) keyValue.valueExpr).keyValuePairs));
break;
case path:
ingressModel.setPath(annotationValue);
break;
case targetPath:
ingressModel.setTargetPath(annotationValue);
break;
case hostname:
ingressModel.setHostname(annotationValue);
break;
case ingressClass:
ingressModel.setIngressClass(annotationValue);
break;
case enableTLS:
ingressModel.setEnableTLS(Boolean.parseBoolean(annotationValue));
break;
default:
break;
}
}
if (ingressModel.getName() == null || ingressModel.getName().length() == 0) {
ingressModel.setName(getValidName(serviceName) + INGRESS_POSTFIX);
}
if (ingressModel.getHostname() == null || ingressModel.getHostname().length() == 0) {
ingressModel.setHostname(getValidName(serviceName) + INGRESS_HOSTNAME_POSTFIX);
}
return ingressModel;
}
use of org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method processSecrets.
/**
* Process Secrets annotations.
*
* @param attachmentNode Attachment Node
* @return List of @{@link SecretModel} objects
*/
Set<SecretModel> processSecrets(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
Set<SecretModel> secrets = new HashSet<>();
List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
List<BLangExpression> secretAnnotation = ((BLangArrayLiteral) keyValue.valueExpr).exprs;
for (BLangExpression bLangExpression : secretAnnotation) {
SecretModel secretModel = new SecretModel();
List<BLangRecordLiteral.BLangRecordKeyValue> annotationValues = ((BLangRecordLiteral) bLangExpression).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue annotation : annotationValues) {
VolumeMountConfig volumeMountConfig = VolumeMountConfig.valueOf(annotation.getKey().toString());
String annotationValue = resolveValue(annotation.getValue().toString());
switch(volumeMountConfig) {
case name:
secretModel.setName(getValidName(annotationValue));
break;
case mountPath:
secretModel.setMountPath(annotationValue);
break;
case data:
List<BLangExpression> data = ((BLangArrayLiteral) annotation.valueExpr).exprs;
secretModel.setData(getDataForSecret(data));
break;
case readOnly:
secretModel.setReadOnly(Boolean.parseBoolean(annotationValue));
break;
default:
break;
}
}
secrets.add(secretModel);
}
}
return secrets;
}
Aggregations