Skip to content

Commit

Permalink
Merge pull request #129 from ayeshLK/compiler_plugin
Browse files Browse the repository at this point in the history
Fix identified issues in SL Alpha 5 distribution
  • Loading branch information
Maninda authored May 5, 2021
2 parents 75b48a9 + 60f807e commit b894f9e
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 10 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Multipart content delivery using websubhub-client.
- Subscription Lease seconds expired event.

## [0.2.0-beta.1] - 2021-05-06

### Fixed
- [Fix the listener initialization with inline configs compiler plugin error](https://github.com/ballerina-platform/ballerina-standard-library/issues/1304)

## [0.2.0-alpha8] - 2021-04-22
### Added
- [Add compiler plugin to validate websubhub:Service](https://github.com/ballerina-platform/ballerina-standard-library/issues/1099)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ public void testCompilerPluginForParamOrder() {
Assert.assertEquals(diagnostic.message(), expectedMsg);
}

@Test
public void testValidServiceDeclarationWithIncludedRecordParams() {
Package currentPackage = loadPackage("sample_14");
PackageCompilation compilation = currentPackage.getCompilation();
DiagnosticResult diagnosticResult = compilation.diagnosticResult();
Assert.assertEquals(diagnosticResult.diagnostics().size(), 0);
}

private Package loadPackage(String path) {
Path projectDirPath = RESOURCE_DIRECTORY.resolve(path);
BuildProject project = BuildProject.load(getEnvironmentBuilder(), projectDirPath);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
org = "websubhub_test"
name = "sample_14"
version = "0.1.0"

[build-options]
observabilityIncluded = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import ballerina/websubhub as foo;
import ballerina/http;
import ballerina/io;

listener foo:Listener securedHub = new(9090,
secureSocket = {
key: {
certFile: "../resources/public.crt",
keyFile: "../resources/private.key"
}
}
);

service /websubhub on securedHub {

isolated remote function onRegisterTopic(foo:TopicRegistration message)
returns foo:TopicRegistrationSuccess|foo:TopicRegistrationError {
if (message.topic == "test") {
return foo:TOPIC_REGISTRATION_SUCCESS;
} else {
return foo:TOPIC_REGISTRATION_ERROR;
}
}

isolated remote function onDeregisterTopic(foo:TopicDeregistration message, http:Request baseRequest)
returns foo:TopicDeregistrationSuccess|foo:TopicDeregistrationError {

map<string> body = { isDeregisterSuccess: "true" };
foo:TopicDeregistrationSuccess deregisterResult = {
body
};
if (message.topic == "test") {
return deregisterResult;
} else {
return error foo:TopicDeregistrationError("Topic Deregistration Failed!");
}
}

isolated remote function onUpdateMessage(foo:UpdateMessage message)
returns foo:Acknowledgement|foo:UpdateMessageError {
return foo:ACKNOWLEDGEMENT;
}

isolated remote function onSubscription(foo:Subscription msg)
returns foo:SubscriptionAccepted|foo:SubscriptionPermanentRedirect|foo:SubscriptionTemporaryRedirect
|foo:BadSubscriptionError|foo:InternalSubscriptionError {
foo:SubscriptionAccepted successResult = {
body: <map<string>>{
isSuccess: "true"
}
};
if (msg.hubTopic == "test") {
return successResult;
} else if (msg.hubTopic == "test1") {
return successResult;
} else {
return error foo:BadSubscriptionError("Bad subscription");
}
}

isolated remote function onSubscriptionValidation(foo:Subscription msg)
returns foo:SubscriptionDeniedError? {
if (msg.hubTopic == "test1") {
return error foo:SubscriptionDeniedError("Denied subscription for topic 'test1'");
}
return ();
}

isolated remote function onSubscriptionIntentVerified(foo:VerifiedSubscription msg) {
io:println("Subscription Intent verified invoked!");
}

isolated remote function onUnsubscription(foo:Unsubscription msg)
returns foo:UnsubscriptionAccepted|foo:BadUnsubscriptionError|foo:InternalUnsubscriptionError {
if (msg.hubTopic == "test" || msg.hubTopic == "test1" ) {
foo:UnsubscriptionAccepted successResult = {
body: <map<string>>{
isSuccess: "true"
}
};
return successResult;
} else {
return error foo:BadUnsubscriptionError("Denied unsubscription for topic '" + <string> msg.hubTopic + "'");
}
}

isolated remote function onUnsubscriptionValidation(foo:Unsubscription msg)
returns foo:UnsubscriptionDeniedError? {
if (msg.hubTopic == "test1") {
return error foo:UnsubscriptionDeniedError("Denied subscription for topic 'test1'");
}
return ();
}

isolated remote function onUnsubscriptionIntentVerified(foo:VerifiedUnsubscription msg){
io:println("Unsubscription Intent verified invoked!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import io.ballerina.compiler.api.symbols.UnionTypeSymbol;
import io.ballerina.compiler.syntax.tree.FunctionArgumentNode;
import io.ballerina.compiler.syntax.tree.FunctionDefinitionNode;
import io.ballerina.compiler.syntax.tree.NamedArgumentNode;
import io.ballerina.compiler.syntax.tree.NodeLocation;
import io.ballerina.compiler.syntax.tree.ParenthesizedArgList;
import io.ballerina.compiler.syntax.tree.PositionalArgumentNode;
import io.ballerina.compiler.syntax.tree.RestArgumentNode;
import io.ballerina.compiler.syntax.tree.SeparatedNodeList;
import io.ballerina.compiler.syntax.tree.ServiceDeclarationNode;
import io.ballerina.compiler.syntax.tree.SyntaxKind;
Expand Down Expand Up @@ -151,20 +153,34 @@ private void validateListenerArguments(SyntaxNodeAnalysisContext context,
private void verifyListenerArgType(SyntaxNodeAnalysisContext context, NodeLocation location,
SeparatedNodeList<FunctionArgumentNode> functionArgs) {
if (functionArgs.size() >= 2) {
PositionalArgumentNode firstArg = (PositionalArgumentNode) functionArgs.get(0);
PositionalArgumentNode secondArg = (PositionalArgumentNode) functionArgs.get(1);
SyntaxKind firstArgSyntaxKind = firstArg.expression().kind();
SyntaxKind secondArgSyntaxKind = secondArg.expression().kind();
if ((firstArgSyntaxKind == SyntaxKind.SIMPLE_NAME_REFERENCE
|| firstArgSyntaxKind == SyntaxKind.MAPPING_CONSTRUCTOR)
&& (secondArgSyntaxKind == SyntaxKind.SIMPLE_NAME_REFERENCE
|| secondArgSyntaxKind == SyntaxKind.MAPPING_CONSTRUCTOR)) {
WebSubHubDiagnosticCodes errorCode = WebSubHubDiagnosticCodes.WEBSUBHUB_101;
updateContext(context, errorCode, location);
Optional<SyntaxKind> firstArgSyntaxKindOpt = getArgSyntaxKind(functionArgs.get(0));
Optional<SyntaxKind> secondArgSyntaxKindOpt = getArgSyntaxKind(functionArgs.get(1));
if (firstArgSyntaxKindOpt.isPresent() && secondArgSyntaxKindOpt.isPresent()) {
SyntaxKind firstArgSyntaxKind = firstArgSyntaxKindOpt.get();
SyntaxKind secondArgSyntaxKind = secondArgSyntaxKindOpt.get();
if ((firstArgSyntaxKind == SyntaxKind.SIMPLE_NAME_REFERENCE
|| firstArgSyntaxKind == SyntaxKind.MAPPING_CONSTRUCTOR)
&& (secondArgSyntaxKind == SyntaxKind.SIMPLE_NAME_REFERENCE
|| secondArgSyntaxKind == SyntaxKind.MAPPING_CONSTRUCTOR)) {
WebSubHubDiagnosticCodes errorCode = WebSubHubDiagnosticCodes.WEBSUBHUB_101;
updateContext(context, errorCode, location);
}
}
}
}

private Optional<SyntaxKind> getArgSyntaxKind(FunctionArgumentNode argument) {
SyntaxKind syntaxKind = null;
if (argument instanceof PositionalArgumentNode) {
syntaxKind = ((PositionalArgumentNode) argument).expression().kind();
} else if (argument instanceof NamedArgumentNode) {
syntaxKind = ((NamedArgumentNode) argument).expression().kind();
} else if (argument instanceof RestArgumentNode) {
syntaxKind = ((RestArgumentNode) argument).expression().kind();
}
return Optional.ofNullable(syntaxKind);
}

private void validateRequiredMethodsImplemented(SyntaxNodeAnalysisContext context,
List<FunctionDefinitionNode> availableFunctionDeclarations,
NodeLocation location) {
Expand Down

0 comments on commit b894f9e

Please sign in to comment.