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 1 commit
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 @@ -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 @@ -204,6 +205,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 @@ -872,6 +872,27 @@ 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);
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.assertTrue(buildLog.contains("WARNING [Dependencies.toml:(6:1,18:1)] " +
Thevakumar-Luheerathan marked this conversation as resolved.
Show resolved Hide resolved
"Detected corrupted Dependencies.toml file. This will be updated to latest dependencies."));
String depContent = Files.readString(projectPath.resolve("Dependencies.toml"), Charset.defaultCharset())
.replace("/r" , "");
String corrcetDepContent = Files.readString(projectPath.resolve("Dependencies-corrected.toml"),
Charset.defaultCharset()).replace("/r" , "");
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
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. This will be updated to latest dependencies.",
Thevakumar-Luheerathan marked this conversation as resolved.
Show resolved Hide resolved
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