Skip to content

Commit

Permalink
Merge branch 'master' into byte-array-literal
Browse files Browse the repository at this point in the history
  • Loading branch information
ushirask authored Jul 11, 2023
2 parents 9286366 + d08328e commit b56a6a0
Show file tree
Hide file tree
Showing 835 changed files with 13,734 additions and 6,269 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ the source code.

You can use one of the following options to try out Ballerina.

* [Set up Ballerina](https://ballerina.io/learn/install-ballerina/set-up-ballerina/)
* [Set up Ballerina](https://ballerina.io/learn/get-started/)
* [Ballerina Playground](https://play.ballerina.io/)

You can use following resources to learn Ballerina.
Expand All @@ -52,7 +52,7 @@ For instructions on downloading and installing, see [Ballerina Downloads](https:

### Installation options

For more installation options, see [Installation options](https://ballerina.io/learn/install-ballerina/installation-options/).
For more installation options, see [Installation options](https://ballerina.io/downloads/installation-options/).

### Get the VS Code extension

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ public enum ErrorCodes implements DiagnosticCode {

REGEXP_INVALID_HEX_DIGIT("regexp.invalid.hex.digit", "RUNTIME_0120"),
CONFIG_TOML_INVALID_MODULE_STRUCTURE_WITH_VARIABLE("config.toml.invalid.module.structure.with.variable",
"RUNTIME_0121");
"RUNTIME_0121"),
EMPTY_XML_SEQUENCE_HAS_NO_ATTRIBUTES("empty.xml.sequence.no.attributes", "RUNTIME_0122");

private final String errorMsgKey;
private final String errorCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
package io.ballerina.runtime.internal.scheduling;

/**
* This interface represents the function frame which saves the existing
* This abstract class represents the function frame which saves the existing
* state when a function yields.
*
* @since 2201.2.0
*/
public interface FunctionFrame {
public abstract class FunctionFrame {

String getYieldLocation();
public String yieldLocation;

String getYieldStatus();
public String yieldStatus;

}
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,10 @@ public void removeLocalTransactionContext() {
public void removeCurrentTrxContext() {
if (!this.trxContexts.isEmpty()) {
this.currentTrxContext = this.trxContexts.pop();
globalProps.put(CURRENT_TRANSACTION_CONTEXT_PROPERTY, this.currentTrxContext);
return;
}
globalProps.remove(CURRENT_TRANSACTION_CONTEXT_PROPERTY);
this.currentTrxContext = null;
}

Expand Down Expand Up @@ -479,10 +481,10 @@ private void getInfoFromYieldedState(StringBuilder strandInfo, String closingBra
try {
for (FunctionFrame frame : strandFrames) {
if (noPickedYieldStatus) {
yieldStatus = frame.getYieldStatus();
yieldStatus = frame.yieldStatus;
noPickedYieldStatus = false;
}
String yieldLocation = frame.getYieldLocation();
String yieldLocation = frame.yieldLocation;
frameStackTrace.append(stringPrefix).append(yieldLocation);
frameStackTrace.append("\n");
stringPrefix = "\t\t \t";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,11 @@ public boolean getBoolean(long index) {
*/
@Override
public byte getByte(long index) {
return (Byte) get(index);
Object value = get(index);
if (value instanceof Long) {
return ((Long) value).byteValue();
}
return (Byte) value;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ incorrect.action.invocation = invalid action invocation. connector variable expe
invalid.var.assignment = invalid usage of 'var'
xml.attribute.map.update.not.allowed = xml attributes cannot be updated as a collection. update attributes one at a time
xml.qname.update.not.allowed = cannot assign values to an xml qualified name
empty.xml.sequence.no.attributes = empty xml sequence cannot have attributes
undefined.namespace = undefined namespace ''{0}''
incorrect.function.arguments = incorrect arguments for function pointer - ''{0}''
server.connector.already.exist = server connector config with port - {0} already exist with different parameters
Expand Down
129 changes: 68 additions & 61 deletions cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ToolCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.ballerina.cli.utils.PrintUtils;
import io.ballerina.projects.BalToolsManifest;
import io.ballerina.projects.BalToolsToml;
import io.ballerina.projects.JvmTarget;
import io.ballerina.projects.ProjectException;
import io.ballerina.projects.SemanticVersion;
import io.ballerina.projects.Settings;
Expand All @@ -31,6 +32,8 @@
import org.ballerinalang.central.client.CentralAPIClient;
import org.ballerinalang.central.client.exceptions.CentralClientException;
import org.ballerinalang.central.client.exceptions.PackageAlreadyExistsException;
import org.ballerinalang.central.client.model.Tool;
import org.ballerinalang.central.client.model.ToolSearchResult;
import org.ballerinalang.toml.exceptions.SettingsTomlException;
import org.wso2.ballerinalang.compiler.util.Names;
import org.wso2.ballerinalang.util.RepoUtils;
Expand All @@ -48,6 +51,7 @@
import static io.ballerina.cli.cmd.Constants.DIST_TOOL_TOML_PREFIX;
import static io.ballerina.cli.cmd.Constants.TOML_EXT;
import static io.ballerina.cli.cmd.Constants.TOOL_COMMAND;
import static io.ballerina.cli.utils.PrintUtils.printTools;
import static io.ballerina.projects.util.ProjectConstants.BALA_DIR_NAME;
import static io.ballerina.projects.util.ProjectConstants.BAL_TOOLS_TOML;
import static io.ballerina.projects.util.ProjectConstants.CENTRAL_REPOSITORY_CACHE_NAME;
Expand Down Expand Up @@ -144,8 +148,8 @@ public void execute() {
commandUsageInfo = BLauncherCmd.getCommandUsageInfo(TOOL_COMMAND + HYPHEN + TOOL_LIST_COMMAND);
} else if (argList.get(0).equals(TOOL_REMOVE_COMMAND)) {
commandUsageInfo = BLauncherCmd.getCommandUsageInfo(TOOL_COMMAND + HYPHEN + TOOL_REMOVE_COMMAND);
// } else if (argList.get(0).equals(TOOL_SEARCH_COMMAND)) {
// commandUsageInfo = BLauncherCmd.getCommandUsageInfo(TOOL_COMMAND + HYPHEN + TOOL_SEARCH_COMMAND);
} else if (argList.get(0).equals(TOOL_SEARCH_COMMAND)) {
commandUsageInfo = BLauncherCmd.getCommandUsageInfo(TOOL_COMMAND + HYPHEN + TOOL_SEARCH_COMMAND);
} else {
commandUsageInfo = BLauncherCmd.getCommandUsageInfo(TOOL_COMMAND);
}
Expand All @@ -167,9 +171,9 @@ public void execute() {
case TOOL_LIST_COMMAND:
handleListCommand();
break;
// case TOOL_SEARCH_COMMAND:
// handleSearchCommand();
// break;
case TOOL_SEARCH_COMMAND:
handleSearchCommand();
break;
case TOOL_REMOVE_COMMAND:
handleRemoveCommand();
break;
Expand Down Expand Up @@ -263,22 +267,22 @@ private void handleListCommand() {
PrintUtils.printLocalTools(tools, RepoUtils.getTerminalWidth());
}

// private void handleSearchCommand() {
// if (argList.size() < 2) {
// CommandUtil.printError(this.errStream, "no keyword given.", TOOL_SEARCH_USAGE_TEXT, false);
// CommandUtil.exitError(this.exitWhenFinish);
// return;
// }
// if (argList.size() > 2) {
// CommandUtil.printError(
// this.errStream, "too many arguments.", TOOL_SEARCH_USAGE_TEXT, false);
// CommandUtil.exitError(this.exitWhenFinish);
// return;
// }
//
// String searchArgs = argList.get(1);
// searchToolsInCentral(searchArgs);
// }
private void handleSearchCommand() {
if (argList.size() < 2) {
CommandUtil.printError(this.errStream, "no keyword given.", TOOL_SEARCH_USAGE_TEXT, false);
CommandUtil.exitError(this.exitWhenFinish);
return;
}
if (argList.size() > 2) {
CommandUtil.printError(
this.errStream, "too many arguments.", TOOL_SEARCH_USAGE_TEXT, false);
CommandUtil.exitError(this.exitWhenFinish);
return;
}

String searchArgs = argList.get(1);
searchToolsInCentral(searchArgs);
}

private void handleRemoveCommand() {
if (argList.size() < 2) {
Expand Down Expand Up @@ -517,46 +521,49 @@ private boolean deleteSpecificToolVersionCache(String org, String name, String v
return ProjectUtils.deleteDirectory(toolPath);
}

// /**
// * Search for tools in central.
// *
// * @param keyword search keyword.
// */
// private void searchToolsInCentral(String keyword) {
// try {
// Settings settings;
// try {
// settings = RepoUtils.readSettings();
// // Ignore Settings.toml diagnostics in the search command
// } catch (SettingsTomlException e) {
// // Ignore 'Settings.toml' parsing errors and return empty Settings object
// settings = Settings.from();
// }
// CentralAPIClient client = new CentralAPIClient(RepoUtils.getRemoteRepoURL(),
// initializeProxy(settings.getProxy()),
// getAccessTokenOfCLI(settings));
// ToolSearchResult toolSearchResult = client.searchTool(keyword,
// JvmTarget.JAVA_11.code(),
// RepoUtils.getBallerinaVersion());
//
// List<Tool> tools = toolSearchResult.getTools();
// if (tools != null && tools.size() > 0) {
// printTools(toolSearchResult.getTools(), RepoUtils.getTerminalWidth());
// } else {
// outStream.println("no tools found.");
// }
// } catch (CentralClientException e) {
// String errorMessage = e.getMessage();
// if (null != errorMessage && !"".equals(errorMessage.trim())) {
// // removing the error stack
// if (errorMessage.contains("\n\tat")) {
// errorMessage = errorMessage.substring(0, errorMessage.indexOf("\n\tat"));
// }
// CommandUtil.printError(this.errStream, errorMessage, null, false);
// CommandUtil.exitError(this.exitWhenFinish);
// }
// }
// }
/**
* Search for tools in central.
*
* @param keyword search keyword.
*/
private void searchToolsInCentral(String keyword) {
try {
Settings settings;
try {
settings = RepoUtils.readSettings();
// Ignore Settings.toml diagnostics in the search command
} catch (SettingsTomlException e) {
// Ignore 'Settings.toml' parsing errors and return empty Settings object
settings = Settings.from();
}
CentralAPIClient client = new CentralAPIClient(RepoUtils.getRemoteRepoURL(),
initializeProxy(settings.getProxy()), settings.getProxy().username(),
settings.getProxy().password(), getAccessTokenOfCLI(settings));
ToolSearchResult toolSearchResult = client.searchTool(keyword,
JvmTarget.JAVA_11.code(),
RepoUtils.getBallerinaVersion());

List<Tool> tools = toolSearchResult.getTools();
if (tools != null && tools.size() > 0) {
printTools(toolSearchResult.getTools(), RepoUtils.getTerminalWidth());
} else {
outStream.println("no tools found.");
}
} catch (CentralClientException e) {
String errorMessage = e.getMessage();
if (null != errorMessage && !"".equals(errorMessage.trim())) {
// removing the error stack
if (errorMessage.contains("\n\tat")) {
errorMessage = errorMessage.substring(0, errorMessage.indexOf("\n\tat"));
}
CommandUtil.printError(this.errStream, errorMessage, null, false);
CommandUtil.exitError(this.exitWhenFinish);
} else {
CommandUtil.printError(this.errStream, "error while searching for tools.", null, false);
CommandUtil.exitError(this.exitWhenFinish);
}
}
}

private boolean isToolLocallyAvailable(String toolId, String version) {
if (version.equals(Names.EMPTY.getValue())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public static void printTools(List<Tool> tools, String terminalWidth) {
outStream.println();
}
outStream.println();
outStream.println(tools.size() + " tools found");
outStream.println(tools.size() + " tools found.");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1250,4 +1250,56 @@ private void validateBuildTimeInfo(String buildLog) {
"Missing testingExecutionDuration field in build time logs");
Assert.assertTrue(buildLog.contains("totalDuration"), "Missing totalDuration field in build time logs");
}

@Test(description = "Check GraalVM compatibility of build project")
public void testGraalVMCompatibilityOfJavaImportedProject() throws IOException {
// Project contains only dist provided Java dependencies
Path projectPath = this.testResources.resolve("validJava11Project");
System.setProperty("user.dir", projectPath.toString());
BuildCommand buildCommand = new BuildCommand(projectPath, printStream, printStream, false);
// non existing bal file
new CommandLine(buildCommand).parseArgs("--graalvm");
try {
buildCommand.execute();
} catch (BLauncherException e) {
String buildLog = readOutput(true);
Assert.assertTrue(buildLog.contains("Compiling source") && buildLog.contains("foo/winery:0.1.0") &&
!buildLog.contains("WARNING: Package is not verified with GraalVM"));
}
}

@Test(description = "Check GraalVM compatibility of build project")
public void testGraalVMCompatibilityOfJava11Project() throws IOException {
// Project contains platform Java dependencies
Path projectPath = this.testResources.resolve("validProjectWithPlatformLibs");
System.setProperty("user.dir", projectPath.toString());
BuildCommand buildCommand = new BuildCommand(projectPath, printStream, printStream, false);
// non existing bal file
new CommandLine(buildCommand).parseArgs("--graalvm");
try {
buildCommand.execute();
} catch (BLauncherException e) {
String buildLog = readOutput(true);
Assert.assertTrue(buildLog.contains("Compiling source") &&
buildLog.contains("sameera/myproject:0.1.0") &&
buildLog.contains("WARNING: Package is not verified with GraalVM"));
}
}

@Test(description = "Check GraalVM compatibility of build project")
public void testGraalVMCompatibilityOfAnyProject() throws IOException {
// Project contains platform Java dependencies
Path projectPath = this.testResources.resolve("validApplicationProject");
System.setProperty("user.dir", projectPath.toString());
BuildCommand buildCommand = new BuildCommand(projectPath, printStream, printStream, false);
// non existing bal file
new CommandLine(buildCommand).parseArgs("--graalvm");
try {
buildCommand.execute();
} catch (BLauncherException e) {
String buildLog = readOutput(true);
Assert.assertTrue(buildLog.contains("Compiling source") && buildLog.contains("foo/winery:0.1.0")
&& !buildLog.contains("WARNING: Package is not verified with GraalVM"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,14 @@ public void testPackApplicationPackage() {
}

@Test(description = "Pack a Standalone Ballerina file")
public void testPackStandaloneFile() {
public void testPackStandaloneFile() throws IOException {
Path projectPath = this.testResources.resolve("valid-bal-file").resolve("hello_world.bal");
System.setProperty("user.dir", this.testResources.resolve("valid-bal-file").toString());
PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true);
new CommandLine(packCommand).parseArgs();
try {
packCommand.execute();
} catch (BLauncherException e) {
Assert.assertTrue(e.getDetailedMessages().get(0)
.contains("'-c' or '--compile' can only be used with a Ballerina package."));
}
packCommand.execute();
String buildLog = readOutput(true);
Assert.assertTrue(buildLog.contains(" bal pack can only be used with a Ballerina package."));
}

@Test(description = "Pack a package with platform libs")
Expand Down Expand Up @@ -359,4 +356,16 @@ public void testPackTemplatePackageWithACompilerPackageDependency() throws IOExc
Assert.assertFalse(mainBalContent.contains("public function newFunctionByCodeModifiermain(string params) " +
"returns error? {\n}"));
}

@Test(description = "Pack a library package with platform libraries")
public void testPackProjectWithPlatformLibs() throws IOException {
Path projectPath = this.testResources.resolve("validProjectWithPlatformLibs");
System.setProperty("user.dir", projectPath.toString());

PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true);
new CommandLine(packCommand).parseArgs();
packCommand.execute();
String buildLog = readOutput(true);
Assert.assertTrue(buildLog.contains("WARNING: Package is not verified with GraalVM."));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,20 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
return FileVisitResult.CONTINUE;
}
}

@Test(description = "Test Graalvm incompatible ballerina project")
public void testGraalVMIncompatibleProject() throws IOException {
Path projectPath = this.testResources.resolve("validGraalvmCompatibleProject");
System.setProperty(ProjectConstants.USER_DIR, projectPath.toString());
TestCommand testCommand = new TestCommand(projectPath, printStream, printStream, false);
// non existing bal file
new CommandLine(testCommand).parseArgs("--graalvm");
try {
testCommand.execute();
} catch (BLauncherException e) {
String buildLog = readOutput(true);
Assert.assertTrue(buildLog.contains("WARNING: Package is not compatible with GraalVM."));
}
}

}
Loading

0 comments on commit b56a6a0

Please sign in to comment.