Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
SasinduDilshara committed Nov 14, 2022
2 parents 203d6ab + 32c1243 commit b019785
Show file tree
Hide file tree
Showing 142 changed files with 4,860 additions and 580 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/daily_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,20 @@ jobs:
key: ${{ runner.os }}-gradle-${{ github.sha }}
restore-keys: ${{ runner.os }}-gradle

- name: Setup GraalVM
uses: graalvm/setup-graalvm@v1
with:
version: '22.2.0'
java-version: '11'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}
set-java-home: 'false'

- name: Build with Gradle
run: |
export DISPLAY=':99.0'
/usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
./gradlew build --max-workers=2 --scan --no-daemon
./gradlew build -Pnative.test --max-workers=2 --scan --no-daemon
find ~/.gradle/caches/ -name "*.lock" -type f -delete
- name: Notify failure
Expand Down
52 changes: 35 additions & 17 deletions .github/workflows/pull_request_full_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,29 @@ jobs:
build-lang:
name: Build Ballerina Lang
runs-on: ubuntu-latest
concurrency:
group: ${{ github.head_ref }}-full-build-pipeline
timeout-minutes: 120
concurrency:
group: ${{ github.head_ref }}-FBP-lang
cancel-in-progress: true

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Clone Ballerina Lang Repository
run: git clone https://github.com/${{ github.repository_owner }}/ballerina-lang.git

- name: Checkout To Lang Branch
run: |
cd ballerina-lang
git checkout ${{ github.event.inputs.ballerina_lang_branch }}
- name: Get Lang Version
id: lang-version
run: |
VERSION=$((grep -w "version" | cut -d= -f2) < ballerina-lang/gradle.properties)
VERSION=$((grep -w "version" | cut -d= -f2) < gradle.properties)
echo "::set-output name=version::$VERSION"
- name: Build ballerina-lang
run: |
cd ballerina-lang
./gradlew clean build -x check publishToMavenLocal --stacktrace --scan
- name: Archive Lang Artifacts
uses: actions/upload-artifact@v2
with:
Expand All @@ -46,15 +45,16 @@ jobs:
needs: build-lang
name: Build Stdlib Level
runs-on: ubuntu-latest
timeout-minutes: 120
concurrency:
group: ${{ github.head_ref }}-FBP-stdlib-${{ matrix.level }}
cancel-in-progress: true
strategy:
fail-fast: false
matrix:
level: [1, 2, 3, 4, 5, 6, 7, 8]
level: [ 1, 2, 3, 4, 5, 6, 7, 8 ]

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Download Ballerina Lang Artifacts
uses: actions/download-artifact@v2
with:
Expand All @@ -65,16 +65,29 @@ jobs:
run: |
wget https://github.com/raw/ballerina-platform/ballerina-release/master/dependabot/resources/extensions.json
wget https://github.com/raw/ballerina-platform/ballerina-distribution/2201.0.x/gradle.properties
- name: Clone Modules
run: |
for module_name in $(jq -r '.standard_library| .[] | select(.level==${{ matrix.level }}) | .name' extensions.json); \
do git clone https://github.com/ballerina-platform/${module_name}.git; \
done
- name: Checkout non-default branch
run: |
for module_name in $(jq -r '.standard_library| .[] | select(.level==${{ matrix.level }}) | .name' extensions.json); \
do
cd $module_name
git fetch origin
git checkout -t origin/update4 || :
cd ..
done
- name: Update Lang Version in Module
run: |
for module_name in $(jq -r '.standard_library| .[] | select(.level==${{ matrix.level }}) | .name' extensions.json); do \
perl -pi -e "s/^\s*ballerinaLangVersion=.*/ballerinaLangVersion=${{ needs.build-lang.outputs.lang_version }}/" ${module_name}/gradle.properties; \
done
- name: Build Module
run: |
for module_name in $(jq -r '.standard_library| .[] | select(.level==${{ matrix.level }}) | .name' extensions.json); do \
Expand All @@ -89,24 +102,29 @@ jobs:
needs: build-lang
name: Build Ballerina Distribution
runs-on: ubuntu-latest
timeout-minutes: 120
concurrency:
group: ${{ github.head_ref }}-FBP-distribution
cancel-in-progress: true

steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
repository: 'ballerina-platform/ballerina-distribution'

- name: Download Ballerina Lang Artifacts
uses: actions/download-artifact@v2
with:
name: Ballerina Lang Artifacts
path: ~/.m2/
- name: Clone Distribution
run: git clone https://github.com/ballerina-platform/ballerina-distribution.git

