diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java index c8327dc85e98..414485188df8 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java @@ -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; @@ -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(); diff --git a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java index 46103a063d02..93c0218f44c5 100644 --- a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java +++ b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java @@ -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"); diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/corrupted-dependencies-toml.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/corrupted-dependencies-toml.txt new file mode 100644 index 000000000000..d7995f8662e1 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/corrupted-dependencies-toml.txt @@ -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 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/corrupted-dependencies-toml.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/corrupted-dependencies-toml.txt new file mode 100644 index 000000000000..33f997a713eb --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/corrupted-dependencies-toml.txt @@ -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 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/corrupted-dependecies-toml-file/Ballerina.toml b/cli/ballerina-cli/src/test/resources/test-resources/corrupted-dependecies-toml-file/Ballerina.toml new file mode 100644 index 000000000000..1532051489af --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/corrupted-dependecies-toml-file/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "luheerathan" +name = "test1" +version = "0.1.0" +distribution = "2201.9.0" + +[build-options] +observabilityIncluded = true diff --git a/cli/ballerina-cli/src/test/resources/test-resources/corrupted-dependecies-toml-file/Dependencies-corrected.toml b/cli/ballerina-cli/src/test/resources/test-resources/corrupted-dependecies-toml-file/Dependencies-corrected.toml new file mode 100644 index 000000000000..3c95919acd36 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/corrupted-dependecies-toml-file/Dependencies-corrected.toml @@ -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"} +] + diff --git a/cli/ballerina-cli/src/test/resources/test-resources/corrupted-dependecies-toml-file/Dependencies-corrupt.toml b/cli/ballerina-cli/src/test/resources/test-resources/corrupted-dependecies-toml-file/Dependencies-corrupt.toml new file mode 100644 index 000000000000..62cbb98f45dd --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/corrupted-dependecies-toml-file/Dependencies-corrupt.toml @@ -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"} +] + diff --git a/cli/ballerina-cli/src/test/resources/test-resources/corrupted-dependecies-toml-file/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/corrupted-dependecies-toml-file/main.bal new file mode 100644 index 000000000000..b684ce66a33e --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/corrupted-dependecies-toml-file/main.bal @@ -0,0 +1,3 @@ +public function main() { + +} diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/DependencyManifestBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/DependencyManifestBuilder.java index d6f6f7ae294e..db383cc6e2fb 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/DependencyManifestBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/DependencyManifestBuilder.java @@ -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, diff --git a/compiler/ballerina-lang/src/test/java/io/ballerina/projects/DependenciesTomlTests.java b/compiler/ballerina-lang/src/test/java/io/ballerina/projects/DependenciesTomlTests.java index 9ecdb566ae86..6d2404e30dc3 100644 --- a/compiler/ballerina-lang/src/test/java/io/ballerina/projects/DependenciesTomlTests.java +++ b/compiler/ballerina-lang/src/test/java/io/ballerina/projects/DependenciesTomlTests.java @@ -132,13 +132,12 @@ public void testInvalidDependenciesTomlWithoutOrg() throws IOException { DEPENDENCIES_TOML_REPO.resolve("dependency-wo-org.toml")); DiagnosticResult diagnostics = depsManifest.diagnostics(); diagnostics.errors().forEach(OUT::println); - Assert.assertTrue(diagnostics.hasErrors()); - Assert.assertEquals(diagnostics.errors().size(), 2); - Iterator iterator = diagnostics.errors().iterator(); + Assert.assertEquals(diagnostics.diagnostics().size(), 1); + Iterator iterator = diagnostics.diagnostics().iterator(); Diagnostic firstDiagnostic = iterator.next(); - Assert.assertEquals(firstDiagnostic.message(), "'org' under [[package]] is missing"); - Assert.assertEquals(firstDiagnostic.location().lineRange().toString(), "(20:0,22:17)"); - Assert.assertEquals(iterator.next().message(), "'org' under [[package]] is missing"); + Assert.assertEquals(firstDiagnostic.message(), "Detected corrupted Dependencies.toml file. " + + "Dependencies will be updated to the latest versions."); + Assert.assertEquals(firstDiagnostic.location().lineRange().toString(), "(5:0,26:17)"); } /** @@ -154,13 +153,13 @@ public void testInvalidDependenciesTomlWithoutOrgValue() throws IOException { DependencyManifest depsManifest = getDependencyManifest( DEPENDENCIES_TOML_REPO.resolve("dependency-wo-org-value.toml")); DiagnosticResult diagnostics = depsManifest.diagnostics(); - diagnostics.errors().forEach(OUT::println); - Assert.assertTrue(diagnostics.hasErrors()); - Assert.assertEquals(diagnostics.errors().size(), 1); - Iterator iterator = diagnostics.errors().iterator(); + diagnostics.diagnostics().forEach(OUT::println); + Assert.assertEquals(diagnostics.diagnostics().size(), 1); + Iterator iterator = diagnostics.diagnostics().iterator(); Diagnostic firstDiagnostic = iterator.next(); - Assert.assertEquals(firstDiagnostic.location().lineRange().toString(), "(22:0,22:0)"); - Assert.assertEquals(firstDiagnostic.message(), "missing value"); + Assert.assertEquals(firstDiagnostic.message(), "Detected corrupted Dependencies.toml file. " + + "Dependencies will be updated to the latest versions."); + Assert.assertEquals(firstDiagnostic.location().lineRange().toString(), "(5:0,28:17)"); } /** @@ -176,30 +175,12 @@ public void testDependenciesTomlWithInvalidOrgNameVersion() throws IOException { DependencyManifest depsManifest = getDependencyManifest( DEPENDENCIES_TOML_REPO.resolve("invalid-org-name-value.toml")); DiagnosticResult diagnostics = depsManifest.diagnostics(); - diagnostics.errors().forEach(OUT::println); - - Assert.assertTrue(diagnostics.hasErrors()); - Assert.assertEquals(diagnostics.errors().size(), 7); - - Iterator iterator = diagnostics.errors().iterator(); + Assert.assertEquals(diagnostics.diagnostics().size(), 1); + Iterator iterator = diagnostics.diagnostics().iterator(); Diagnostic firstDiagnostic = iterator.next(); - Assert.assertEquals(firstDiagnostic.message(), "invalid 'org' under 'dependencies': " + - "'org' can only contain alphanumerics and underscores"); - Assert.assertEquals(firstDiagnostic.location().lineRange().toString(), "(13:11,13:18)"); - Assert.assertEquals(iterator.next().message(), "invalid 'name' under 'dependencies': " + - "'name' can only contain alphanumerics, underscores and periods"); - Diagnostic thirdDiagnostic = iterator.next(); - Assert.assertEquals(thirdDiagnostic.message(), "invalid 'org' under [[package]]: " + - "'org' can only contain alphanumerics and underscores"); - Assert.assertEquals(thirdDiagnostic.location().lineRange().toString(), "(21:6,21:13)"); - Assert.assertEquals(iterator.next().message(), "invalid 'name' under [[package]]: " + - "'name' can only contain alphanumerics, underscores and periods"); - Assert.assertEquals(iterator.next().message(), "invalid 'version' under [[package]]: " + - "'version' should be compatible with semver"); - Assert.assertEquals(iterator.next().message(), - "invalid 'org' under [[package]]: " + "maximum length of 'org' is 256 characters"); - Assert.assertEquals(iterator.next().message(), - "invalid 'name' under [[dependency]]: " + "maximum length of 'name' is 256 characters"); + Assert.assertEquals(firstDiagnostic.message(), "Detected corrupted Dependencies.toml file. " + + "Dependencies will be updated to the latest versions."); + Assert.assertEquals(firstDiagnostic.location().lineRange().toString(), "(5:0,33:17)"); } @Test(description = "Test dependencies.toml with invalid distribution version") @@ -207,15 +188,11 @@ public void testDependenciesTomlWithInvalidDistributionVersion() throws IOExcept DependencyManifest depsManifest = getDependencyManifest( DEPENDENCIES_TOML_REPO.resolve("invalid-dist-version-value.toml")); DiagnosticResult diagnostics = depsManifest.diagnostics(); - diagnostics.errors().forEach(OUT::println); - - Assert.assertTrue(diagnostics.hasErrors()); - Assert.assertEquals(diagnostics.errors().size(), 1); - - Iterator iterator = diagnostics.errors().iterator(); + Assert.assertEquals(diagnostics.diagnostics().size(), 1); + Iterator iterator = diagnostics.diagnostics().iterator(); Diagnostic firstDiagnostic = iterator.next(); - Assert.assertEquals(firstDiagnostic.message(), "invalid 'distribution-version' under [ballerina]: " + - "'distribution-version' should be compatible with semver rules"); + Assert.assertEquals(firstDiagnostic.message(), "Detected corrupted Dependencies.toml file. " + + "Dependencies will be updated to the latest versions."); } @Test @@ -247,20 +224,22 @@ public void testInvalidDependenciesToml() throws IOException { DependencyManifest depsManifest = getDependencyManifest( DEPENDENCIES_TOML_REPO.resolve("dependencies-non-array.toml")); depsManifest.diagnostics().errors().forEach(OUT::println); - Assert.assertTrue(depsManifest.diagnostics().hasErrors()); - Assert.assertEquals(depsManifest.diagnostics().errors().iterator().next().message(), - "incompatible type for key 'package': expected 'ARRAY', found 'OBJECT'"); + Assert.assertEquals(depsManifest.diagnostics().diagnostics().size(), 1); + Iterator iterator = depsManifest.diagnostics().diagnostics().iterator(); + Diagnostic firstDiagnostic = iterator.next(); + Assert.assertEquals(firstDiagnostic.message(), "Detected corrupted Dependencies.toml file. " + + "Dependencies will be updated to the latest versions."); } @Test public void testDependenciesTomlWithInvalidDependencyScope() throws IOException { DependencyManifest depsManifest = getDependencyManifest( DEPENDENCIES_TOML_REPO.resolve("dependencies-invalid-scope.toml")); - depsManifest.diagnostics().errors().forEach(OUT::println); - Assert.assertTrue(depsManifest.diagnostics().hasErrors()); - Assert.assertEquals(depsManifest.diagnostics().errorCount(), 1); - Assert.assertEquals(depsManifest.diagnostics().errors().iterator().next().message(), - "invalid 'scope' under [[package]]: 'scope' can only contain value 'testOnly'"); + Assert.assertEquals(depsManifest.diagnostics().diagnostics().size(), 1); + Iterator iterator = depsManifest.diagnostics().diagnostics().iterator(); + Diagnostic firstDiagnostic = iterator.next(); + Assert.assertEquals(firstDiagnostic.message(), "Detected corrupted Dependencies.toml file. " + + "Dependencies will be updated to the latest versions."); } @Test @@ -268,14 +247,11 @@ public void testDependenciesTomlWithoutDepsTomlVersion() throws IOException { DependencyManifest depsManifest = getDependencyManifest( DEPENDENCIES_TOML_REPO.resolve("without-deps-toml-version.toml")); depsManifest.diagnostics().diagnostics().forEach(OUT::println); - // old dependency version warning - Assert.assertTrue(depsManifest.diagnostics().hasWarnings()); - Assert.assertEquals(depsManifest.diagnostics().warnings().iterator().next().message(), - "Detected an old version of Dependencies.toml file. This will be updated to v2 format."); - // [[package]] not supported in the old dependencies toml spec - Assert.assertTrue(depsManifest.diagnostics().hasErrors()); - Assert.assertEquals(depsManifest.diagnostics().errors().iterator().next().message(), - "key 'package' not supported in schema 'Dependencies Toml Spec'"); + Assert.assertEquals(depsManifest.diagnostics().diagnostics().size(), 1); + Iterator iterator = depsManifest.diagnostics().diagnostics().iterator(); + Diagnostic firstDiagnostic = iterator.next(); + Assert.assertEquals(firstDiagnostic.message(), "Detected corrupted Dependencies.toml file. " + + "Dependencies will be updated to the latest versions."); } @Test @@ -327,15 +303,12 @@ public void testDependenciesTomlWithAdditionalAttributeInModulesArray() throws I DependencyManifest depsManifest = getDependencyManifest( DEPENDENCIES_TOML_REPO.resolve("dependencies-with-additional-attribute-in-modules.toml")); DiagnosticResult diagnostics = depsManifest.diagnostics(); - diagnostics.errors().forEach(OUT::println); - - Assert.assertTrue(diagnostics.hasErrors()); - Assert.assertEquals(diagnostics.errors().size(), 1); - - Iterator iterator = diagnostics.errors().iterator(); + Assert.assertEquals(diagnostics.diagnostics().size(), 1); + Iterator iterator = diagnostics.diagnostics().iterator(); Diagnostic firstDiagnostic = iterator.next(); - Assert.assertEquals(firstDiagnostic.message(), "key 'name' not supported in schema 'modules'"); - Assert.assertEquals(firstDiagnostic.location().lineRange().toString(), "(31:44,31:60)"); + Assert.assertEquals(firstDiagnostic.message(), "Detected corrupted Dependencies.toml file. " + + "Dependencies will be updated to the latest versions."); + Assert.assertEquals(firstDiagnostic.location().lineRange().toString(), "(5:0,41:1)"); } @Test(description = "Invalid Dependencies.toml file with additional attribute in dependencies array") @@ -343,15 +316,12 @@ public void testDependenciesTomlWithAdditionalAttributeInDependenciesArray() thr DependencyManifest depsManifest = getDependencyManifest( DEPENDENCIES_TOML_REPO.resolve("dependencies-with-additional-attribute-in-dependencies.toml")); DiagnosticResult diagnostics = depsManifest.diagnostics(); - diagnostics.errors().forEach(OUT::println); - - Assert.assertTrue(diagnostics.hasErrors()); - Assert.assertEquals(diagnostics.errors().size(), 1); - - Iterator iterator = diagnostics.errors().iterator(); + Assert.assertEquals(diagnostics.diagnostics().size(), 1); + Iterator iterator = diagnostics.diagnostics().iterator(); Diagnostic firstDiagnostic = iterator.next(); - Assert.assertEquals(firstDiagnostic.message(), "key 'version' not supported in schema 'dependencies'"); - Assert.assertEquals(firstDiagnostic.location().lineRange().toString(), "(13:37,13:54)"); + Assert.assertEquals(firstDiagnostic.message(), "Detected corrupted Dependencies.toml file. " + + "Dependencies will be updated to the latest versions."); + Assert.assertEquals(firstDiagnostic.location().lineRange().toString(), "(5:0,41:1)"); } @Test(description = "Invalid Dependencies.toml file with invalid tool ids") @@ -359,32 +329,12 @@ public void testDependenciesTomlWithInvalidToolId() throws IOException { DependencyManifest depsManifest = getDependencyManifest( DEPENDENCIES_TOML_REPO.resolve("tool-with-invalid-id-value.toml")); DiagnosticResult diagnostics = depsManifest.diagnostics(); - diagnostics.errors().forEach(OUT::println); - - Assert.assertTrue(diagnostics.hasErrors()); - Assert.assertEquals(diagnostics.errors().size(), 5); - - Iterator iterator = diagnostics.errors().iterator(); + Assert.assertEquals(diagnostics.diagnostics().size(), 1); + Iterator iterator = diagnostics.diagnostics().iterator(); Diagnostic firstDiagnostic = iterator.next(); - Assert.assertEquals(firstDiagnostic.message(), "invalid 'id' under [[tool]]: " + - "'id' cannot have initial underscore characters"); - Assert.assertEquals(firstDiagnostic.location().lineRange().toString(), "(26:5,26:11)"); - Diagnostic secondDiagnostic = iterator.next(); - Assert.assertEquals(secondDiagnostic.message(), "invalid 'id' under [[tool]]: " + - "'id' cannot have trailing underscore characters"); - Assert.assertEquals(secondDiagnostic.location().lineRange().toString(), "(32:5,32:11)"); - Diagnostic thirdDiagnostic = iterator.next(); - Assert.assertEquals(thirdDiagnostic.message(), "invalid 'id' under [[tool]]: " + - "'id' cannot have consecutive underscore characters"); - Assert.assertEquals(thirdDiagnostic.location().lineRange().toString(), "(38:5,38:12)"); - Diagnostic fourthDiagnostic = iterator.next(); - Assert.assertEquals(fourthDiagnostic.message(), "invalid 'id' under [[tool]]: " + - "'id' can only contain alphanumerics and underscores"); - Assert.assertEquals(fourthDiagnostic.location().lineRange().toString(), "(44:5,44:11)"); - Diagnostic fifthDiagnostic = iterator.next(); - Assert.assertEquals(fifthDiagnostic.message(), "invalid 'id' under [[tool]]: " + - "'id' cannot have initial numeric characters"); - Assert.assertEquals(fifthDiagnostic.location().lineRange().toString(), "(50:5,50:11)"); + Assert.assertEquals(firstDiagnostic.message(), "Detected corrupted Dependencies.toml file. " + + "Dependencies will be updated to the latest versions."); + Assert.assertEquals(firstDiagnostic.location().lineRange().toString(), "(5:0,53:17)"); } @Test(description = "Invalid Dependencies.toml file with invalid org, name in tool array") @@ -392,24 +342,12 @@ public void testDependenciesTomlWithInvalidToolOrgNameVersion() throws IOExcepti DependencyManifest depsManifest = getDependencyManifest( DEPENDENCIES_TOML_REPO.resolve("tool-with-invalid-org-name-version-value.toml")); DiagnosticResult diagnostics = depsManifest.diagnostics(); - diagnostics.errors().forEach(OUT::println); - - Assert.assertTrue(diagnostics.hasErrors()); - Assert.assertEquals(diagnostics.errors().size(), 3); - - Iterator iterator = diagnostics.errors().iterator(); + Assert.assertEquals(diagnostics.diagnostics().size(), 1); + Iterator iterator = diagnostics.diagnostics().iterator(); Diagnostic firstDiagnostic = iterator.next(); - Assert.assertEquals(firstDiagnostic.message(), "invalid 'org' under [[tool]]: " + - "maximum length of 'org' is 256 characters"); - Assert.assertEquals(firstDiagnostic.location().lineRange().toString(), "(26:6,26:337)"); - Diagnostic secondDiagnostic = iterator.next(); - Assert.assertEquals(secondDiagnostic.message(), "invalid 'name' under [[tool]]: " + - "maximum length of 'name' is 256 characters"); - Assert.assertEquals(secondDiagnostic.location().lineRange().toString(), "(27:7,27:303)"); - Diagnostic thirdDiagnostic = iterator.next(); - Assert.assertEquals(thirdDiagnostic.message(), "invalid 'version' under [[tool]]: " + - "'version' should be compatible with semver"); - Assert.assertEquals(thirdDiagnostic.location().lineRange().toString(), "(28:10,28:16)"); + Assert.assertEquals(firstDiagnostic.message(), "Detected corrupted Dependencies.toml file. " + + "Dependencies will be updated to the latest versions."); + Assert.assertEquals(firstDiagnostic.location().lineRange().toString(), "(5:0,28:16)"); } @Test(description = "Invalid Dependencies.toml file with missing org field in tool array") @@ -418,12 +356,12 @@ public void testInvalidDependenciesTomlToolWithoutOrg() throws IOException { DEPENDENCIES_TOML_REPO.resolve("tool-wo-org.toml")); DiagnosticResult diagnostics = depsManifest.diagnostics(); diagnostics.errors().forEach(OUT::println); - Assert.assertTrue(diagnostics.hasErrors()); - Assert.assertEquals(diagnostics.errors().size(), 1); - Iterator iterator = diagnostics.errors().iterator(); + Assert.assertEquals(diagnostics.diagnostics().size(), 1); + Iterator iterator = diagnostics.diagnostics().iterator(); Diagnostic firstDiagnostic = iterator.next(); - Assert.assertEquals(firstDiagnostic.message(), "'org' under [[tool]] is missing"); - Assert.assertEquals(firstDiagnostic.location().lineRange().toString(), "(25:0,28:17)"); + Assert.assertEquals(firstDiagnostic.message(), "Detected corrupted Dependencies.toml file. " + + "Dependencies will be updated to the latest versions."); + Assert.assertEquals(firstDiagnostic.location().lineRange().toString(), "(5:0,28:17)"); } @Test(description = "Invalid Dependencies.toml file with missing org value in tool array") @@ -432,12 +370,12 @@ public void testInvalidDependenciesTomlWithoutToolOrgValue() throws IOException DEPENDENCIES_TOML_REPO.resolve("tool-wo-org-value.toml")); DiagnosticResult diagnostics = depsManifest.diagnostics(); diagnostics.errors().forEach(OUT::println); - Assert.assertTrue(diagnostics.hasErrors()); - Assert.assertEquals(diagnostics.errors().size(), 1); - Iterator iterator = diagnostics.errors().iterator(); + Assert.assertEquals(diagnostics.diagnostics().size(), 1); + Iterator iterator = diagnostics.diagnostics().iterator(); Diagnostic firstDiagnostic = iterator.next(); - Assert.assertEquals(firstDiagnostic.location().lineRange().toString(), "(28:0,28:0)"); - Assert.assertEquals(firstDiagnostic.message(), "missing value"); + Assert.assertEquals(firstDiagnostic.message(), "Detected corrupted Dependencies.toml file. " + + "Dependencies will be updated to the latest versions."); + Assert.assertEquals(firstDiagnostic.location().lineRange().toString(), "(5:0,29:17)"); } private DependencyManifest getDependencyManifest(Path dependenciesTomlPath) throws IOException {