Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
org = "ballerina"
name = "cloud"
version = "3.3.0"
version = "3.3.1"
repository = "https://github.com/ballerina-platform/module-ballerina-c2c"
license = ["Apache-2.0"]
keywords = ["cloud", "kubernetes", "docker", "k8s", "c2c"]
Expand Down
2 changes: 1 addition & 1 deletion ballerina/CompilerPlugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ id = "code2cloud"
class = "io.ballerina.c2c.C2CCompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/cloud-compiler-plugin-3.3.0.jar"
path = "../compiler-plugin/build/libs/cloud-compiler-plugin-3.3.1-SNAPSHOT.jar"
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ distribution-version = "2201.12.0"
[[package]]
org = "ballerina"
name = "cloud"
version = "3.3.0"
version = "3.3.1"
modules = [
{org = "ballerina", packageName = "cloud", moduleName = "cloud"}
]
Expand Down
29 changes: 22 additions & 7 deletions cloud-util/src/main/java/io/ballerina/c2c/util/C2CVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import io.ballerina.compiler.syntax.tree.MappingFieldNode;
import io.ballerina.compiler.syntax.tree.MetadataNode;
import io.ballerina.compiler.syntax.tree.ModuleVariableDeclarationNode;
import io.ballerina.compiler.syntax.tree.NamedArgumentNode;
import io.ballerina.compiler.syntax.tree.Node;
import io.ballerina.compiler.syntax.tree.NodeList;
import io.ballerina.compiler.syntax.tree.NodeVisitor;
Expand Down Expand Up @@ -282,13 +283,27 @@ private Optional<ListenerInfo> extractListenerInitializer(String listenerName,
}
if (arguments.size() > paramNo) {
FunctionArgumentNode functionArgumentNode = arguments.get(paramNo);
ExpressionNode expression = ((PositionalArgumentNode) functionArgumentNode).expression();
if (expression.kind() == SyntaxKind.SIMPLE_NAME_REFERENCE) {
return getListenerInfo(listenerName, expression);
} else if (expression instanceof BasicLiteralNode) {
BasicLiteralNode basicLiteralNode = (BasicLiteralNode) expression;
int port = Integer.parseInt(basicLiteralNode.literalToken().text());
return Optional.of(new ListenerInfo(listenerName, port));
if (functionArgumentNode.kind() == SyntaxKind.POSITIONAL_ARG) {
// Listener with positional argument - on new http:Listener(9091)
ExpressionNode expression = ((PositionalArgumentNode) functionArgumentNode).expression();
if (expression.kind() == SyntaxKind.SIMPLE_NAME_REFERENCE) {
return getListenerInfo(listenerName, expression);
} else if (expression instanceof BasicLiteralNode basicLiteralNode) {
int port = Integer.parseInt(basicLiteralNode.literalToken().text());
return Optional.of(new ListenerInfo(listenerName, port));
}
} else if (functionArgumentNode.kind() == SyntaxKind.NAMED_ARG) {
// Listener with named argument - on new http:Listener(port = 9091)
NamedArgumentNode namedArgumentNode = (NamedArgumentNode) functionArgumentNode;
if (namedArgumentNode.argumentName().name().text().equals("port")) {
ExpressionNode expression = namedArgumentNode.expression();
if (expression.kind() == SyntaxKind.SIMPLE_NAME_REFERENCE) {
return getListenerInfo(listenerName, expression);
} else if (expression instanceof BasicLiteralNode basicLiteralNode) {
int port = Integer.parseInt(basicLiteralNode.literalToken().text());
return Optional.of(new ListenerInfo(listenerName, port));
}
}
}
}
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,14 @@ public void testMultiListenerExpose() {
Assert.assertEquals(serviceList.get(0).getListeners().get(0).getPort(), 9091);
Assert.assertEquals(serviceList.get(0).getListeners().get(1).getPort(), 9090);
}

@Test
public void testNamedArgListener() {
Path projectPath = Paths.get("src", "test", "resources", "service", "named-param-port");
BuildProject project = BuildProject.load(projectPath);
ProjectServiceInfo projectServiceInfo = new ProjectServiceInfo(project);
List<ServiceInfo> serviceList = projectServiceInfo.getServiceList();
Assert.assertEquals(serviceList.size(), 1);
Assert.assertEquals(serviceList.get(0).getListeners().get(0).getPort(), 8290);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
org = "anuruddha"
name = "namedparam"
version = "0.1.0"

[build-options]
observabilityIncluded = true
cloud = "k8s"
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2025 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
//
// WSO2 Inc. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/http;

listener http:Listener healthListener = new (port = 8290);

service http:Service /probe on healthListener {
resource function get readyz (http:Caller caller) returns error? {
check caller->respond("Resource is Ready");
}
}