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

Warn about corruption in Dependencies.toml. #42717

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.Set;

import static io.ballerina.cli.launcher.LauncherUtils.createLauncherException;
import static io.ballerina.projects.internal.ProjectDiagnosticErrorCode.CORRUPTED_DEPENDENCIES_TOML;
import static io.ballerina.projects.util.ProjectConstants.DOT;
import static io.ballerina.projects.util.ProjectConstants.TOOL_DIAGNOSTIC_CODE_PREFIX;

Expand Down Expand Up @@ -207,6 +208,13 @@ public void execute(Project project) {
throw createLauncherException("package resolution contains errors");
}

// Add corrupted dependencies toml diagnostic
project.currentPackage().dependencyManifest().diagnostics().diagnostics().forEach(diagnostic -> {
if (diagnostic.diagnosticInfo().code().equals(CORRUPTED_DEPENDENCIES_TOML.diagnosticId())) {
diagnostics.add(diagnostic);
}
});

// Package resolution is successful. Continue compiling the package.
if (project.buildOptions().dumpBuildTime()) {
start = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,31 @@ public void testBuildBalProjectWithDumpRawGraphsFlag() throws IOException {
ProjectUtils.deleteDirectory(projectPath.resolve("target"));
}

@Test(description = "Build a package with corrupted Dependencies.toml file")
public void testBuildWithCorruptedDependenciesToml() throws IOException {
Path projectPath = this.testResources.resolve("corrupted-dependecies-toml-file");
cleanTarget(projectPath);
System.setProperty(USER_DIR_PROPERTY, projectPath.toString());
Path sourcePath = projectPath.resolve("Dependencies-corrupt.toml");
Path destinationPath = projectPath.resolve("Dependencies.toml");
Files.copy(sourcePath, destinationPath);
BuildCommand buildCommand = new BuildCommand(projectPath, printStream, printStream, false);
new CommandLine(buildCommand);
buildCommand.execute();
String buildLog = readOutput(true);
Assert.assertEquals(
buildLog.replaceAll("\r", ""),
getOutput("corrupted-dependencies-toml.txt").replaceAll("\r", ""));
String depContent = Files.readString(projectPath.resolve("Dependencies.toml"), Charset.defaultCharset())
.replace("/r" , "");
String ballerinaShortVersion = RepoUtils.getBallerinaShortVersion();
String corrcetDepContent = Files.readString(projectPath.resolve("Dependencies-corrected.toml"),
Charset.defaultCharset()).replace("/r" , "")
.replace("DIST_VERSION", ballerinaShortVersion);
Assert.assertEquals(depContent, corrcetDepContent);
Files.delete(destinationPath);
}

@Test(description = "Test bir cached project build performance")
public void testBirCachedProjectBuildPerformance() {
Path projectPath = this.testResources.resolve("noClassDefProject");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Compiling source
luheerathan/test1:0.1.0
WARNING [Dependencies.toml:(6:1,18:1)] Detected corrupted Dependencies.toml file. Dependencies will be updated to the latest versions.

Generating executable
target/bin/test1.jar
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Compiling source
luheerathan/test1:0.1.0
WARNING [Dependencies.toml:(6:1,18:1)] Detected corrupted Dependencies.toml file. Dependencies will be updated to the latest versions.

Generating executable
target/bin/test1.jar
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
org = "luheerathan"
name = "test1"
version = "0.1.0"
distribution = "2201.9.0"

[build-options]
observabilityIncluded = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# AUTO-GENERATED FILE. DO NOT MODIFY.

# This file is auto-generated by Ballerina for managing dependency versions.
# It should not be modified by hand.

[ballerina]
dependencies-toml-version = "2"
distribution-version = "DIST_VERSION"

[[package]]
org = "luheerathan"
name = "test1"
version = "0.1.0"
modules = [
{org = "luheerathan", packageName = "test1", moduleName = "test1"}
]

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# AUTO-GENERATED FILE. DO NOT MODIFY.

# This file is auto-generated by Ballerina for managing dependency versions.
# It should not be modified by hand.

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201"

[[package]]
org = "luheerathan"
name = "test1"
version = "0.1.0"
modules = [
{org = "luheerathan", packageName = "test1", moduleName = "test1"}
]

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public function main() {

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,19 @@ private DependencyManifestBuilder(TomlDocument dependenciesToml,
this.dependenciesToml = Optional.ofNullable(dependenciesToml);
this.packageDescriptor = packageDescriptor;
this.diagnosticList = new ArrayList<>();
this.dependencyManifest = parseAsDependencyManifest();
DependencyManifest parsedDependecyManifest = parseAsDependencyManifest();
if (parsedDependecyManifest.diagnostics().hasErrors()) {
var diagnosticInfo = new DiagnosticInfo(
ProjectDiagnosticErrorCode.CORRUPTED_DEPENDENCIES_TOML.diagnosticId(),
"Detected corrupted 'Dependencies.toml' file. Dependencies will be updated to the latest versions.",
DiagnosticSeverity.WARNING);
var diagnostic = DiagnosticFactory.createDiagnostic(diagnosticInfo,
this.dependenciesToml.get().toml().rootNode().location());
this.dependencyManifest = DependencyManifest.from(null, null,
Collections.emptyList(), Collections.emptyList(), new DefaultDiagnosticResult(List.of(diagnostic)));
} else {
this.dependencyManifest = parsedDependecyManifest;
}
}

public static DependencyManifestBuilder from(TomlDocument dependenciesToml,
Expand Down
Loading
Loading