Skip to content

Commit

Permalink
Merge pull request #40195 from KavinduZoysa/sync-with-master
Browse files Browse the repository at this point in the history
Sync `group by` branch with master
  • Loading branch information
KavinduZoysa committed Apr 12, 2023
2 parents 816f2d6 + 4e3b3d1 commit 9bfcdf3
Show file tree
Hide file tree
Showing 153 changed files with 2,832 additions and 754 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/language_server_simulator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
branch: ["master", "2201.2.x", "2201.3.x", "2201.4.x", "2201.4.0-stage"]
branch: ["master", "2201.3.x", "2201.4.x", "2201.4.2-stage", "2201.5.x", "2201.5.0-stage"]
skipGenerators: ["", "IMPORT_STATEMENT"]

steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ public Object instantiate(Strand s) {
return instantiate(s, new BInitialValueEntry[0]);
}

public MapValue getAnnotations() {
return annotations;
}

@Override
public Object instantiate(Strand s, BInitialValueEntry[] initialValues) {
Type referredType = getReferredType(this.describingType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public void execute() {

// validate deprecation message
if (!validateDeprecationMsg(deprecationMsg)) {
CommandUtil.printError(errStream, "invalid deprecation message. The character `\\` " +
"not allowed in the deprecation message. Please provide a valid message.",
CommandUtil.printError(errStream, "invalid deprecation message. The message can only contain" +
" alphanumerics, underscores, hyphens, commas, periods and spaces.",
USAGE_TEXT, false);
CommandUtil.exitError(this.exitWhenFinish);
return;
Expand All @@ -133,7 +133,7 @@ public void execute() {

private boolean validateDeprecationMsg(String deprecationMsg) {
if (deprecationMsg != null) {
return deprecationMsg.matches("^[^\\\\]*$");
return deprecationMsg.matches("^[a-zA-Z0-9,.'\\-_ ]*$");
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
import java.io.PrintStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static io.ballerina.cli.cmd.Constants.TEST_COMMAND;
Expand All @@ -58,6 +60,7 @@ public class TestCommand implements BLauncherCmd {

private final PrintStream outStream;
private final PrintStream errStream;
private Path projectPath;
private final boolean exitWhenFinish;

public TestCommand() {
Expand Down Expand Up @@ -120,8 +123,8 @@ public TestCommand() {
"dependencies.")
private Boolean offline;

@CommandLine.Parameters (arity = "0..1")
private final Path projectPath;
@CommandLine.Parameters(description = "Program arguments")
private List<String> argList = new ArrayList<>();

@CommandLine.Option(names = {"--help", "-h"}, hidden = true)
private boolean helpFlag;
Expand Down Expand Up @@ -185,8 +188,8 @@ public TestCommand() {
@CommandLine.Option(names = "--excludes", description = "option to exclude source files/folders from code coverage")
private String excludes;

private static final String testCmd = "bal test [--offline]\n" +
" [<ballerina-file> | <package-path>] [(--key=value)...]";
private static final String testCmd = "bal test [--OPTIONS]\n" +
" [<ballerina-file> | <package-path>] [(-Ckey=value)...]";

public void execute() {
long start = 0;
Expand All @@ -196,6 +199,18 @@ public void execute() {
return;
}

String[] cliArgs = new String[0];
if (!argList.isEmpty()) {
if (!argList.get(0).matches(ProjectConstants.CONFIG_ARGS_PATTERN)) {
this.projectPath = Paths.get(argList.get(0));
if (argList.size() > 1) {
cliArgs = argList.subList(1, argList.size()).toArray(new String[0]);
}
} else {
cliArgs = argList.toArray(new String[0]);
}
}

if (sticky == null) {
sticky = false;
}
Expand Down Expand Up @@ -311,7 +326,7 @@ public void execute() {
.addTask(new CompileTask(outStream, errStream, false, isPackageModified, buildOptions.enableCache()))
// .addTask(new CopyResourcesTask(), listGroups) // merged with CreateJarTask
.addTask(new RunTestsTask(outStream, errStream, rerunTests, groupList, disableGroupList, testList,
includes, coverageFormat, moduleMap, listGroups, excludes),
includes, coverageFormat, moduleMap, listGroups, excludes, cliArgs),
project.buildOptions().nativeImage())
.addTask(new RunNativeImageTestTask(outStream, rerunTests, groupList, disableGroupList,
testList, includes, coverageFormat, moduleMap, listGroups),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ private static Optional<BLauncherCmd> getInvokedCmd(String... args) {
// is not provided
.setEndOfOptionsDelimiter("");
cmdParser.getSubcommands().get("build").setStopAtUnmatched(false).setStopAtPositional(true);
cmdParser.getSubcommands().get("test").setStopAtUnmatched(false).setStopAtPositional(true);
cmdParser.getSubcommands().get("test").setStopAtUnmatched(true).setStopAtPositional(true)
.setUnmatchedOptionsArePositionalParams(true)
.setEndOfOptionsDelimiter("");

// Build Version Command
VersionCmd versionCmd = new VersionCmd();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,34 +218,60 @@ private boolean isPackCmdForATemplatePkg(Project project) {
return compileForBalPack && project.currentPackage().manifest().template();
}

/**
* Prints the warning that explains the dependency update due to the detection of a new distribution.
*
* @param project project instance
*/
private void printWarningForHigherDistribution(Project project) {
SemanticVersion prevDistributionVersion = project.currentPackage().dependencyManifest().distributionVersion();
SemanticVersion currentDistributionVersion = SemanticVersion.from(RepoUtils.getBallerinaShortVersion());
if (!project.buildOptions().sticky() && (null == prevDistributionVersion
|| ProjectUtils.isNewUpdateDistribution(prevDistributionVersion, currentDistributionVersion))) {

if (project.currentPackage().dependencyManifest().dependenciesTomlVersion() != null) {
String currentVersionForDiagnostic = String.valueOf(currentDistributionVersion.minor());
if (currentDistributionVersion.patch() != 0) {
currentVersionForDiagnostic += DOT + currentDistributionVersion.patch();
if (project.currentPackage().dependencyManifest().dependenciesTomlVersion() != null) {
String currentVersionForDiagnostic = String.valueOf(currentDistributionVersion.minor());
if (currentDistributionVersion.patch() != 0) {
currentVersionForDiagnostic += DOT + currentDistributionVersion.patch();
}
String prevVersionForDiagnostic;
if (null != prevDistributionVersion) {
prevVersionForDiagnostic = String.valueOf(prevDistributionVersion.minor());
if (prevDistributionVersion.patch() != 0) {
prevVersionForDiagnostic += DOT + prevDistributionVersion.patch();
}
String prevVersionForDiagnostic;
if (null != prevDistributionVersion) {
prevVersionForDiagnostic = String.valueOf(prevDistributionVersion.minor());
if (prevDistributionVersion.patch() != 0) {
prevVersionForDiagnostic += DOT + prevDistributionVersion.patch();
}
} else {
prevVersionForDiagnostic = "4 or an older Update";
}
String warning = null;
// existing project
if (prevDistributionVersion == null) {
// Built with Update 4 or less. Therefore, we issue a warning
warning = "Detected an attempt to compile this package using Swan Lake Update "
+ currentVersionForDiagnostic +
". However, this package was built using Swan Lake Update " + prevVersionForDiagnostic +
".";
if (project.buildOptions().sticky()) {
warning += "\nHINT: Execute the bal command with --sticky=false";
} else {
prevVersionForDiagnostic = "4 or an older Update";
warning += " To ensure compatibility, the Dependencies.toml file will be updated with the " +
"latest versions that are compatible with Update " + currentVersionForDiagnostic + ".";
}
} else {
// Built with Update 5 or above
boolean newUpdateDistribution =
ProjectUtils.isNewUpdateDistribution(prevDistributionVersion, currentDistributionVersion);
if (newUpdateDistribution) {
// Issue a warning
warning = "Detected an attempt to compile this package using Swan Lake Update "
+ currentVersionForDiagnostic +
". However, this package was built using Swan Lake Update " + prevVersionForDiagnostic +
". To ensure compatibility, the Dependencies.toml file will be updated with the " +
"latest versions that are compatible with Update " + currentVersionForDiagnostic + ".";
}
}
if (warning != null) {
DiagnosticInfo diagnosticInfo = new DiagnosticInfo(
ProjectDiagnosticErrorCode.BUILT_WITH_OLDER_SL_UPDATE_DISTRIBUTION.diagnosticId(),
"Detected an attempt to build this package using Swan Lake Update "
+ currentVersionForDiagnostic +
". However, this package was built using Swan Lake Update " + prevVersionForDiagnostic +
". To ensure compatibility, the Dependencies.toml file will be updated with the " +
"latest versions that are compatible with Update " + currentVersionForDiagnostic + ".",
DiagnosticSeverity.WARNING);
warning, DiagnosticSeverity.WARNING);
PackageDiagnostic diagnostic = new PackageDiagnostic(diagnosticInfo,
project.currentPackage().descriptor().name().toString());
err.println(diagnostic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public class RunTestsTask implements Task {
private String singleExecTests;
private Map<String, Module> coverageModules;
private boolean listGroups;
private final List<String> cliArgs;

TestReport testReport;
private static final Boolean isWindows = System.getProperty("os.name").toLowerCase(Locale.getDefault())
Expand All @@ -121,10 +122,11 @@ public class RunTestsTask implements Task {

public RunTestsTask(PrintStream out, PrintStream err, boolean rerunTests, String groupList,
String disableGroupList, String testList, String includes, String coverageFormat,
Map<String, Module> modules, boolean listGroups, String excludes) {
Map<String, Module> modules, boolean listGroups, String excludes, String[] cliArgs) {
this.out = out;
this.err = err;
this.isRerunTestExecution = rerunTests;
this.cliArgs = List.of(cliArgs);

if (disableGroupList != null) {
this.disableGroupList = disableGroupList;
Expand Down Expand Up @@ -340,6 +342,9 @@ private int runTestSuite(Target target, Package currentPackage, JBallerinaBacken
cmdArgs.add(this.singleExecTests != null ? this.singleExecTests : "");
cmdArgs.add(Boolean.toString(isRerunTestExecution));
cmdArgs.add(Boolean.toString(listGroups));
cliArgs.forEach((arg) -> {
cmdArgs.add(arg);
});

ProcessBuilder processBuilder = new ProcessBuilder(cmdArgs).inheritIO();
Process proc = processBuilder.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ NAME
ballerina-run - Compile and run the current package

SYNOPSIS
bal run [OPTIONS] [<package>|<source-file>|<jar-file>] [--] <args...>
bal run [OPTIONS] [<package>|<source-file>|<jar-file>] [-- <args...> <(-Ckey=value)...>]


DESCRIPTION
Expand Down Expand Up @@ -64,6 +64,9 @@ ARGUMENTS

args...
The list of command-line arguments for the Ballerina program.
The arguments can be program arguments defined in the parameter
list of the 'main' function or configurable variables. Configurable
values can be provided with the syntax '-C<key>=<value>'.


EXAMPLES
Expand All @@ -79,3 +82,6 @@ EXAMPLES
Run the 'main' function in the current package with three program args:
add, 10, and 5.
$ bal run -- add 10 5

Run the test functions with values provided for configurable variables:
$ bal run -- -Cval1=add -Cval2=10 -Cval3=5
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ NAME
ballerina-test - Run package tests

SYNOPSIS
bal test [OPTIONS] [<package>|<source-file>]
bal test [OPTIONS] [<package>|<source-file>] [(-Ckey=value)...]


DESCRIPTION
Expand Down Expand Up @@ -88,6 +88,11 @@ OPTIONS
see https://ballerina.io/learn/test-ballerina-code/execute-tests/#generate-test-report-and-code-coverage.


ARGUMENTS
(-Ckey=value)...
The list of configurable variables for the Ballerina program.


EXAMPLES
Run all the test functions in the current package.
$ bal test
Expand Down Expand Up @@ -142,3 +147,6 @@ EXAMPLES
Run the tests with the code coverage with directories excludes from coverage
calculation with '**' and '*'.
$ bal test --code-coverage --excludes=<source_path1/**>,<source_path2/*>

Run the test functions with values provided for configurable variables:
$ bal test -Cval1=add -Cval2=10 -Cval3=5
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
import static org.ballerinalang.central.client.Utils.createBalaInHomeRepo;
import static org.ballerinalang.central.client.Utils.getAsList;
import static org.ballerinalang.central.client.Utils.getBearerToken;
import static org.ballerinalang.central.client.Utils.getRemoteRepo;
import static org.ballerinalang.central.client.Utils.isApplicationJsonContentType;

/**
* {@code CentralAPIClient} is a client for the Central API.
*
Expand Down Expand Up @@ -337,9 +337,10 @@ public void pushPackage(Path balaPath, String org, String name, String version,
.addFormDataPart("bala-file", fileName,
RequestBody.create(MediaType.parse(APPLICATION_OCTET_STREAM), balaPath.toFile()))
.build();

String remoteRepo = getRemoteRepo();
String projectRepo = balaPath.toString().split(name)[0] + name;
ProgressRequestBody balaFileReqBodyWithProgressBar = new ProgressRequestBody(balaFileReqBody,
packageSignature + " [project repo -> central]", this.outStream);
packageSignature + " [" + projectRepo + " -> " + remoteRepo + "]", this.outStream);

// If OutStream is disabled, then pass `balaFileReqBody` only
Request pushRequest = getNewRequest(supportedPlatform, ballerinaVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,10 @@ private CentralClientConstants() {
static final String IS_DEPRECATED = "isdeprecated";
static final String DEPRECATE_MESSAGE = "deprecatemessage";
public static final String ENABLE_OUTPUT_STREAM = "enableOutputStream";
static final String PRODUCTION_REPO = "central.ballerina.io";
static final String STAGING_REPO = "staging-central.ballerina.io";
static final String DEV_REPO = "dev-central.ballerina.io";
public static final String BALLERINA_STAGE_CENTRAL = "BALLERINA_STAGE_CENTRAL";
public static final String BALLERINA_DEV_CENTRAL = "BALLERINA_DEV_CENTRAL";

}
Loading

0 comments on commit 9bfcdf3

Please sign in to comment.