Skip to content

Commit

Permalink
Merge branch 'master' into use-pattern-matching-variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadow-Devil authored Sep 6, 2024
2 parents 9a8d120 + a6a3526 commit 4d2abe5
Show file tree
Hide file tree
Showing 201 changed files with 3,493 additions and 796 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pull_request_full_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
with:
name: Ballerina Lang Artifacts
path: ~/.m2/
include-hidden-files: true

outputs:
lang_version: ${{ steps.lang-version.outputs.version }}
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/pull_request_windows_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,18 @@ jobs:
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle

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

- name: Build with Gradle
env:
packageUser: ${{ github.actor }}
packagePAT: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew.bat build --continue -x :ballerina-lang:test -x :jballerina-integration-test:test -x :ballerina-shell:shell-cli:test -x :ballerina-cli:test -x javadoc --stacktrace -scan --console=plain --no-daemon --no-parallel
run: ./gradlew.bat build --continue -x :ballerina-lang:test -x :jballerina-integration-test:test -x javadoc --stacktrace -scan --console=plain --no-daemon --no-parallel

13 changes: 11 additions & 2 deletions .github/workflows/push_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
windows_build:
name: Build with some tests on Windows
runs-on: windows-latest
timeout-minutes: 120
timeout-minutes: 150
concurrency:
group: ${{ github.head_ref }}-windows
cancel-in-progress: true
Expand Down Expand Up @@ -86,8 +86,17 @@ jobs:
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle

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

- name: Build with Gradle
run: ./gradlew.bat build --continue -x :ballerina-lang:test -x :jballerina-integration-test:test -x :ballerina-shell:shell-cli:test -x :jballerina-debugger-integration-test:test -x javadoc --stacktrace -scan --console=plain --no-daemon --no-parallel
run: ./gradlew.bat build --continue -x :ballerina-lang:test -x :jballerina-integration-test:test -x :jballerina-debugger-integration-test:test -x javadoc --stacktrace -scan --console=plain --no-daemon --no-parallel


sonarcloud_scan:
Expand Down
8 changes: 4 additions & 4 deletions ballerina-shell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ The Ballerina-shell tool is an interactive tool for learning the Ballerina progr
The project is implemented in three base modules.

- **shell-rt** - Module including runtime dependencies for ballerina programs generated. You may find the source code for this
module [here](shell-rt).
module [here](modules/shell-rt).
- **shell-core** - Module including all the base evaluation classes. This has all the base components to evaluate and run a
string. All other components are built on top of this module. You may find the source code for this
module [here](shell-core).
module [here](modules/shell-core).
- **shell-cli** - A command-line interface built on top of shell. Includes multi-line inputs, color-coded outputs,
keyword-based auto-completion, etc... You may find the source code for this module [here](shell-cli).
keyword-based auto-completion, etc... You may find the source code for this module [here](modules/shell-cli).

## Known Issues

Expand Down Expand Up @@ -103,7 +103,7 @@ The project is implemented in three base modules.

## Implementation

For implementation details please refer [this](shell-core/README.md).
For implementation details please refer [this](modules/shell-core/README.md).