- name: Update Lang Version in Module
working-directory: ./ballerina-distribution
run: |
perl -pi -e "s/^\s*ballerinaLangVersion=.*/ballerinaLangVersion=${{ needs.build-lang.outputs.lang_version }}/" gradle.properties
- name: Build Module
working-directory: ./ballerina-distribution
run: ./gradlew clean build --stacktrace --scan --console=plain --no-daemon --continue
run: ./gradlew clean build --stacktrace --scan --console=plain --no-daemon --continue -x :project-api-tests:test
env:
packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }}
packagePAT: ${{ secrets.GITHUB_TOKEN }}
Expand Down
31 changes: 20 additions & 11 deletions .github/workflows/pull_request_ubuntu_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
name: Build with all tests on Ubuntu
runs-on: ubuntu-latest
timeout-minutes: 120
concurrency:
concurrency:
group: ${{ github.head_ref }}-ubuntu
cancel-in-progress: true

Expand All @@ -43,19 +43,28 @@ jobs:
key: ${{ runner.os }}-gradle-${{ github.sha }}
restore-keys: ${{ runner.os }}-gradle

- name: Setup GraalVM
uses: graalvm/setup-graalvm@v1
with:
version: '22.2.0'
java-version: '11'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}
set-java-home: 'false'

- name: Build with Gradle
run: |
export DISPLAY=':99.0'
/usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
./gradlew build --max-workers=2 --scan --no-daemon
./gradlew build -Pnative.test --max-workers=2 --scan --no-daemon
find ~/.gradle/caches/ -name "*.lock" -type f -delete
- name: Generate Jacoco report
if: github.event_name == 'pull_request'
if: github.event_name == 'pull_request'
run: ./gradlew createCodeCoverageReport

- name: Generate Codecov Report
if: github.event_name == 'pull_request'
if: github.event_name == 'pull_request'
uses: codecov/codecov-action@v1
with:
files: ./.jacoco/reports/jacoco/report.xml
Expand All @@ -64,7 +73,7 @@ jobs:
name: Build with sonarcloud scan on Ubuntu
runs-on: ubuntu-latest
timeout-minutes: 120
concurrency:
concurrency:
group: ${{ github.head_ref }}-sonarcloud
cancel-in-progress: true

Expand All @@ -77,7 +86,7 @@ jobs:
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
distribution: 'temurin'
distribution: 'temurin'
java-version: '11'

- name: Initialize sub-modules
Expand Down Expand Up @@ -114,20 +123,20 @@ jobs:
mkdir -p /home/runner/work/ballerina-lang/ballerina-lang/misc/ballerina-config-schema-builder
mkdir -p /home/runner/work/ballerina-lang/ballerina-lang/ballerina-stringutils
mkdir -p /home/runner/work/ballerina-lang/ballerina-lang/semver-checker
- name: Build with Gradle
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: "${{ env.SONAR_TOKEN != '' }}"
run: |
export DISPLAY=':99.0'
/usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
./gradlew build sonarqube --info -x test -x check --max-workers=2 --scan --no-daemon
find ~/.gradle/caches/ -name "*.lock" -type f -delete
- name: Print log message
env:
- name: Print log message
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: "${{ env.SONAR_TOKEN == '' }}"
run: echo "Sonarcloud scan is skipped"
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,23 @@ public static String decodeIdentifier(String encodedIdentifier) {
return Utils.decodeIdentifier(encodedIdentifier);
}

/**
* Escape the special characters in an identifier with a preceding `\`.
*
* @param identifier identifier string
* @return a string of characters with special characters converted to their escaped form
*/
public static String escapeSpecialCharacters(String identifier) {
return Utils.escapeSpecialCharacters(identifier);
}

