From c79b95833649abd298b6468010461850f06da6dc Mon Sep 17 00:00:00 2001 From: bhashinee Date: Mon, 13 May 2024 13:01:10 +0530 Subject: [PATCH 1/7] Ignore the validation for configurables --- .../cache/compiler/CompilerPluginTest.java | 9 +++++++ .../diagnostics/sample7/Ballerina.toml | 4 ++++ .../resources/diagnostics/sample7/main.bal | 24 +++++++++++++++++++ .../cache/compiler/CacheConfigValidator.java | 6 ++--- 4 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 compiler-plugin-tests/src/test/resources/diagnostics/sample7/Ballerina.toml create mode 100644 compiler-plugin-tests/src/test/resources/diagnostics/sample7/main.bal diff --git a/compiler-plugin-tests/src/test/java/io/ballerina/stdlib/cache/compiler/CompilerPluginTest.java b/compiler-plugin-tests/src/test/java/io/ballerina/stdlib/cache/compiler/CompilerPluginTest.java index fd22083b..6963abae 100644 --- a/compiler-plugin-tests/src/test/java/io/ballerina/stdlib/cache/compiler/CompilerPluginTest.java +++ b/compiler-plugin-tests/src/test/java/io/ballerina/stdlib/cache/compiler/CompilerPluginTest.java @@ -117,6 +117,15 @@ public void testConfigWithConstants() { Assert.assertEquals(errorDiagnosticsList.size(), 0); } + @Test + public void testConfigWithIncludedParams() { + DiagnosticResult diagnosticResult = loadPackage("sample7").getCompilation().diagnosticResult(); + List errorDiagnosticsList = diagnosticResult.diagnostics().stream() + .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) + .collect(Collectors.toList()); + Assert.assertEquals(errorDiagnosticsList.size(), 0); + } + private void assertValues(List errorDiagnosticsList) { long availableErrors = errorDiagnosticsList.size(); Assert.assertEquals(availableErrors, 5); diff --git a/compiler-plugin-tests/src/test/resources/diagnostics/sample7/Ballerina.toml b/compiler-plugin-tests/src/test/resources/diagnostics/sample7/Ballerina.toml new file mode 100644 index 00000000..38ad123e --- /dev/null +++ b/compiler-plugin-tests/src/test/resources/diagnostics/sample7/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "cache_test" +name = "sample7" +version = "0.1.0" diff --git a/compiler-plugin-tests/src/test/resources/diagnostics/sample7/main.bal b/compiler-plugin-tests/src/test/resources/diagnostics/sample7/main.bal new file mode 100644 index 00000000..99670a22 --- /dev/null +++ b/compiler-plugin-tests/src/test/resources/diagnostics/sample7/main.bal @@ -0,0 +1,24 @@ +// Copyright (c) 2024, WSO2 Inc. (http://www.wso2.org). +// +// 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/cache; + +configurable int capacity = 300; +const decimal CACHE_CLEANUP_INTERVAL = 900.0; + +public function main() returns error? { + cache:Cache cache = new(capacity = capacity , evictionFactor = 0.2, defaultMaxAge = 86400, cleanupInterval = CACHE_CLEANUP_INTERVAL); +} diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java index 8f1a7d6a..29e6e46c 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java @@ -218,9 +218,9 @@ private void validateConfig(String name, String value, SyntaxNodeAnalysisContext break; } } catch (NumberFormatException e) { - reportDiagnostic(ctx, location, DiagnosticsCodes.CACHE_106.getErrorCode(), - DiagnosticsCodes.CACHE_106.getError() + e.getMessage(), - DiagnosticsCodes.CACHE_106.getSeverity()); + // This occurs when there is a variable reference in the value in scenarios like having a + // constant or configurable. In such cases like configurable, we cannot validate the value as the value is + // resolved at runtime. Hence, ignoring the validation. } } From ed92925731a552cfe298689b5c757e4869aae4ba Mon Sep 17 00:00:00 2001 From: bhashinee Date: Tue, 14 May 2024 09:53:52 +0530 Subject: [PATCH 2/7] Add a test description --- .../io/ballerina/stdlib/cache/compiler/CompilerPluginTest.java | 3 ++- .../ballerina/stdlib/cache/compiler/CacheConfigValidator.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler-plugin-tests/src/test/java/io/ballerina/stdlib/cache/compiler/CompilerPluginTest.java b/compiler-plugin-tests/src/test/java/io/ballerina/stdlib/cache/compiler/CompilerPluginTest.java index 6963abae..e060566d 100644 --- a/compiler-plugin-tests/src/test/java/io/ballerina/stdlib/cache/compiler/CompilerPluginTest.java +++ b/compiler-plugin-tests/src/test/java/io/ballerina/stdlib/cache/compiler/CompilerPluginTest.java @@ -117,7 +117,8 @@ public void testConfigWithConstants() { Assert.assertEquals(errorDiagnosticsList.size(), 0); } - @Test + @Test(description = "Tests whether there are no compilation failures for constants and configurables as included " + + "params. Those validations will be ignored.") public void testConfigWithIncludedParams() { DiagnosticResult diagnosticResult = loadPackage("sample7").getCompilation().diagnosticResult(); List errorDiagnosticsList = diagnosticResult.diagnostics().stream() diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java index 29e6e46c..ca544e5d 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java @@ -220,7 +220,8 @@ private void validateConfig(String name, String value, SyntaxNodeAnalysisContext } catch (NumberFormatException e) { // This occurs when there is a variable reference in the value in scenarios like having a // constant or configurable. In such cases like configurable, we cannot validate the value as the value is - // resolved at runtime. Hence, ignoring the validation. + // resolved at runtime. Hence, ignoring the validation. And for constants, if they are not in the same file, + // we cannot read them from the compiler plugin. Hence, ignoring the validation. } } From 852eb0b68385820d69ed61cc3f8e8650456fd81e Mon Sep 17 00:00:00 2001 From: bhashinee Date: Tue, 14 May 2024 10:14:01 +0530 Subject: [PATCH 3/7] [Automated] Update native jar versions in toml files --- ballerina/Ballerina.toml | 6 +++--- ballerina/CompilerPlugin.toml | 2 +- ballerina/Dependencies.toml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index fa815ebf..4595e614 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerina" name = "cache" -version = "3.7.1" +version = "3.7.6" authors = ["Ballerina"] keywords = ["cache", "LRU"] repository = "https://github.com/ballerina-platform/module-ballerina-cache" @@ -15,5 +15,5 @@ graalvmCompatible = true [[platform.java17.dependency]] groupId = "io.ballerina.stdlib" artifactId = "cache-native" -version = "3.7.1" -path = "../native/build/libs/cache-native-3.7.1-SNAPSHOT.jar" +version = "3.7.6" +path = "../native/build/libs/cache-native-3.7.6.jar" diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index 25808855..a40bda0c 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,4 +3,4 @@ id = "cache-compiler-plugin" class = "io.ballerina.stdlib.cache.compiler.CacheCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/cache-compiler-plugin-3.7.1-SNAPSHOT.jar" +path = "../compiler-plugin/build/libs/cache-compiler-plugin-3.7.6.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 0f5f50ab..d8a24000 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -10,7 +10,7 @@ distribution-version = "2201.8.0" [[package]] org = "ballerina" name = "cache" -version = "3.7.1" +version = "3.7.6" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "jballerina.java"}, From 8adc70a2ee627df005c8a2881f8e12d605c72a3f Mon Sep 17 00:00:00 2001 From: bhashinee Date: Tue, 14 May 2024 10:18:20 +0530 Subject: [PATCH 4/7] [Automated] Update native jar versions in toml files --- ballerina/Ballerina.toml | 6 +++--- ballerina/CompilerPlugin.toml | 2 +- ballerina/Dependencies.toml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 4595e614..fa815ebf 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerina" name = "cache" -version = "3.7.6" +version = "3.7.1" authors = ["Ballerina"] keywords = ["cache", "LRU"] repository = "https://github.com/ballerina-platform/module-ballerina-cache" @@ -15,5 +15,5 @@ graalvmCompatible = true [[platform.java17.dependency]] groupId = "io.ballerina.stdlib" artifactId = "cache-native" -version = "3.7.6" -path = "../native/build/libs/cache-native-3.7.6.jar" +version = "3.7.1" +path = "../native/build/libs/cache-native-3.7.1-SNAPSHOT.jar" diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index a40bda0c..25808855 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,4 +3,4 @@ id = "cache-compiler-plugin" class = "io.ballerina.stdlib.cache.compiler.CacheCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/cache-compiler-plugin-3.7.6.jar" +path = "../compiler-plugin/build/libs/cache-compiler-plugin-3.7.1-SNAPSHOT.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index d8a24000..0f5f50ab 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -10,7 +10,7 @@ distribution-version = "2201.8.0" [[package]] org = "ballerina" name = "cache" -version = "3.7.6" +version = "3.7.1" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "jballerina.java"}, From b3451eb683b173e95a76568e64d78c1661fa6534 Mon Sep 17 00:00:00 2001 From: bhashinee Date: Tue, 14 May 2024 10:19:01 +0530 Subject: [PATCH 5/7] Update the comment --- .../ballerina/stdlib/cache/compiler/CacheConfigValidator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java index ca544e5d..de6f3442 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java @@ -221,7 +221,8 @@ private void validateConfig(String name, String value, SyntaxNodeAnalysisContext // This occurs when there is a variable reference in the value in scenarios like having a // constant or configurable. In such cases like configurable, we cannot validate the value as the value is // resolved at runtime. Hence, ignoring the validation. And for constants, if they are not in the same file, - // we cannot read them from the compiler plugin. Hence, ignoring the validation. + // we cannot read them from the compiler plugin. Hence, ignoring the validation. These will be validated + // runtime. } } From 6b829019446b6741ded20b4be4a2ac7c463cd7b3 Mon Sep 17 00:00:00 2001 From: bhashinee Date: Tue, 14 May 2024 10:22:52 +0530 Subject: [PATCH 6/7] Update the change log --- changelog.md | 6 +++++- .../stdlib/cache/compiler/CacheConfigValidator.java | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 24ecca2f..f23ca10c 100644 --- a/changelog.md +++ b/changelog.md @@ -4,7 +4,11 @@ This file contains all the notable changes done to the Ballerina Cache package t The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [unreleased] +### Fixed +- [Fix the compilation failure when constants and configurables are used in cache config as included params](https://github.com/ballerina-platform/ballerina-library/issues/6036) + +## [3.7.1] - 2024-01-11 ### Fixed - [Fix the compilation failure when constants are used in cache config](https://github.com/ballerina-platform/ballerina-library/issues/5915) diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java index de6f3442..a7f106af 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java @@ -218,6 +218,7 @@ private void validateConfig(String name, String value, SyntaxNodeAnalysisContext break; } } catch (NumberFormatException e) { + // ignore // This occurs when there is a variable reference in the value in scenarios like having a // constant or configurable. In such cases like configurable, we cannot validate the value as the value is // resolved at runtime. Hence, ignoring the validation. And for constants, if they are not in the same file, From 56889119f2c35b7a6ab598fd201f715df4bd5943 Mon Sep 17 00:00:00 2001 From: Bhashinee Date: Tue, 14 May 2024 16:09:38 +0530 Subject: [PATCH 7/7] Update compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java Co-authored-by: Danesh Kuruppu --- .../io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java index a7f106af..de6f3442 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java @@ -218,7 +218,6 @@ private void validateConfig(String name, String value, SyntaxNodeAnalysisContext break; } } catch (NumberFormatException e) { - // ignore // This occurs when there is a variable reference in the value in scenarios like having a // constant or configurable. In such cases like configurable, we cannot validate the value as the value is // resolved at runtime. Hence, ignoring the validation. And for constants, if they are not in the same file,