## Building

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -62,8 +61,8 @@ public TestIntegrator(InputStream inputStream, OutputStream outputStream, ByteAr
@Override
public void run() {
try {
PrintStream testPrint = new PrintStream(outputStream, true, Charset.defaultCharset());
InputStreamReader inStreamReader = new InputStreamReader(inputStream, Charset.defaultCharset());
PrintStream testPrint = new PrintStream(outputStream, true, StandardCharsets.UTF_8);
InputStreamReader inStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
BufferedReader testReader = new BufferedReader(inStreamReader);

// The response here is not testable because it can change.
Expand Down Expand Up @@ -117,9 +116,8 @@ private String readResponse(BufferedReader stream) throws IOException {
* Send the data given to the specific stream.
*/
private void sendRequest(PrintStream stream, String string) throws InterruptedException {
stream.append(string);
stream.println(System.lineSeparator());
stream.flush();
// This is a workaround since with double `System.lineSeparator()` the tests fail on windows.
stream.append(string).append("\n\n").flush();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;

/**
Expand All @@ -54,7 +54,7 @@ protected void test(String fileName) throws Exception {
PrintStream origOut = System.out;
try {
ByteArrayOutputStream stdOut = new ByteArrayOutputStream();
PrintStream interceptedOutStream = new PrintStream(stdOut, true, Charset.defaultCharset());
PrintStream interceptedOutStream = new PrintStream(stdOut, true, StandardCharsets.UTF_8);
System.setOut(interceptedOutStream);

TestIntegrator testIntegrator = new TestIntegrator(testIn, testOut, stdOut, testCases);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.ballerina.compiler.syntax.tree.ExpressionNode;
import io.ballerina.compiler.syntax.tree.Node;
import io.ballerina.compiler.syntax.tree.NodeParser;
import io.ballerina.shell.parser.ParserConstants;
import io.ballerina.shell.parser.TrialTreeParser;

import java.util.ArrayList;
Expand Down Expand Up @@ -57,7 +58,16 @@ public Collection<Node> parse(String source) throws ParserTrialFailedException {
if (expressionNode.hasDiagnostics()) {
throw new ParserTrialFailedException("Error occurred during extracting expression from the statement");
}
validateExpression(expressionNode.toSourceCode());
nodes.add(expressionNode);
return nodes;
}

private void validateExpression(String expression) {
String functionName = expression.replaceAll("\\s*\\(.*", "");
if (ParserConstants.isFunctionNameRestricted(functionName)) {
String message = String.format("Function name '%s' not allowed in Ballerina Shell.%n", functionName);
throw new InvalidMethodException(message);
}
}
}
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ plugins {
apply from: "$rootDir/gradle/repositories.gradle"

allprojects {
tasks.withType(JavaCompile).configureEach {
options.fork = true
}

group = project.group
version = project.version

Expand Down Expand Up @@ -144,4 +148,3 @@ sonarqube {
}

copyBallerinaClassFiles.dependsOn copyExecFilesAndJavaClassFiles
createCodeCoverageReport.dependsOn copyBallerinaClassFiles
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ public interface Repository {
* Get whether remote management is enabled.
* @return True if remote management is enabled, false otherwise.
*/
boolean isRemoteEnabled();
boolean isRemoteManagementEnabled();
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ public static Object parseMapExpressionStringValue(String exprValue, BLink paren
}
CycleUtils.Node node = new CycleUtils.Node(eleMap, parent);
Set<Type> typeSet = new HashSet<>();
for (int i = 0; i < list.size(); i++) {
String e = list.get(i);
for (String e : list) {
int colonIndex = e.indexOf(':');
int quotesCount = 0;
for (int j = 0; j < e.length(); j++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class RepositoryImpl implements Repository {
private static final String nodeId = generateNodeId();
private static String balHome;
private static String balVersion;
private static boolean isRemoteEnabled = false;
private static boolean isRemoteManagementEnabled = false;

@Override
public List<Artifact> getArtifacts() {
Expand Down Expand Up @@ -73,8 +73,8 @@ public Node getNode() {
}

@Override
public boolean isRemoteEnabled() {
return isRemoteEnabled;
public boolean isRemoteManagementEnabled() {
return isRemoteManagementEnabled;
}

private Artifact createArtifact(ObjectValue service, ObjectValue listener) {
Expand All @@ -92,7 +92,7 @@ private Artifact createArtifact(ObjectValue service, ObjectValue listener) {
}

public static void addServiceListener(BObject listener, BObject service, Object attachPoint) {
if (!isRemoteEnabled) {
if (!isRemoteManagementEnabled) {
return;
}
BServiceType serviceType = (BServiceType) service.getType();
Expand All @@ -101,10 +101,11 @@ public static void addServiceListener(BObject listener, BObject service, Object
listenerServiceMap.put((ObjectValue) listener, (ObjectValue) service);
}

public static void addBallerinaRuntimeInformation(String balHome, String balVersion, boolean isRemoteEnabled) {
public static void addBallerinaRuntimeInformation(String balHome, String balVersion,
boolean isRemoteManagementEnabled) {
RepositoryImpl.balHome = balHome;
RepositoryImpl.balVersion = balVersion;
RepositoryImpl.isRemoteEnabled = isRemoteEnabled;
RepositoryImpl.isRemoteManagementEnabled = isRemoteManagementEnabled;
}

private static String generateNodeId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,31 +188,31 @@ public class XmlValidator {
}

// remove special characters
for (int i = 0; i < specialChar.length; i++) {
CHARS[specialChar[i]] = (byte) (CHARS[specialChar[i]] & ~MASK_CONTENT);
for (int k : specialChar) {
CHARS[k] = (byte) (CHARS[k] & ~MASK_CONTENT);
}

// set space characters
for (int i = 0; i < spaceChar.length; i++) {
CHARS[spaceChar[i]] |= MASK_SPACE;
for (int k : spaceChar) {
CHARS[k] |= MASK_SPACE;
}

// set name start characters
for (int i = 0; i < nameStartChar.length; i++) {
CHARS[nameStartChar[i]] |= MASK_NAME_START | MASK_NAME | MASK_NCNAME_START | MASK_NCNAME;
for (int k : nameStartChar) {
CHARS[k] |= MASK_NAME_START | MASK_NAME | MASK_NCNAME_START | MASK_NCNAME;
}
for (int i = 0; i < letterRange.length; i += 2) {
for (int j = letterRange[i]; j <= letterRange[i + 1]; j++) {
CHARS[j] |= MASK_NAME_START | MASK_NAME | MASK_NCNAME_START | MASK_NCNAME;
}
}
for (int i = 0; i < letterChar.length; i++) {
CHARS[letterChar[i]] |= MASK_NAME_START | MASK_NAME | MASK_NCNAME_START | MASK_NCNAME;
for (int k : letterChar) {
CHARS[k] |= MASK_NAME_START | MASK_NAME | MASK_NCNAME_START | MASK_NCNAME;
}

// set name characters
for (int i = 0; i < nameChar.length; i++) {
CHARS[nameChar[i]] |= MASK_NAME | MASK_NCNAME;
for (int k : nameChar) {
CHARS[k] |= MASK_NAME | MASK_NCNAME;
}
for (int i = 0; i < digitRange.length; i += 2) {
for (int j = digitRange[i]; j <= digitRange[i + 1]; j++) {
Expand All @@ -224,24 +224,24 @@ public class XmlValidator {
CHARS[j] |= MASK_NAME | MASK_NCNAME;
}
}
for (int i = 0; i < combiningCharChar.length; i++) {
CHARS[combiningCharChar[i]] |= MASK_NAME | MASK_NCNAME;
for (int k : combiningCharChar) {
CHARS[k] |= MASK_NAME | MASK_NCNAME;
}
for (int i = 0; i < extenderRange.length; i += 2) {
for (int j = extenderRange[i]; j <= extenderRange[i + 1]; j++) {
CHARS[j] |= MASK_NAME | MASK_NCNAME;
}
}
for (int i = 0; i < extenderChar.length; i++) {
CHARS[extenderChar[i]] |= MASK_NAME | MASK_NCNAME;
for (int k : extenderChar) {
CHARS[k] |= MASK_NAME | MASK_NCNAME;
}

// remove ':' from allowable MASK_NCNAME_START and MASK_NCNAME chars
CHARS[':'] &= ~(MASK_NCNAME_START | MASK_NCNAME);

// set Pubid characters
for (int i = 0; i < pubidChar.length; i++) {
CHARS[pubidChar[i]] |= MASK_PUBID;
for (int k : pubidChar) {
CHARS[k] |= MASK_PUBID;
}
for (int i = 0; i < pubidRange.length; i += 2) {
for (int j = pubidRange[i]; j <= pubidRange[i + 1]; j++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,10 @@ private TransactionLocalContext createTrxContextBranch(TransactionLocalContext c
}

public void handleChannelError(ChannelDetails[] channels, ErrorValue error) {
for (int i = 0; i < channels.length; i++) {
ChannelDetails channelDetails = channels[i];
for (ChannelDetails channelDetails : channels) {
WorkerDataChannel channel = getWorkerDataChannel(channelDetails);

if (channels[i].send) {
if (channelDetails.send) {
channel.setSendError(error);
} else {
channel.setReceiveError(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import io.ballerina.runtime.api.Module;
import io.ballerina.runtime.api.types.MethodType;
import io.ballerina.runtime.api.types.Parameter;
import io.ballerina.runtime.api.types.ResourceMethodType;
import io.ballerina.runtime.api.types.Type;

Expand Down Expand Up @@ -53,9 +54,9 @@ public String toString() {
}
StringJoiner sj = new StringJoiner(",", "resource function " + accessor + " " + rp.toString() +
"(", ") returns (" + type.retType + ")");
for (int i = 0; i < parameters.length; i++) {
Type type = parameters[i].type;
sj.add(type.getName() + " " + parameters[i].name);
for (Parameter parameter : parameters) {
Type type = parameter.type;
sj.add(type.getName() + " " + parameter.name);
}
return sj.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ private String createExpressionStringValueDataEntry(Iterator<Map.Entry<Long, Lis
StringJoiner sj = new StringJoiner(",");
StringJoiner keyJoiner = new StringJoiner(",");
String[] keysList = tableType.getFieldNames();
for (int i = 0; i < keysList.length; i++) {
keyJoiner.add(keysList[i]);
for (String string : keysList) {
keyJoiner.add(string);
}
while (itr.hasNext()) {
Map.Entry<Long, List<V>> struct = itr.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,8 @@ private void initializeIteratorNextReturnType() {
childrenType = children.get(0).getType();
} else {
Set<Type> types = new HashSet<>();
for (int i = 0; i < children.size(); i++) {
types.add(children.get(i).getType());
for (BXml child : children) {
types.add(child.getType());
}
childrenType = new BUnionType(new ArrayList<>(types));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ public class TransactionConstants {

public static final String ANN_NAME_TRX_PARTICIPANT_CONFIG = "Participant";
public static final String TIMESTAMP_OBJECT_VALUE_FIELD = "timeValue";
public static final int DEFAULT_TRX_AUTO_COMMIT_TIMEOUT = 120;
public static final int DEFAULT_TRX_CLEANUP_TIMEOUT = 600;
}
Loading

0 comments on commit 4d2abe5

Please sign in to comment.