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

[2201.7.x] Check org, name for null before package resolution when resolving dependencies in Ballerina.toml #42723

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1250,4 +1250,20 @@ 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 = "Build a project with invalid fields in TOML array 'dependency'")
public void testBuildProjectWithInvalidDependencyArrayInBallerinaToml() throws IOException {
Path projectPath = this.testResources.resolve("invalid-dependency-array-project");
System.setProperty("user.dir", projectPath.toString());
BuildCommand buildCommand = new BuildCommand(projectPath, printStream, printStream, false);
new CommandLine(buildCommand).parseArgs();
try {
buildCommand.execute();
} catch (BLauncherException e) {
Assert.assertEquals("error: compilation contains errors", e.getDetailedMessages().get(0));
String buildLog = readOutput(true);
Assert.assertEquals(buildLog.replaceAll("\r", ""),
getOutput("build-bal-project-with-invalid-dependency-array.txt"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Compiling source
foo/winery:0.1.0
ERROR [Ballerina.toml:(7:7,7:19)] invalid 'org' under [[dependency]]: 'org' can only contain alphanumerics and underscores
ERROR [Ballerina.toml:(8:8,8:15)] invalid 'name' under [[dependency]]: 'name' can only contain alphanumerics, underscores and periods
ERROR [Ballerina.toml:(9:11,9:19)] invalid 'version' under [[dependency]]: 'version' should be compatible with semver
ERROR [Ballerina.toml:(12:1,16:21)] 'name' under [[dependency]] is missing
ERROR [Ballerina.toml:(12:1,16:21)] 'org' under [[dependency]] is missing
ERROR [Ballerina.toml:(12:1,16:21)] 'version' under [[dependency]] is missing
ERROR [Ballerina.toml:(13:1,13:19)] key 'org1' not supported in schema 'dependency'
ERROR [Ballerina.toml:(14:1,14:15)] key 'name2' not supported in schema 'dependency'
ERROR [Ballerina.toml:(15:1,15:19)] key 'version3' not supported in schema 'dependency'
ERROR [Ballerina.toml:(16:14,16:21)] invalid 'repository' under [dependency]: 'repository' can only have the value 'local'
ERROR [main.bal:(2:13,2:20)] incompatible types: expected 'int', found 'string'
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Compiling source
foo/winery:0.1.0
ERROR [Ballerina.toml:(7:7,7:19)] invalid 'org' under [[dependency]]: 'org' can only contain alphanumerics and underscores
ERROR [Ballerina.toml:(8:8,8:15)] invalid 'name' under [[dependency]]: 'name' can only contain alphanumerics, underscores and periods
ERROR [Ballerina.toml:(9:11,9:19)] invalid 'version' under [[dependency]]: 'version' should be compatible with semver
ERROR [Ballerina.toml:(12:1,16:21)] 'name' under [[dependency]] is missing
ERROR [Ballerina.toml:(12:1,16:21)] 'org' under [[dependency]] is missing
ERROR [Ballerina.toml:(12:1,16:21)] 'version' under [[dependency]] is missing
ERROR [Ballerina.toml:(13:1,13:19)] key 'org1' not supported in schema 'dependency'
ERROR [Ballerina.toml:(14:1,14:15)] key 'name2' not supported in schema 'dependency'
ERROR [Ballerina.toml:(15:1,15:19)] key 'version3' not supported in schema 'dependency'
ERROR [Ballerina.toml:(16:14,16:21)] invalid 'repository' under [dependency]: 'repository' can only have the value 'local'
ERROR [main.bal:(2:13,2:20)] incompatible types: expected 'int', found 'string'
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
org = "foo"
name = "winery"
version = "0.1.0"

[[dependency]]
org = "ballerina#"
name = "dat$a"
version = "0.1.0r"
repository = "local"

[[dependency]]
org1 = "ballerina"
name2 = "data"
version3 = "0.1.0"
repository = "maven"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public function main() {
int x = "hello";
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ void updateDeprecatedStatusForPackage(PackageDescriptor descriptor) {
public boolean isPackageExists(PackageOrg org,
PackageName name,
PackageVersion version) {
if (org.value() == null || name.value() == null) {
return false;
}
Path balaPath = getPackagePath(org.value(), name.value(), version.value().toString());
return Files.exists(balaPath);
}
Expand Down