Skip to content

Commit

Permalink
Do validation for old persist toml configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhashinee committed Mar 6, 2024
1 parent a4cf7cc commit 166f1e4
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
org = "root"
name = "project_7"
version = "0.1.0"

[[tool.persist]]
id = "project7"
options.datastore = "postgresql"
filePath = "persist/model.bal"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
org = "root"
name = "project_2"
version = "0.1.0"

[persist]
datastore = "postgresql"
Original file line number Diff line number Diff line change
@@ -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;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -188,16 +189,24 @@ public static String getDatastore(SyntaxNodeAnalysisContext ctx) throws BalExcep
DocumentNode rootNote = syntaxTree.rootNode();
NodeList<DocumentMemberDeclarationNode> 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");
Expand Down Expand Up @@ -226,16 +235,24 @@ public static String getDatastore(CodeActionContext ctx) throws BalException {
DocumentNode rootNote = syntaxTree.rootNode();
NodeList<DocumentMemberDeclarationNode> 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");
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 166f1e4

Please sign in to comment.