diff --git a/compiler-plugin-test/src/test/java/io/ballerina/stdlib/persist/compiler/CompilerPluginTest.java b/compiler-plugin-test/src/test/java/io/ballerina/stdlib/persist/compiler/CompilerPluginTest.java index 74fa43cd..2d8e8a09 100644 --- a/compiler-plugin-test/src/test/java/io/ballerina/stdlib/persist/compiler/CompilerPluginTest.java +++ b/compiler-plugin-test/src/test/java/io/ballerina/stdlib/persist/compiler/CompilerPluginTest.java @@ -97,6 +97,11 @@ public void skipValidationsForBalProjectFiles() { Assert.assertEquals(diagnosticResult.diagnosticCount(), 0); } + @Test + public void validateWithOldPersistTomlConfig() { + getErrorDiagnostics("project_8", "field-types.bal", 0); + } + @Test public void validateTheProjectForNewGenerateCmd() { Path projectDirPath = Paths.get("src", "test", "resources", "project_7"). diff --git a/compiler-plugin-test/src/test/resources/project_7/Ballerina.toml b/compiler-plugin-test/src/test/resources/project_7/Ballerina.toml index a7edd720..540bcdfb 100644 --- a/compiler-plugin-test/src/test/resources/project_7/Ballerina.toml +++ b/compiler-plugin-test/src/test/resources/project_7/Ballerina.toml @@ -2,3 +2,8 @@ org = "root" name = "project_7" version = "0.1.0" + +[[tool.persist]] +id = "project7" +options.datastore = "postgresql" +filePath = "persist/model.bal" \ No newline at end of file diff --git a/compiler-plugin-test/src/test/resources/project_8/Ballerina.toml b/compiler-plugin-test/src/test/resources/project_8/Ballerina.toml new file mode 100644 index 00000000..95501f6b --- /dev/null +++ b/compiler-plugin-test/src/test/resources/project_8/Ballerina.toml @@ -0,0 +1,7 @@ +[package] +org = "root" +name = "project_2" +version = "0.1.0" + +[persist] +datastore = "postgresql" diff --git a/compiler-plugin-test/src/test/resources/project_8/persist/field-types.bal b/compiler-plugin-test/src/test/resources/project_8/persist/field-types.bal new file mode 100644 index 00000000..1ee2c1b6 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/project_8/persist/field-types.bal @@ -0,0 +1,11 @@ +import ballerina/persist as _; + +public type Employee record {| + readonly string id; + string firstName; + string lastName; + string email; + string phone; + string? managerId; + string jobTitle; +|}; diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/Constants.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/Constants.java index 7ec887dc..22e42c18 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/Constants.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/Constants.java @@ -23,8 +23,10 @@ */ public final class Constants { public static final String PERSIST_DIRECTORY = "persist"; - public static final String PERSIST = "tool.persist"; - public static final String DATASTORE = "options.datastore"; + public static final String TOOL_PERSIST = "tool.persist"; + public static final String PERSIST = "persist"; + public static final String OPTIONS_DATASTORE = "options.datastore"; + public static final String DATASTORE = "datastore"; public static final String TIME_MODULE = "time"; public static final String EMPTY_STRING = ""; public static final String ARRAY = "[]"; diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/Utils.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/Utils.java index a5442213..4ae64fdc 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/Utils.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/Utils.java @@ -32,6 +32,7 @@ import io.ballerina.toml.syntax.tree.NodeList; import io.ballerina.toml.syntax.tree.SyntaxTree; import io.ballerina.toml.syntax.tree.TableArrayNode; +import io.ballerina.toml.syntax.tree.TableNode; import io.ballerina.tools.diagnostics.Diagnostic; import io.ballerina.tools.diagnostics.DiagnosticProperty; import io.ballerina.tools.diagnostics.DiagnosticSeverity; @@ -188,16 +189,24 @@ public static String getDatastore(SyntaxNodeAnalysisContext ctx) throws BalExcep DocumentNode rootNote = syntaxTree.rootNode(); NodeList nodeList = rootNote.members(); for (DocumentMemberDeclarationNode member : nodeList) { - if (member instanceof TableArrayNode node) { - String tableName = node.identifier().toSourceCode().trim(); + if (member instanceof TableArrayNode arrNode) { + String tableName = arrNode.identifier().toSourceCode().trim(); + if (tableName.equals(Constants.TOOL_PERSIST)) { + for (KeyValueNode field : arrNode.fields()) { + if (field.identifier().toSourceCode().trim().equals(Constants.OPTIONS_DATASTORE)) { + return field.value().toSourceCode().trim().replaceAll("\"", ""); + } + } + } + } else if (member instanceof TableNode tableNode) { + String tableName = tableNode.identifier().toSourceCode().trim(); if (tableName.equals(Constants.PERSIST)) { - for (KeyValueNode field : node.fields()) { + for (KeyValueNode field : tableNode.fields()) { if (field.identifier().toSourceCode().trim().equals(Constants.DATASTORE)) { return field.value().toSourceCode().trim().replaceAll("\"", ""); } } } - } } throw new BalException("the persist.datastore configuration does not exist in the Ballerina.toml file"); @@ -226,16 +235,24 @@ public static String getDatastore(CodeActionContext ctx) throws BalException { DocumentNode rootNote = syntaxTree.rootNode(); NodeList nodeList = rootNote.members(); for (DocumentMemberDeclarationNode member : nodeList) { - if (member instanceof TableArrayNode node) { - String tableName = node.identifier().toSourceCode().trim(); + if (member instanceof TableArrayNode arrNode) { + String tableName = arrNode.identifier().toSourceCode().trim(); + if (tableName.equals(Constants.TOOL_PERSIST)) { + for (KeyValueNode field : arrNode.fields()) { + if (field.identifier().toSourceCode().trim().equals(Constants.OPTIONS_DATASTORE)) { + return field.value().toSourceCode().trim().replaceAll("\"", ""); + } + } + } + } else if (member instanceof TableNode tableNode) { + String tableName = tableNode.identifier().toSourceCode().trim(); if (tableName.equals(Constants.PERSIST)) { - for (KeyValueNode field : node.fields()) { + for (KeyValueNode field : tableNode.fields()) { if (field.identifier().toSourceCode().trim().equals(Constants.DATASTORE)) { return field.value().toSourceCode().trim().replaceAll("\"", ""); } } } - } } throw new BalException("the persist.datastore configuration does not exist in the Ballerina.toml file"); diff --git a/gradle.properties b/gradle.properties index 88470dc4..cf110374 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ testngVersion=7.6.1 gsonVersion=2.10.1 ballerinaGradlePluginVersion=2.0.1 -ballerinaLangVersion=2201.9.0-20240216-054100-84e1bc71 +ballerinaLangVersion=2201.9.0-20240229-103900-a949e6d4 # Direct Dependencies