Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…allerina-data-xmldata into issue_6355
  • Loading branch information
prakanth97 committed May 27, 2024
2 parents 98bf3a4 + 0e66df4 commit 666051e
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-timestamped-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ jobs:
call_workflow:
name: Run Build Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-standard-library/.github/workflows/build-timestamp-master-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@main
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/build-with-bal-test-graalvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
call_stdlib_workflow:
name: Run StdLib Workflow
if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }}
uses: ballerina-platform/ballerina-standard-library/.github/workflows/build-with-bal-test-graalvm-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-template.yml@main
with:
lang_tag: ${{ inputs.lang_tag }}
lang_version: ${{ inputs.lang_version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/central-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
call_workflow:
name: Run Central Publish Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-standard-library/.github/workflows/central-publish-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@main
secrets: inherit
with:
environment: ${{ github.event.inputs.environment }}
2 changes: 1 addition & 1 deletion .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
call_workflow:
name: Run Release Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-standard-library/.github/workflows/release-package-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/release-package-template.yml@main
secrets: inherit
with:
package-name: data.xmldata
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ jobs:
call_workflow:
name: Run PR Build Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-standard-library/.github/workflows/pull-request-build-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@main
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/trivy-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ jobs:
call_workflow:
name: Run Trivy Scan Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-standard-library/.github/workflows/trivy-scan-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@main
secrets: inherit
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Ballerina XML Data Library

[![Build](https://github.com/ballerina-platform/module-ballerina-data.xmldata/actions/workflows/build-timestamped-master.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerina-data.xmldata/actions/workflows/build-timestamped-master.yml)
[![codecov](https://codecov.io/gh/ballerina-platform/module-ballerina-data.xmldata/branch/main/graph/badge.svg)](https://codecov.io/gh/ballerina-platform/module-ballerina-data.xmldata)
[![Trivy](https://github.com/ballerina-platform/module-ballerina-data.xmldata/actions/workflows/trivy-scan.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerina-data.xmldata/actions/workflows/trivy-scan.yml)
[![GraalVM Check](https://github.com/ballerina-platform/module-ballerina-data.xmldata/actions/workflows/build-with-bal-test-graalvm.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerina-data.xmldata/actions/workflows/build-with-bal-test-graalvm.yml)
[![GitHub Last Commit](https://img.shields.io/github/last-commit/ballerina-platform/module-ballerina-data.xmldata.svg)](https://github.com/ballerina-platform/module-ballerina-data.xmldata/commits/master)
[![Github issues](https://img.shields.io/github/issues/ballerina-platform/ballerina-standard-library/module/data.xmldata.svg?label=Open%20Issues)](https://github.com/ballerina-platform/ballerina-standard-library/labels/module%2Fdata.xmldata)

The Ballerina XML Data Library is a comprehensive toolkit designed to facilitate the handling and manipulation of XML data within Ballerina applications. It streamlines the process of converting XML data to native Ballerina data types, enabling developers to work with XML content seamlessly and efficiently.

This library is the refined successor of the `ballerina/xmldata` module, incorporating enhanced functionalities and improved performance.
Expand Down
2 changes: 1 addition & 1 deletion ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export = ["data.xmldata"]
groupId = "io.ballerina.lib"
artifactId = "data-native"
version = "0.1.0"
path = "../native/build/libs/data.xmldata-native-0.1.0-SNAPSHOT.jar"
path = "../native/build/libs/data.xmldata-native-0.1.0.jar"
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 = "constraint-compiler-plugin"
class = "io.ballerina.lib.data.xmldata.compiler.XmldataCompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/data.xmldata-compiler-plugin-0.1.0-SNAPSHOT.jar"
path = "../compiler-plugin/build/libs/data.xmldata-compiler-plugin-0.1.0.jar"
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.9.0-20240403-163200-09e0471e"
distribution-version = "2201.9.0"

[[package]]
org = "ballerina"
Expand Down
3 changes: 3 additions & 0 deletions ballerina/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,6 @@ build.dependsOn deleteDependencyTomlFiles

test.dependsOn ":${packageName}-native:build"
test.dependsOn ":${packageName}-compiler-plugin:build"

publish.dependsOn build
publishToMavenLocal.dependsOn build
8 changes: 8 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
coverage:
precision: 2
round: down
range: "60...80"
status:
project:
default:
target: 80
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,23 @@ public void testUnionTypeNegative() {
Assert.assertEquals(errorDiagnosticsList.get(5).diagnosticInfo().messageFormat(),
"invalid field: duplicate field found");
}

@Test
public void testCompilerPluginWithAProjectWithSubModule() {
DiagnosticResult diagnosticResult =
CompilerPluginTestUtils.loadPackage("sample_package_10").getCompilation().diagnosticResult();
List<Diagnostic> errorDiagnosticsList = diagnosticResult.diagnostics().stream()
.filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR))
.collect(Collectors.toList());
Assert.assertEquals(errorDiagnosticsList.size(), 1);
Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(),
"invalid field: duplicate field found");

List<Diagnostic> warningDiagnosticsList = diagnosticResult.diagnostics().stream()
.filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.WARNING))
.collect(Collectors.toList());
Assert.assertEquals(warningDiagnosticsList.size(), 1);
Assert.assertEquals(warningDiagnosticsList.get(0).diagnosticInfo().messageFormat(),
"invalid annotation attachment: child record does not allow name annotation");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
org = "xmldata_test"
name = "sample_10"
version = "0.1.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import ballerina/data.xmldata;

@xmldata:Name {
value: "Data"
}
type Data3 record {|
Data4 a;
|};

@xmldata:Name {
value: "A"
}
type Data4 record {|
string b;
|};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import ballerina/data.xmldata;

type Data record {|
string A;
@xmldata:Name {
value: "A"
}
string B;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@
import io.ballerina.compiler.syntax.tree.ModuleMemberDeclarationNode;
import io.ballerina.compiler.syntax.tree.ModulePartNode;
import io.ballerina.compiler.syntax.tree.ModuleVariableDeclarationNode;
import io.ballerina.compiler.syntax.tree.NameReferenceNode;
import io.ballerina.compiler.syntax.tree.Node;
import io.ballerina.compiler.syntax.tree.QualifiedNameReferenceNode;
import io.ballerina.compiler.syntax.tree.SyntaxKind;
import io.ballerina.compiler.syntax.tree.TypeDefinitionNode;
import io.ballerina.compiler.syntax.tree.VariableDeclarationNode;
import io.ballerina.lib.data.xmldata.compiler.objects.QualifiedName;
import io.ballerina.projects.Document;
import io.ballerina.projects.plugins.AnalysisTask;
import io.ballerina.projects.plugins.SyntaxNodeAnalysisContext;
import io.ballerina.tools.diagnostics.Diagnostic;
Expand All @@ -70,13 +71,11 @@
public class XmldataRecordFieldValidator implements AnalysisTask<SyntaxNodeAnalysisContext> {

private SemanticModel semanticModel;
private Document srcFile;
private final HashMap<Location, DiagnosticInfo> allDiagnosticInfo = new HashMap<>();

@Override
public void perform(SyntaxNodeAnalysisContext ctx) {
semanticModel = ctx.semanticModel();
srcFile = ctx.currentPackage().getDefaultModule().document(ctx.documentId());
List<Diagnostic> diagnostics = semanticModel.diagnostics();
boolean erroneousCompilation = diagnostics.stream()
.anyMatch(d -> d.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR));
Expand Down Expand Up @@ -258,15 +257,16 @@ private void detectNameAnnotUsageWarning(RecordFieldSymbol fieldSymbol, SyntaxNo
return;
}

Optional<Symbol> symbol = semanticModel.symbol(srcFile, location.get().lineRange().startLine());
if (symbol.isEmpty()) {
TypeSymbol typeSymbol = fieldSymbol.typeDescriptor();
if (typeSymbol.typeKind() != TypeDescKind.TYPE_REFERENCE) {
return;
}

if (symbol.get().kind() != SymbolKind.TYPE_DEFINITION) {
TypeReferenceTypeSymbol typeReferenceTypeSymbol = (TypeReferenceTypeSymbol) typeSymbol;
Symbol symbol = typeReferenceTypeSymbol.definition();
if (symbol == null || symbol.kind() != SymbolKind.TYPE_DEFINITION) {
return;
}
TypeDefinitionSymbol typeDefinitionSymbol = (TypeDefinitionSymbol) symbol.get();
TypeDefinitionSymbol typeDefinitionSymbol = (TypeDefinitionSymbol) symbol;
typeDefinitionSymbol.annotations().forEach(annotationSymbol -> {
if (!isAnnotFromXmldata(annotationSymbol)) {
return;
Expand Down Expand Up @@ -386,6 +386,16 @@ private boolean isParseFunctionFromXmldata(ExpressionNode expressionNode) {
if (expressionNode.kind() != SyntaxKind.FUNCTION_CALL) {
return false;
}

NameReferenceNode nameReferenceNode = ((FunctionCallExpressionNode) expressionNode).functionName();
if (nameReferenceNode.kind() != SyntaxKind.QUALIFIED_NAME_REFERENCE) {
return false;
}
String prefix = ((QualifiedNameReferenceNode) nameReferenceNode).modulePrefix().text();
if (!prefix.equals(Constants.XMLDATA)) {
return false;
}

String functionName = ((FunctionCallExpressionNode) expressionNode).functionName().toSourceCode().trim();
return functionName.contains(Constants.PARSE_STRING) || functionName.contains(Constants.PARSE_BYTES)
|| functionName.contains(Constants.PARSE_STREAM) || functionName.contains(Constants.PARSE_AS_TYPE);
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
org.gradle.caching=true
group=io.ballerina.stdlib
version=0.1.0-SNAPSHOT
ballerinaLangVersion=2201.9.0-20240403-163200-09e0471e
group=io.ballerina.lib
version=0.1.1-SNAPSHOT
ballerinaLangVersion=2201.9.0

checkstyleToolVersion=10.12.0
puppycrawlCheckstyleVersion=10.12.0
Expand Down

0 comments on commit 666051e

Please sign in to comment.