/**
* Unescapes a ballerina string.
*
* @param text ballerina string to unescape
* @return a string of characters with any escaped characters converted to their unescaped form
*/
public static String unescapeBallerina(String text) {
return Utils.unescapeBallerina(text);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public static void startListenersAndSignalHandler(boolean isService) {
startListeners(isService);

// start TRAP signal handler which produces the strand dump
startTrapSignalHandler();
}

public static void startTrapSignalHandler() {
try {
Signal.handle(new Signal("TRAP"), signal -> outStream.println(StrandDump.getStrandDump()));
} catch (IllegalArgumentException ignored) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import io.ballerina.runtime.internal.util.exceptions.RuntimeErrors;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.Map;
Expand All @@ -54,6 +53,8 @@ public class DecimalValue implements SimpleValue, BDecimal {
new BigDecimal("9.999999999999999999999999999999999e6144", MathContext.DECIMAL128);
private static final BigDecimal DECIMAL_MIN =
new BigDecimal("-9.999999999999999999999999999999999e6144", MathContext.DECIMAL128);
private static final BigDecimal MIN_DECIMAL_MAGNITUDE =
new BigDecimal("1.000000000000000000000000000000000e-6143", MathContext.DECIMAL128);

// Variable used to track the kind of a decimal value.
@Deprecated
Expand All @@ -71,20 +72,16 @@ public DecimalValue(BigDecimal value) {
public DecimalValue(String value) {
// Check whether the number provided is a hexadecimal value.
BigDecimal bd;
if (isHexValueString(value)) {
bd = hexToDecimalFloatingPointNumber(value);
} else {
try {
bd = new BigDecimal(value, MathContext.DECIMAL128);
} catch (NumberFormatException exception) {
String message = exception.getMessage();
if ((message != null) && (message.equals("Too many nonzero exponent digits.") ||
message.equals("Exponent overflow."))) {
throw ErrorCreator.createError(BallerinaErrorReasons.LARGE_EXPONENT_ERROR,
BLangExceptionHelper.getErrorDetails(RuntimeErrors.LARGE_EXPONENTS_IN_DECIMAL, value));
}
throw exception;
try {
bd = new BigDecimal(value, MathContext.DECIMAL128);
} catch (NumberFormatException exception) {
String message = exception.getMessage();
if ((message != null) && (message.equals("Too many nonzero exponent digits.") ||
message.equals("Exponent overflow."))) {
throw ErrorCreator.createError(BallerinaErrorReasons.LARGE_EXPONENT_ERROR,
BLangExceptionHelper.getErrorDetails(RuntimeErrors.LARGE_EXPONENTS_IN_DECIMAL, value));
}
throw exception;
}
this.value = getValidDecimalValue(bd);

Expand All @@ -102,67 +99,13 @@ private static BigDecimal getValidDecimalValue(BigDecimal bd) {
if (bd.compareTo(DECIMAL_MAX) > 0 || bd.compareTo(DECIMAL_MIN) < 0) {
throw ErrorCreator.createError(BallerinaErrorReasons.NUMBER_OVERFLOW,
BLangExceptionHelper.getErrorDetails(RuntimeErrors.DECIMAL_VALUE_OUT_OF_RANGE));
} else if (bd.abs(MathContext.DECIMAL128).compareTo(MIN_DECIMAL_MAGNITUDE) < 0 &&
bd.abs(MathContext.DECIMAL128).compareTo(BigDecimal.ZERO) > 0) {
return BigDecimal.ZERO;
}
return bd;
}

private static boolean isHexValueString(String value) {
String upperCaseValue = value.toUpperCase();
return upperCaseValue.startsWith("0X") || upperCaseValue.startsWith("-0X");
}

/**
* Method used to convert the hexadecimal number to decimal floating point number.
* BigDecimal does not support hexadecimal numbers. Hence, we need to convert the hexadecimal number to a
* decimal floating point number before passing the string value to the BigDecimal constructor.
*
* @param value Hexadecimal string value that needs to be converted.
* @return BigDecimal corresponds to the hexadecimal number provided.
*/
private static BigDecimal hexToDecimalFloatingPointNumber(String value) {
String upperCaseValue = value.toUpperCase();
// Remove the hexadecimal indicator prefix.
String hexValue = upperCaseValue.replace("0X", "");
if (!hexValue.contains("P")) {
hexValue = hexValue.concat("P0");
}
// Isolate the binary exponent and the number.
String[] splitAtExponent = hexValue.split("P");
int binaryExponent = Integer.parseInt(splitAtExponent[1]);
String numberWithoutExp = splitAtExponent[0];
String intComponent;

// Check whether the hex number has a decimal part.
// If there is a decimal part, turn the hex floating point number to a whole number by multiplying it by a
// power of 16.
// i.e: 23FA2.123 = 23FA2123 * 16^(-3)
if (numberWithoutExp.contains(".")) {
String[] numberComponents = numberWithoutExp.split("\\.");
intComponent = numberComponents[0];
String decimalComponent = numberComponents[1];
// Change the base of the hex power to 2 and calculate the binary exponent.
// i.e: 23FA2123 * 16^(-3) = 23FA2123 * (2^4)^(-3) = 23FA2123 * 2^(-12)
binaryExponent += 4 * (-1) * decimalComponent.length();
intComponent = intComponent.concat(decimalComponent);
} else {
intComponent = numberWithoutExp;
}

BigDecimal exponentValue;
// Find the value corresponding to the binary exponent.
if (binaryExponent >= 0) {
exponentValue = new BigDecimal(2).pow(binaryExponent);
} else {
//If negative exponent e, then the corresponding value equals to (1 / 2^(-e)).
exponentValue = BigDecimal.ONE.divide(new BigDecimal(2).pow(-binaryExponent), MathContext.DECIMAL128);
}
// Convert the hexadecimal whole number(without exponent) to decimal big integer.
BigInteger hexEquivalentNumber = new BigInteger(intComponent, 16);

// Calculate and return the final decimal floating point number equivalent to the hex number provided.
return new BigDecimal(hexEquivalentNumber).multiply(exponentValue, MathContext.DECIMAL128);
}

/**
* Get value of the decimal.
* @return the value
Expand Down
4 changes: 4 additions & 0 deletions cli/ballerina-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ test {
dependsOn createTestBre

systemProperty "ballerina.home", "$buildDir"

useTestNG() {
suites 'src/test/resources/testng.xml'
if (!project.hasProperty("native.test")) {
excludeGroups 'native'
}
}
}

Expand Down
Loading

0 comments on commit b019785

Please sign in to comment.