From e7285217314cbe8dccc6eadd11d78c72cd3dd91a Mon Sep 17 00:00:00 2001 From: Nipuna Fernando Date: Fri, 11 Aug 2023 23:51:57 +0530 Subject: [PATCH] Build the examples --- .gitignore | 1 + README.md | 5 +- {excel => ballerina}/Ballerina.toml | 0 {excel => ballerina}/Module.md | 2 +- {excel => ballerina}/Package.md | 0 {excel => ballerina}/client.bal | 0 {excel => ballerina}/constants.bal | 0 {excel => ballerina}/icon.png | Bin {excel => ballerina}/tests/test.bal | 0 {excel => ballerina}/types.bal | 0 {excel => ballerina}/utils.bal | 0 examples/README.md | 34 +++++++++++++ {samples => examples}/add_chart.bal | 0 {samples => examples}/add_table.bal | 0 {samples => examples}/add_worksheet.bal | 0 examples/build.sh | 47 ++++++++++++++++++ .../calculate_workbook_application.bal | 0 {samples => examples}/create_column.bal | 4 +- {samples => examples}/create_row.bal | 0 {samples => examples}/delete_chart.bal | 0 {samples => examples}/delete_column.bal | 0 {samples => examples}/delete_row.bal | 0 {samples => examples}/delete_table.bal | 0 {samples => examples}/delete_worksheet.bal | 0 {samples => examples}/get_cell.bal | 0 {samples => examples}/get_chart.bal | 0 {samples => examples}/get_chart_image .bal | 0 {samples => examples}/get_table.bal | 0 .../get_workbook_application.bal | 0 {samples => examples}/get_worksheet.bal | 0 {samples => examples}/list_charts.bal | 0 {samples => examples}/list_columns.bal | 0 {samples => examples}/list_rows.bal | 0 {samples => examples}/list_tables.bal | 0 {samples => examples}/list_worksheets.bal | 0 {samples => examples}/reset_chart_image.bal | 0 {samples => examples}/set_chart_position.bal | 0 {samples => examples}/update_chart.bal | 2 +- {samples => examples}/update_column.bal | 2 +- {samples => examples}/update_row.bal | 0 {samples => examples}/update_table.bal | 0 {samples => examples}/update_worksheet.bal | 0 42 files changed, 90 insertions(+), 7 deletions(-) rename {excel => ballerina}/Ballerina.toml (100%) rename {excel => ballerina}/Module.md (96%) rename {excel => ballerina}/Package.md (100%) rename {excel => ballerina}/client.bal (100%) rename {excel => ballerina}/constants.bal (100%) rename {excel => ballerina}/icon.png (100%) rename {excel => ballerina}/tests/test.bal (100%) rename {excel => ballerina}/types.bal (100%) rename {excel => ballerina}/utils.bal (100%) create mode 100644 examples/README.md rename {samples => examples}/add_chart.bal (100%) rename {samples => examples}/add_table.bal (100%) rename {samples => examples}/add_worksheet.bal (100%) create mode 100755 examples/build.sh rename {samples => examples}/calculate_workbook_application.bal (100%) rename {samples => examples}/create_column.bal (96%) rename {samples => examples}/create_row.bal (100%) rename {samples => examples}/delete_chart.bal (100%) rename {samples => examples}/delete_column.bal (100%) rename {samples => examples}/delete_row.bal (100%) rename {samples => examples}/delete_table.bal (100%) rename {samples => examples}/delete_worksheet.bal (100%) rename {samples => examples}/get_cell.bal (100%) rename {samples => examples}/get_chart.bal (100%) rename {samples => examples}/get_chart_image .bal (100%) rename {samples => examples}/get_table.bal (100%) rename {samples => examples}/get_workbook_application.bal (100%) rename {samples => examples}/get_worksheet.bal (100%) rename {samples => examples}/list_charts.bal (100%) rename {samples => examples}/list_columns.bal (100%) rename {samples => examples}/list_rows.bal (100%) rename {samples => examples}/list_tables.bal (100%) rename {samples => examples}/list_worksheets.bal (100%) rename {samples => examples}/reset_chart_image.bal (100%) rename {samples => examples}/set_chart_position.bal (100%) rename {samples => examples}/update_chart.bal (96%) rename {samples => examples}/update_column.bal (96%) rename {samples => examples}/update_row.bal (100%) rename {samples => examples}/update_table.bal (100%) rename {samples => examples}/update_worksheet.bal (100%) diff --git a/.gitignore b/.gitignore index 25e83cb..930db88 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ .mtj.tmp/ # Package Files # +*.jar *.war *.nar *.ear diff --git a/README.md b/README.md index 89f2ce0..32002d7 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ Ballerina Microsoft Excel Connector =================== [![Build Status](https://github.com/ballerina-platform/module-ballerinax-microsoft.excel/workflows/CI/badge.svg)](https://github.com/ballerina-platform/module-ballerinax-microsoft.excel/actions?query=workflow%3ACI) +[![codecov](https://codecov.io/gh/ballerina-platform/module-ballerinax-microsoft.excel/branch/master/graph/badge.svg)](https://codecov.io/gh/ballerina-platform/module-ballerinax-microsoft.excel) [![GitHub Last Commit](https://img.shields.io/github/last-commit/ballerina-platform/module-ballerinax-microsoft.excel.svg)](https://github.com/ballerina-platform/module-ballerinax-microsoft.excel/commits/master) [![GraalVM Check](https://github.com/ballerina-platform/module-ballerinax-microsoft.excel/actions/workflows/build-with-bal-test-native.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerinax-microsoft.excel/actions/workflows/build-with-bal-test-native.yml) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) @@ -26,11 +27,11 @@ Execute the commands below to build from the source after installing Ballerina. 1. To build the package: ``` - bal pack ./excel + bal build ./ballerina ``` 2. To run tests after build: ``` - bal test ./excel + bal test ./ballerina ``` ## Contributing to Ballerina As an open source project, Ballerina welcomes contributions from the community. diff --git a/excel/Ballerina.toml b/ballerina/Ballerina.toml similarity index 100% rename from excel/Ballerina.toml rename to ballerina/Ballerina.toml diff --git a/excel/Module.md b/ballerina/Module.md similarity index 96% rename from excel/Module.md rename to ballerina/Module.md index 638c15b..48f7cc6 100644 --- a/excel/Module.md +++ b/ballerina/Module.md @@ -43,4 +43,4 @@ Following is an example on how to add a worksheet using the connector. 2. Use `bal run` command to compile and run the Ballerina program. -**[You can find a list of samples here](https://github.com/ballerina-platform/module-ballerinax-microsoft.excel/tree/master/samples)** +**[You can find a list of samples here](https://github.com/ballerina-platform/module-ballerinax-microsoft.excel/tree/master/examples)** diff --git a/excel/Package.md b/ballerina/Package.md similarity index 100% rename from excel/Package.md rename to ballerina/Package.md diff --git a/excel/client.bal b/ballerina/client.bal similarity index 100% rename from excel/client.bal rename to ballerina/client.bal diff --git a/excel/constants.bal b/ballerina/constants.bal similarity index 100% rename from excel/constants.bal rename to ballerina/constants.bal diff --git a/excel/icon.png b/ballerina/icon.png similarity index 100% rename from excel/icon.png rename to ballerina/icon.png diff --git a/excel/tests/test.bal b/ballerina/tests/test.bal similarity index 100% rename from excel/tests/test.bal rename to ballerina/tests/test.bal diff --git a/excel/types.bal b/ballerina/types.bal similarity index 100% rename from excel/types.bal rename to ballerina/types.bal diff --git a/excel/utils.bal b/ballerina/utils.bal similarity index 100% rename from excel/utils.bal rename to ballerina/utils.bal diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..28ec345 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,34 @@ +# Examples + +This directory contains a collection of sample code examples written in Ballerina. These examples demonstrate various +use cases of the module. You can follow the instructions below to build and run these examples. + +## Running an Example + +Execute the following commands to build an example from the source. + +* To build an example + + `bal build ` + + +* To run an example + + `bal run ` + +## Building the Examples with the Local Module + +**Warning**: Because of the absence of support for reading local repositories for single Ballerina files, the bala of +the module is manually written to the central repository as a workaround. Consequently, the bash script may modify your +local Ballerina repositories. + +Execute the following commands to build all the examples against the changes you have made to the module locally. + +* To build all the examples + + `./build.sh build` + + +* To run all the examples + + `./build.sh run` \ No newline at end of file diff --git a/samples/add_chart.bal b/examples/add_chart.bal similarity index 100% rename from samples/add_chart.bal rename to examples/add_chart.bal diff --git a/samples/add_table.bal b/examples/add_table.bal similarity index 100% rename from samples/add_table.bal rename to examples/add_table.bal diff --git a/samples/add_worksheet.bal b/examples/add_worksheet.bal similarity index 100% rename from samples/add_worksheet.bal rename to examples/add_worksheet.bal diff --git a/examples/build.sh b/examples/build.sh new file mode 100755 index 0000000..5d32ff0 --- /dev/null +++ b/examples/build.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +BAL_EXAMPLES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +BAL_CENTRAL_DIR="$HOME/.ballerina/repositories/central.ballerina.io/" +BAL_HOME_DIR="$BAL_EXAMPLES_DIR/../ballerina" + +set -e + +case "$1" in +build) + BAL_CMD="build" + ;; +run) + BAL_CMD="run" + ;; +*) + echo "Invalid command provided: '$1'. Please provide 'build' or 'test' as the command." + exit 1 + ;; +esac + +# Read Ballerina package name +BAL_PACKAGE_NAME=$(awk -F'"' '/^name/ {print $2}' "$BAL_HOME_DIR/Ballerina.toml") + +# Push the package to the local repository +cd "$BAL_HOME_DIR" && + bal pack && + bal push --repository=local + +# Remove the cache directories in the repositories +cacheDirs=($(ls -d "$BAL_CENTRAL_DIR"/cache-* 2>/dev/null)) +for dir in "${cacheDirs[@]}"; do + [ -d "$dir" ] && rm -r "$dir" +done +echo "Successfully cleaned the cache directories" + +# Update the central repository +BAL_DESTINATION_DIR="$HOME/.ballerina/repositories/central.ballerina.io/bala/ballerinax/$BAL_PACKAGE_NAME" +BAL_SOURCE_DIR="$HOME/.ballerina/repositories/local/bala/ballerinax/$BAL_PACKAGE_NAME" +[ -d "$BAL_DESTINATION_DIR" ] && rm -r "$BAL_DESTINATION_DIR" +[ -d "$BAL_SOURCE_DIR" ] && cp -r "$BAL_SOURCE_DIR" "$BAL_DESTINATION_DIR" +echo "Successfully updated the local central repositories" + +# Loop through examples in the examples directory +find "$BAL_EXAMPLES_DIR" -type f -name "*.bal" | while read -r BAL_EXAMPLE_FILE; do + bal "$BAL_CMD" --offline "$BAL_EXAMPLE_FILE" +done diff --git a/samples/calculate_workbook_application.bal b/examples/calculate_workbook_application.bal similarity index 100% rename from samples/calculate_workbook_application.bal rename to examples/calculate_workbook_application.bal diff --git a/samples/create_column.bal b/examples/create_column.bal similarity index 96% rename from samples/create_column.bal rename to examples/create_column.bal index 6b184a9..26dfa41 100644 --- a/samples/create_column.bal +++ b/examples/create_column.bal @@ -37,8 +37,8 @@ excel:Client excelClient = check new (configuration); public function main() { json[][] values = [["a3"], ["c3"], ["aa"]]; int columnIndex = 1; - - excel:Column|error response = excelClient->createColumn(workbookIdOrPath, "sheetName", "tableName", values, + + excel:Column|error response = excelClient->createColumn(workbookIdOrPath, "sheetName", "tableName", values, columnIndex); if (response is excel:Column) { log:printInfo(response.toString()); diff --git a/samples/create_row.bal b/examples/create_row.bal similarity index 100% rename from samples/create_row.bal rename to examples/create_row.bal diff --git a/samples/delete_chart.bal b/examples/delete_chart.bal similarity index 100% rename from samples/delete_chart.bal rename to examples/delete_chart.bal diff --git a/samples/delete_column.bal b/examples/delete_column.bal similarity index 100% rename from samples/delete_column.bal rename to examples/delete_column.bal diff --git a/samples/delete_row.bal b/examples/delete_row.bal similarity index 100% rename from samples/delete_row.bal rename to examples/delete_row.bal diff --git a/samples/delete_table.bal b/examples/delete_table.bal similarity index 100% rename from samples/delete_table.bal rename to examples/delete_table.bal diff --git a/samples/delete_worksheet.bal b/examples/delete_worksheet.bal similarity index 100% rename from samples/delete_worksheet.bal rename to examples/delete_worksheet.bal diff --git a/samples/get_cell.bal b/examples/get_cell.bal similarity index 100% rename from samples/get_cell.bal rename to examples/get_cell.bal diff --git a/samples/get_chart.bal b/examples/get_chart.bal similarity index 100% rename from samples/get_chart.bal rename to examples/get_chart.bal diff --git a/samples/get_chart_image .bal b/examples/get_chart_image .bal similarity index 100% rename from samples/get_chart_image .bal rename to examples/get_chart_image .bal diff --git a/samples/get_table.bal b/examples/get_table.bal similarity index 100% rename from samples/get_table.bal rename to examples/get_table.bal diff --git a/samples/get_workbook_application.bal b/examples/get_workbook_application.bal similarity index 100% rename from samples/get_workbook_application.bal rename to examples/get_workbook_application.bal diff --git a/samples/get_worksheet.bal b/examples/get_worksheet.bal similarity index 100% rename from samples/get_worksheet.bal rename to examples/get_worksheet.bal diff --git a/samples/list_charts.bal b/examples/list_charts.bal similarity index 100% rename from samples/list_charts.bal rename to examples/list_charts.bal diff --git a/samples/list_columns.bal b/examples/list_columns.bal similarity index 100% rename from samples/list_columns.bal rename to examples/list_columns.bal diff --git a/samples/list_rows.bal b/examples/list_rows.bal similarity index 100% rename from samples/list_rows.bal rename to examples/list_rows.bal diff --git a/samples/list_tables.bal b/examples/list_tables.bal similarity index 100% rename from samples/list_tables.bal rename to examples/list_tables.bal diff --git a/samples/list_worksheets.bal b/examples/list_worksheets.bal similarity index 100% rename from samples/list_worksheets.bal rename to examples/list_worksheets.bal diff --git a/samples/reset_chart_image.bal b/examples/reset_chart_image.bal similarity index 100% rename from samples/reset_chart_image.bal rename to examples/reset_chart_image.bal diff --git a/samples/set_chart_position.bal b/examples/set_chart_position.bal similarity index 100% rename from samples/set_chart_position.bal rename to examples/set_chart_position.bal diff --git a/samples/update_chart.bal b/examples/update_chart.bal similarity index 96% rename from samples/update_chart.bal rename to examples/update_chart.bal index edc896e..fe4e450 100644 --- a/samples/update_chart.bal +++ b/examples/update_chart.bal @@ -40,7 +40,7 @@ public function main() { left: 99 }; - excel:Worksheet|error response = excelClient->updateChart(workbookIdOrPath, "worksheetName", "chartName", + excel:Worksheet|error response = excelClient->updateChart(workbookIdOrPath, "worksheetName", "chartName", updateChart); if (response is excel:Worksheet) { log:printInfo(response.toString()); diff --git a/samples/update_column.bal b/examples/update_column.bal similarity index 96% rename from samples/update_column.bal rename to examples/update_column.bal index d6bf36c..026bca1 100644 --- a/samples/update_column.bal +++ b/examples/update_column.bal @@ -35,7 +35,7 @@ excel:ConnectionConfig configuration = { excel:Client excelClient = check new (configuration); public function main() { - excel:Column|error response = excelClient->updateColumn(workbookIdOrPath, "sheetName", "tableName", 1, + excel:Column|error response = excelClient->updateColumn(workbookIdOrPath, "sheetName", "tableName", 1, name = "columnName"); if (response is excel:Column) { log:printInfo(response.toString()); diff --git a/samples/update_row.bal b/examples/update_row.bal similarity index 100% rename from samples/update_row.bal rename to examples/update_row.bal diff --git a/samples/update_table.bal b/examples/update_table.bal similarity index 100% rename from samples/update_table.bal rename to examples/update_table.bal diff --git a/samples/update_worksheet.bal b/examples/update_worksheet.bal similarity index 100% rename from samples/update_worksheet.bal rename to examples/update_worksheet.bal