Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cli and bindgen tool tests with java 11 dependencies #41243

Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ public void execute() {
String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(PUSH_COMMAND);
outStream.println(commandUsageInfo);
// Exit status, zero for OK, non-zero for error
Runtime.getRuntime().exit(0);
if (exitWhenFinish) {
Runtime.getRuntime().exit(0);
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public void execute(Project project) {
if (project.buildOptions().dumpBuildTime()) {
start = System.currentTimeMillis();
}
String warning = GraalVMCompatibilityUtils.getWarningForPackage(
project.currentPackage(), jBallerinaBackend.targetPlatform().code());
String warning = GraalVMCompatibilityUtils.getWarningForPackage(project.currentPackage());
if (warning != null) {
out.println("\n" + warning);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ public void execute(Project project) {
}
EmitResult emitResult;
if (project.buildOptions().nativeImage() && project.buildOptions().cloud().equals("")) {
String warnings = GraalVMCompatibilityUtils.getAllWarnings(
project.currentPackage(), jBallerinaBackend.targetPlatform().code(), false);
String warnings = GraalVMCompatibilityUtils.getAllWarnings(project.currentPackage(), false);
if (!warnings.isEmpty()) {
out.println(warnings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,23 @@ public ResolveMavenDependenciesTask(PrintStream out) {

@Override
public void execute(Project project) {
List<Map<String, Object>> platformLibraries = new ArrayList<>();
List<Map<String, Object>> platformRepositories = new ArrayList<>();
PackageManifest.Platform platform = null;
for (JvmTarget jvmTarget : JvmTarget.values()) {
platform = project.currentPackage().manifest().platform(jvmTarget.code());
if (platform != null) {
break;
platformLibraries.addAll(platform.dependencies());
platformRepositories.addAll(platform.repositories());
}
}
if (platform == null) {
return;
}

List<Map<String, Object>> platformLibraries = platform.dependencies();
List<Map<String, Object>> platformRepositories = platform.repositories();
List<Map<String, Object>> mavenCustomRepos = new ArrayList<>();
List<Map<String, Object>> mavenDependencies = new ArrayList<>();
if (platformLibraries == null) {
if (platformLibraries.isEmpty()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,7 @@ public void execute(Project project) {
if (hasTests) {
int testResult = 1;
try {
String warnings = GraalVMCompatibilityUtils.getAllWarnings(
project.currentPackage(), jBallerinaBackend.targetPlatform().code(), true);
String warnings = GraalVMCompatibilityUtils.getAllWarnings(project.currentPackage(), true);
if (!warnings.isEmpty()) {
out.println(warnings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package io.ballerina.cli.utils;

import io.ballerina.projects.AnyTarget;
import io.ballerina.projects.JvmTarget;
import io.ballerina.projects.PackageDependencyScope;
import io.ballerina.projects.PackageManifest;
import io.ballerina.projects.ResolvedPackageDependency;
Expand All @@ -37,27 +38,22 @@
*/
public class GraalVMCompatibilityUtils {

private static boolean hasExternalPlatformDependencies(io.ballerina.projects.Package pkg, String targetPlatform) {
// Check if external platform dependencies are defined
PackageManifest manifest = pkg.manifest();
return manifest.platform(targetPlatform) != null &&
!manifest.platform(targetPlatform).dependencies().isEmpty();
}

/**
* Get the GraalVM compatibility warning message for the given package.
*
* @param pkg Package to be verified
* @param targetPlatform Target platform
* @return Warning message
*/
public static String getWarningForPackage(io.ballerina.projects.Package pkg, String targetPlatform) {
public static String getWarningForPackage(io.ballerina.projects.Package pkg) {
// Verify that Java dependencies (if exist) of this package are GraalVM compatible
if (hasExternalPlatformDependencies(pkg, targetPlatform)) {
PackageManifest.Platform platform = pkg.manifest().platform(targetPlatform);
PackageManifest manifest = pkg.manifest();
for (JvmTarget jvmTarget : JvmTarget.values()) {
PackageManifest.Platform platform = manifest.platform(jvmTarget.code());
if (platform == null || platform.dependencies().isEmpty()) {
continue;
}
String packageName = pkg.manifest().name().value();

if (platform == null || platform.graalvmCompatible() == null) {
if (platform.graalvmCompatible() == null) {
return String.format(
"************************************************************%n" +
"* WARNING: Package is not verified with GraalVM. *%n" +
Expand All @@ -68,7 +64,7 @@ public static String getWarningForPackage(io.ballerina.projects.Package pkg, Str
"are compatible with GraalVM. Subsequently, update the Ballerina.toml file under " +
"the section '[platform.%s]' with the attribute 'graalvmCompatible = true'.%n%n" +
"************************************************************%n",
packageName, targetPlatform);
packageName, jvmTarget.code());
} else if (!platform.graalvmCompatible()) {
return String.format(
"************************************************************%n" +
Expand Down Expand Up @@ -116,14 +112,13 @@ private static String getWarningForDependencies(io.ballerina.projects.Package pk
* Get all the applicable warning messages for GraalVM compatibility of the package.
*
* @param pkg Package to be verified
* @param targetPlatform Target platform
* @param isTestExec Whether it is a test execution
* @return Warning message
*/
public static String getAllWarnings(io.ballerina.projects.Package pkg, String targetPlatform, boolean isTestExec) {
public static String getAllWarnings(io.ballerina.projects.Package pkg, boolean isTestExec) {
StringBuilder warnings = new StringBuilder();
// Verify that Java dependencies (if exist) of this package are GraalVM compatible
String packageWarning = getWarningForPackage(pkg, targetPlatform);
String packageWarning = getWarningForPackage(pkg);
if (packageWarning != null) {
warnings.append(packageWarning);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ public void testPushWithCustomPath() throws IOException {

try (MockedStatic<RepoUtils> repoUtils = Mockito.mockStatic(RepoUtils.class)) {
repoUtils.when(RepoUtils::createAndGetHomeReposPath).thenReturn(mockRepo);
repoUtils.when(RepoUtils::getBallerinaShortVersion).thenReturn("1.0.0");
repoUtils.when(RepoUtils::readSettings).thenReturn(Settings.from());
pushCommand.execute();
}

Expand Down Expand Up @@ -257,7 +259,7 @@ public void testPushCommandArgAndHelp() throws IOException {
new CommandLine(pushCommand).parse(args);
pushCommand.execute();

Assert.assertTrue(readOutput().contains("ballerina-push - Push packages to Ballerina Central"));
Assert.assertTrue(readOutput().contains("ballerina-push - Push the Ballerina Archive (BALA)"));
}

@Test(description = "Test push command with help flag")
Expand All @@ -269,7 +271,7 @@ public void testPushCommandWithHelp() throws IOException {
new CommandLine(pushCommand).parse(args);
pushCommand.execute();

Assert.assertTrue(readOutput().contains("ballerina-push - Push packages to Ballerina Central"));
Assert.assertTrue(readOutput().contains("ballerina-push - Push the Ballerina Archive (BALA)"));
}

@Test
Expand All @@ -287,6 +289,8 @@ public void testPushToCustomRepo() throws IOException {
new CommandLine(pushCommand).parse(args);
try (MockedStatic<RepoUtils> repoUtils = Mockito.mockStatic(RepoUtils.class)) {
repoUtils.when(RepoUtils::createAndGetHomeReposPath).thenReturn(mockRepo);
repoUtils.when(RepoUtils::getBallerinaShortVersion).thenReturn("1.0.0");
repoUtils.when(RepoUtils::readSettings).thenReturn(Settings.from());
pushCommand.execute();
}

Expand Down Expand Up @@ -338,7 +342,7 @@ public void testPushWithEmptyPackageMd() throws IOException {
Files.delete(projectPath.resolve(ProjectConstants.PACKAGE_MD_FILE_NAME));

// Push
String expected = "package md file cannot be empty";
String expected = "md file cannot be empty";

PushCommand pushCommand = new PushCommand(projectPath, printStream, printStream, false);
new CommandLine(pushCommand).parse();
Expand All @@ -363,7 +367,8 @@ public void testPushToAnUnsupportedRepo() throws IOException {
PushCommand pushCommand = new PushCommand(projectPath, printStream, printStream, false);
new CommandLine(pushCommand).parse(args);
pushCommand.execute();
String errMsg = "unsupported repository 'stdlib.local' found. Only 'local' repository is supported.";
String errMsg = "unsupported repository 'stdlib.local' found. Only 'local' repository and repositories " +
"mentioned in the Settings.toml are supported.";
Assert.assertTrue(readOutput().contains(errMsg));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.8.0-SNAPSHOT"

[[package]]
org = "ballerina"
Expand All @@ -14,12 +15,22 @@ scope = "testOnly"

[[package]]
org = "ballerina"
name = "test"
name = "lang.error"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "test"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.error"}
]
modules = [
{org = "ballerina", packageName = "test", moduleName = "test"}
]
Expand All @@ -42,6 +53,4 @@ dependencies = [
]
modules = [
{org = "pramjs", packageName = "project_b", moduleName = "project_b"}
]


]
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ digraph "Initial" {
node [shape=record]
"foo/package_a" [label="<0.1.0> foo/package_a:0.1.0"];
"foo/package_b" [label="<0.1.0> foo/package_b:0.1.0"];
"foo/package_c" [label="<0.1.0> foo/package_c:0.1.0"];
"foo/package_c" [unresolved="true",color="grey",label="<0.1.0> foo/package_c:0.1.0"];

// Edges
"foo/package_a":"0.1.0" -> "foo/package_b":"0.1.0";
Expand Down Expand Up @@ -51,7 +51,7 @@ digraph "Initial" {
node [shape=record]
"foo/package_a" [label="<0.1.0> foo/package_a:0.1.0"];
"foo/package_b" [label="<0.1.0> foo/package_b:0.1.0"];
"foo/package_c" [label="<0.1.0> foo/package_c:0.1.0"];
"foo/package_c" [unresolved="true",color="grey",label="<0.1.0> foo/package_c:0.1.0"];

// Edges
"foo/package_a":"0.1.0" -> "foo/package_b":"0.1.0";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ digraph "foo/package_a:0.1.0" {
// Edges
"foo/package_a":"0.1.0" -> "foo/package_b":"0.1.0";
"foo/package_b":"0.1.0" -> "foo/package_c":"0.1.0";
}
}
No tests found
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ digraph "Initial" {
node [shape=record]
"foo/package_a" [label="<0.1.0> foo/package_a:0.1.0"];
"foo/package_b" [label="<0.1.0> foo/package_b:0.1.0"];
"foo/package_c" [label="<0.1.0> foo/package_c:0.1.0"];
"foo/package_c" [unresolved="true",color="grey",label="<0.1.0> foo/package_c:0.1.0"];

// Edges
"foo/package_a":"0.1.0" -> "foo/package_b":"0.1.0";
Expand Down Expand Up @@ -51,7 +51,7 @@ digraph "Initial" {
node [shape=record]
"foo/package_a" [label="<0.1.0> foo/package_a:0.1.0"];
"foo/package_b" [label="<0.1.0> foo/package_b:0.1.0"];
"foo/package_c" [label="<0.1.0> foo/package_c:0.1.0"];
"foo/package_c" [unresolved="true",color="grey",label="<0.1.0> foo/package_c:0.1.0"];

// Edges
"foo/package_a":"0.1.0" -> "foo/package_b":"0.1.0";
Expand Down Expand Up @@ -89,4 +89,5 @@ digraph "Final" {
// Edges
"foo/package_a":"0.1.0" -> "foo/package_b":"0.1.0";
"foo/package_b":"0.1.0" -> "foo/package_c":"0.1.0";
}
}
No tests found
3 changes: 1 addition & 2 deletions cli/ballerina-cli/src/test/resources/testng.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ under the License.
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >

<suite name="commands-test-suite">
<test name="command-tests" preserve-order="true">
<test name="command-tests">
<classes>
<class name="io.ballerina.cli.cmd.AddCommandTest" />
<class name="io.ballerina.cli.cmd.BaseCommandTest" />
Expand All @@ -41,7 +41,6 @@ under the License.
<class name="io.ballerina.cli.cmd.PackCommandTest" />
<class name="io.ballerina.cli.cmd.CommandUtilTest" />
<class name="io.ballerina.cli.cmd.TestNativeImageCommandTest"/>
<class name="io.ballerina.cli.cmd.BuildNativeImageCommandTest"/>
<class name="io.ballerina.cli.cmd.DeprecateCommandTest"/>
<class name="io.ballerina.cli.cmd.ToolCommandTest"/>
</classes>
Expand Down
Loading
Loading