From bb595712947282373170ab222e4dee875e3c483e Mon Sep 17 00:00:00 2001 From: Gayal Dassanayake Date: Fri, 25 Oct 2024 16:02:29 +0530 Subject: [PATCH 1/4] Add dep-manifest modules to the pkg-manifest dep --- .../io/ballerina/projects/internal/BlendedManifest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BlendedManifest.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BlendedManifest.java index 7cb06b7c2dd1..caf395f98a25 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BlendedManifest.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BlendedManifest.java @@ -35,6 +35,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; @@ -133,11 +134,12 @@ public static BlendedManifest from(DependencyManifest dependencyManifest, } } } else { + Collection moduleNames = existingDepOptional.isPresent() ? + existingDepOptional.get().modules : Collections.emptyList(); depContainer.add(depInPkgManifest.org(), depInPkgManifest.name(), new Dependency( depInPkgManifest.org(), depInPkgManifest.name(), depInPkgManifest.version(), DependencyRelation.UNKNOWN, REPOSITORY_NOT_SPECIFIED, - moduleNames(new DependencyManifest.Package(depInPkgManifest.name(), depInPkgManifest.org(), - depInPkgManifest.version())), DependencyOrigin.USER_SPECIFIED)); + moduleNames, DependencyOrigin.USER_SPECIFIED)); continue; } From 820e68b50fc7d5fabb12c64cc96457a65ce01806 Mon Sep 17 00:00:00 2001 From: Gayal Dassanayake Date: Mon, 28 Oct 2024 10:45:03 +0530 Subject: [PATCH 2/4] Add test for hierarchical name deps --- .../projects/test/PackageResolutionTests.java | 24 ++++++++++++++++ .../package_z/Ballerina.toml | 9 ++++++ .../package_z/Dependencies-template.toml | 28 +++++++++++++++++++ .../package_z/main.bal | 4 +++ .../package_zz_1_0_0/Ballerina.toml | 4 +++ .../package_zz_1_0_0/main.bal | 2 ++ .../package_zz_1_0_2/Ballerina.toml | 4 +++ .../package_zz_1_0_2/main.bal | 2 ++ .../src/test/resources/testng.xml | 7 +---- 9 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_z/Ballerina.toml create mode 100644 project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_z/Dependencies-template.toml create mode 100644 project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_z/main.bal create mode 100644 project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_zz_1_0_0/Ballerina.toml create mode 100644 project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_zz_1_0_0/main.bal create mode 100644 project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_zz_1_0_2/Ballerina.toml create mode 100644 project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_zz_1_0_2/main.bal diff --git a/project-api/project-api-test/src/test/java/io/ballerina/projects/test/PackageResolutionTests.java b/project-api/project-api-test/src/test/java/io/ballerina/projects/test/PackageResolutionTests.java index fb91bebbf7c0..9e8dae57b5a1 100644 --- a/project-api/project-api-test/src/test/java/io/ballerina/projects/test/PackageResolutionTests.java +++ b/project-api/project-api-test/src/test/java/io/ballerina/projects/test/PackageResolutionTests.java @@ -117,6 +117,7 @@ public void setup() throws IOException { replaceDependenciesTomlVersion(tempResourceDir.resolve("package_n")); replaceDependenciesTomlVersion(tempResourceDir.resolve("package_p_withDep")); replaceDependenciesTomlVersion(tempResourceDir.resolve("package_p_withoutDep")); + replaceDependenciesTomlVersion(tempResourceDir.resolve("package_z")); } @Test(description = "tests resolution with zero direct dependencies") @@ -880,6 +881,29 @@ public void testDependencyResolutionWithTransitiveDependencyBuiltFromHigherDistV Assert.assertEquals(diagnosticResult.diagnosticCount(), 0, "Unexpected compilation diagnostics"); } + @Test(description = "Resolve dependencies when a dependency has a hierarchical name and is specified in " + + "the Ballerina.toml and the Dependencies.toml of the dependent") + public void testDependencyWithHierrarchicalNameInDepTomlAndBalToml() { + Path projectDirPath = tempResourceDir.resolve("package_z"); + + BCompileUtil.compileAndCacheBala("projects_for_resolution_tests/package_zz_1_0_0"); + BCompileUtil.compileAndCacheBala("projects_for_resolution_tests/package_zz_1_0_2"); + + BuildOptions.BuildOptionsBuilder buildOptionsBuilder = BuildOptions.builder(); + buildOptionsBuilder.setSticky(true); + BuildOptions buildOptions = buildOptionsBuilder.build(); + Project loadProject = TestUtils.loadBuildProject(projectDirPath, buildOptions); + + PackageCompilation compilation = loadProject.currentPackage().getCompilation(); + + DependencyGraph dependencyGraph = compilation.getResolution().dependencyGraph(); + ResolvedPackageDependency packageO = + dependencyGraph.getNodes().stream().filter( + node -> node.packageInstance().manifest().name().toString().equals("foo.bar") + ).findFirst().orElseThrow(); + Assert.assertEquals(packageO.packageInstance().manifest().version().toString(), "1.0.0"); + } + private void replaceDependenciesTomlVersion(Path projectPath) throws IOException { String currentDistrVersion = RepoUtils.getBallerinaShortVersion(); Path dependenciesTomlTemplatePath = projectPath.resolve("Dependencies-template.toml"); diff --git a/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_z/Ballerina.toml b/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_z/Ballerina.toml new file mode 100644 index 000000000000..876a59aced0d --- /dev/null +++ b/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_z/Ballerina.toml @@ -0,0 +1,9 @@ +[package] +org = "samjs" +name = "package_z" +version = "0.1.0" + +[[dependency]] +org = "samjs" +name = "foo.bar" +version = "1.0.0" diff --git a/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_z/Dependencies-template.toml b/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_z/Dependencies-template.toml new file mode 100644 index 000000000000..97a3d7933075 --- /dev/null +++ b/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_z/Dependencies-template.toml @@ -0,0 +1,28 @@ +# 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 = "**INSERT_DISTRIBUTION_VERSION_HERE**" + +[[package]] +org = "samjs" +name = "foo.bar" +version = "1.0.0" +modules = [ + {org = "samjs", packageName = "foo.bar", moduleName = "foo.bar"} +] + +[[package]] +org = "samjs" +name = "package_z" +version = "0.1.0" +dependencies = [ + {org = "samjs", name = "foo.bar"} +] +modules = [ + {org = "samjs", packageName = "package_z", moduleName = "package_z"} +] + diff --git a/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_z/main.bal b/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_z/main.bal new file mode 100644 index 000000000000..69ab50b5833c --- /dev/null +++ b/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_z/main.bal @@ -0,0 +1,4 @@ +import samjs/foo.bar as _; + +public function func_z() { +} diff --git a/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_zz_1_0_0/Ballerina.toml b/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_zz_1_0_0/Ballerina.toml new file mode 100644 index 000000000000..638983bf40e5 --- /dev/null +++ b/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_zz_1_0_0/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "samjs" +name = "foo.bar" +version = "1.0.0" diff --git a/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_zz_1_0_0/main.bal b/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_zz_1_0_0/main.bal new file mode 100644 index 000000000000..e945fa6aef10 --- /dev/null +++ b/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_zz_1_0_0/main.bal @@ -0,0 +1,2 @@ +public function func() { +} diff --git a/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_zz_1_0_2/Ballerina.toml b/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_zz_1_0_2/Ballerina.toml new file mode 100644 index 000000000000..299ae2a724f4 --- /dev/null +++ b/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_zz_1_0_2/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "samjs" +name = "foo.bar" +version = "1.0.2" diff --git a/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_zz_1_0_2/main.bal b/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_zz_1_0_2/main.bal new file mode 100644 index 000000000000..e945fa6aef10 --- /dev/null +++ b/project-api/project-api-test/src/test/resources/projects_for_resolution_tests/package_zz_1_0_2/main.bal @@ -0,0 +1,2 @@ +public function func() { +} diff --git a/project-api/project-api-test/src/test/resources/testng.xml b/project-api/project-api-test/src/test/resources/testng.xml index 0bf8869cb657..291ebf384a0f 100644 --- a/project-api/project-api-test/src/test/resources/testng.xml +++ b/project-api/project-api-test/src/test/resources/testng.xml @@ -20,12 +20,7 @@ under the License. - - - - - - + From 83f8618187acc80cda4724b73c6b7204543cd68e Mon Sep 17 00:00:00 2001 From: Gayal Dassanayake Date: Mon, 28 Oct 2024 12:05:45 +0530 Subject: [PATCH 3/4] Fix broken tests in PackageResolutionTests --- .../projects/test/PackageResolutionTests.java | 56 ++++++++----------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/project-api/project-api-test/src/test/java/io/ballerina/projects/test/PackageResolutionTests.java b/project-api/project-api-test/src/test/java/io/ballerina/projects/test/PackageResolutionTests.java index 9e8dae57b5a1..1e0c559b7382 100644 --- a/project-api/project-api-test/src/test/java/io/ballerina/projects/test/PackageResolutionTests.java +++ b/project-api/project-api-test/src/test/java/io/ballerina/projects/test/PackageResolutionTests.java @@ -98,7 +98,6 @@ * * @since 2.0.0 */ -@Test(groups = "broken") public class PackageResolutionTests extends BaseTest { private static final Path RESOURCE_DIRECTORY = Paths.get( "src/test/resources/projects_for_resolution_tests").toAbsolutePath(); @@ -194,7 +193,6 @@ public void testDependencyGraphWithInvalidBuildFile() { BuildOptions.BuildOptionsBuilder buildOptionsBuilder = BuildOptions.builder(); buildOptionsBuilder.setSticky(false); BuildOptions buildOptions = buildOptionsBuilder.build(); - Project loadProject = TestUtils.loadBuildProject(projectDirPath, buildOptions); PackageCompilation compilation = loadProject.currentPackage().getCompilation(); @@ -366,19 +364,16 @@ public void testClearingEnvironmentCache() throws IOException { "projectB"); FileUtils.deleteDirectory(projectBCachePath.toFile()); - // Step 1 : Build ProjectB1 and Cache CompileResult depCompileResult = BCompileUtil.compileAndCacheBala("projects_for_resolution_tests/projectB1"); if (depCompileResult.getErrorCount() > 0) { Assert.fail("Package B contains compilations error"); } - // Step 2 : Build ProjectA with ProjectB as an import Path projectA = tempResourceDir.resolve("projectA"); Project loadProjectA = TestUtils.loadBuildProject(projectA); - // Step 3 : Get compilation of ProjectA and verify dependencies PackageCompilation compilation = loadProjectA.currentPackage().getCompilation(); DependencyGraph dependencyGraph = compilation.getResolution().dependencyGraph(); @@ -389,7 +384,6 @@ public void testClearingEnvironmentCache() throws IOException { } } - // Step 4 : Modify projectA to be blank // - Step 4.1 : Get the main.bal file document for ProjectA @@ -408,7 +402,6 @@ public void testClearingEnvironmentCache() throws IOException { Document document = defaultModuleProjectA.document(mainDocumentId.get()); document.modify().withContent(newMainProjectAContent).apply(); - // Step 5 : Compile ProjectA and verify dependency compilation = loadProjectA.currentPackage().getCompilation(); dependencyGraph = compilation.getResolution().dependencyGraph(); @@ -419,11 +412,9 @@ public void testClearingEnvironmentCache() throws IOException { } } - // Step 6 : Clear ProjectB cache FileUtils.deleteDirectory(projectBCachePath.toFile()); - // Step 7 : Compile ProjectB2 and cache depCompileResult = BCompileUtil.compileAndCacheBala("projects_for_resolution_tests/projectB2"); if (depCompileResult.getErrorCount() > 0) { @@ -433,7 +424,6 @@ public void testClearingEnvironmentCache() throws IOException { // Step 8 : Clear ProjectB cache FileUtils.deleteDirectory(projectBCachePath.toFile()); - // Step 9 : Modify ProjectA again with the old content // - Step 9.1 : Get the main.bal file document @@ -454,7 +444,6 @@ public void testClearingEnvironmentCache() throws IOException { document = defaultModuleProjectA.document(mainDocumentId.get()); document.modify().withContent(oldMainProjectAContent).apply(); - // Step 10 : Compile ProjectA and verify dependency compilation = loadProjectA.currentPackage().getCompilation(); Assert.assertNotEquals(compilation.diagnosticResult().errorCount(), 0, "Package A has compiled successfully " + @@ -548,7 +537,6 @@ public void testProjectWithTransitiveTestDependencies() throws IOException { Assert.assertEquals(depGraphOfBala.getNodes().size(), 1); } - // TODO: enable after https://github.com/ballerina-platform/ballerina-lang/pull/31972 is merged @Test(description = "Ultimate test case") public void testProjectWithManyDependencies() { BCompileUtil.compileAndCacheBala( @@ -564,12 +552,11 @@ public void testProjectWithManyDependencies() { OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); long initialOpenCount = 0; - if (os instanceof UnixOperatingSystemMXBean) { - UnixOperatingSystemMXBean unixOperatingSystemMXBean = (UnixOperatingSystemMXBean) os; + if (os instanceof UnixOperatingSystemMXBean unixOperatingSystemMXBean) { initialOpenCount = unixOperatingSystemMXBean.getOpenFileDescriptorCount(); } - Project project = BCompileUtil.loadProject( - "projects_for_resolution_tests/ultimate_package_resolution/package_http"); + Project project = TestUtils.loadProject(tempResourceDir + .resolve("ultimate_package_resolution/package_http")); PackageCompilation compilation = project.currentPackage().getCompilation(); JBallerinaBackend jBallerinaBackend = JBallerinaBackend.from(compilation, JvmTarget.JAVA_17); @@ -578,8 +565,7 @@ public void testProjectWithManyDependencies() { diagnosticResult.errors().forEach(OUT::println); Assert.assertEquals(diagnosticResult.diagnosticCount(), 0, "Unexpected compilation diagnostics"); - if (os instanceof UnixOperatingSystemMXBean) { - UnixOperatingSystemMXBean unixOperatingSystemMXBean = (UnixOperatingSystemMXBean) os; + if (os instanceof UnixOperatingSystemMXBean unixOperatingSystemMXBean) { Assert.assertEquals(initialOpenCount, unixOperatingSystemMXBean.getOpenFileDescriptorCount()); } @@ -622,15 +608,18 @@ public void testBalaProjectDependencyResolution() { List nodeInGraph = dependencyGraph.toTopologicallySortedList(); Assert.assertEquals(nodeInGraph.size(), 2); } - // For this to be enabled, #31026 should be fixed. - @Test(enabled = false, dependsOnMethods = "testResolveDependencyFromUnsupportedCustomRepo") - public void testResolveDependencyFromCustomRepo() { + + @Test + public void testResolveDependencyFromCustomRepo() throws IOException { Path projectDirPath = tempResourceDir.resolve("package_b"); - String dependencyContent = "[[dependency]]\n" + - "org = \"samjs\"\n" + - "name = \"package_c\"\n" + - "version = \"0.1.0\"\n" + - "repository = \"local\""; + replaceDistributionVersionOfDependenciesToml(projectDirPath, RepoUtils.getBallerinaShortVersion()); + String dependencyContent = """ + + [[dependency]] + org = "samjs" + name = "package_c" + version = "0.1.0" + repository = "local\""""; // 1) load the build project Environment environment = EnvironmentBuilder.getBuilder().setUserHome(USER_HOME).build(); @@ -638,14 +627,17 @@ public void testResolveDependencyFromCustomRepo() { BuildProject project = TestUtils.loadBuildProject(projectEnvironmentBuilder, projectDirPath); // 2) set local repository to dependency - project.currentPackage().dependenciesToml().orElseThrow().modify().withContent(dependencyContent).apply(); + String currentContent = project.currentPackage().ballerinaToml().get() + .tomlDocument().textDocument().toString(); + String updatedContent = currentContent.concat(dependencyContent); + project.currentPackage().ballerinaToml().orElseThrow().modify().withContent(updatedContent).apply(); // 3) Compile and check the diagnostics PackageCompilation compilation = project.currentPackage().getCompilation(); DiagnosticResult diagnosticResult = compilation.diagnosticResult(); // 4) The dependency is expected to load from distribution cache, hence zero diagnostics - Assert.assertEquals(diagnosticResult.errorCount(), 2); + Assert.assertEquals(diagnosticResult.errorCount(), 0); } // For this to be enabled, #31026 should be fixed. @@ -775,8 +767,8 @@ public void testPackageResolutionOfDependencyInvalidRepository() { // Check whether there are any diagnostics DiagnosticResult diagnosticResult = compilation.diagnosticResult(); diagnosticResult.diagnostics().forEach(OUT::println); - Assert.assertEquals(diagnosticResult.errorCount(), 4, "Unexpected compilation diagnostics"); - Assert.assertEquals(diagnosticResult.warningCount(), 1, "Unexpected compilation diagnostics"); + Assert.assertEquals(diagnosticResult.errorCount(), 3, "Unexpected compilation diagnostics"); + Assert.assertEquals(diagnosticResult.warningCount(), 2, "Unexpected compilation diagnostics"); Iterator diagnosticIterator = diagnosticResult.diagnostics().iterator(); Assert.assertTrue(diagnosticIterator.next().toString().contains( @@ -785,8 +777,8 @@ public void testPackageResolutionOfDependencyInvalidRepository() { // Check dependency cannot be resolved diagnostic Assert.assertEquals( diagnosticIterator.next().toString(), - "ERROR [Ballerina.toml:(21:12,21:21)] invalid 'repository' under [dependency]: 'repository' " + - "can only have the value 'local'"); + "WARNING [Ballerina.toml:(17:1,21:21)] Provided custom repository (invalid) cannot be found in the " + + "Settings.toml. "); Assert.assertEquals(diagnosticIterator.next().toString(), "ERROR [fee.bal:(1:1,1:16)] cannot resolve module 'ccc/ddd'"); Assert.assertEquals(diagnosticIterator.next().toString(), From 87e328a10456d60eebfbebfa4499081f2ac7c7e2 Mon Sep 17 00:00:00 2001 From: Gayal Dassanayake Date: Fri, 1 Nov 2024 20:30:51 +0530 Subject: [PATCH 4/4] Add resolution dot graph test --- .../packages/ExistingProjectTests.java | 8 ++++++-- .../PackageResolutionTestCaseBuilder.java | 3 ++- .../resolution/packages/internal/Utils.java | 18 ++++++++++++++++++ .../case-0016/Ballerina_toml.dot | 3 +++ .../case-0016/Dependencies_toml.dot | 5 +++++ .../suite-existing_project/case-0016/app.dot | 3 +++ .../case-0016/case-description.md | 13 +++++++++++++ .../case-0016/expected-graph-nosticky.dot | 3 +++ .../case-0016/expected-graph-sticky.dot | 3 +++ .../repositories/central.dot | 6 ++++++ 10 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/Ballerina_toml.dot create mode 100644 compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/Dependencies_toml.dot create mode 100644 compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/app.dot create mode 100644 compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/case-description.md create mode 100644 compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/expected-graph-nosticky.dot create mode 100644 compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/expected-graph-sticky.dot diff --git a/compiler/ballerina-lang/src/test/java/io/ballerina/projects/test/resolution/packages/ExistingProjectTests.java b/compiler/ballerina-lang/src/test/java/io/ballerina/projects/test/resolution/packages/ExistingProjectTests.java index fb783a4fbf14..73af87fe78c2 100644 --- a/compiler/ballerina-lang/src/test/java/io/ballerina/projects/test/resolution/packages/ExistingProjectTests.java +++ b/compiler/ballerina-lang/src/test/java/io/ballerina/projects/test/resolution/packages/ExistingProjectTests.java @@ -60,9 +60,13 @@ public static Object[][] testCaseProvider() { // 14. package contains 2 dependencies one of which is in Ballerina toml file thats not local {"suite-existing_project", "case-0014", true}, {"suite-existing_project", "case-0014", false}, - // 15. package updates transitive dependency from the Ballerian toml file that is not local + // 15. package updates transitive dependency from the Ballerina toml file that is not local {"suite-existing_project", "case-0015", true}, - {"suite-existing_project", "case-0015", false} + {"suite-existing_project", "case-0015", false}, + // 16. package name is hierarchical, there are new versions in the central, + // and the older version is specified in Ballerina.toml and Dependencies.toml + {"suite-existing_project", "case-0016", true}, + {"suite-existing_project", "case-0016", false} }; } } diff --git a/compiler/ballerina-lang/src/test/java/io/ballerina/projects/test/resolution/packages/internal/PackageResolutionTestCaseBuilder.java b/compiler/ballerina-lang/src/test/java/io/ballerina/projects/test/resolution/packages/internal/PackageResolutionTestCaseBuilder.java index 90ce85a624ec..ca2f3471db1b 100644 --- a/compiler/ballerina-lang/src/test/java/io/ballerina/projects/test/resolution/packages/internal/PackageResolutionTestCaseBuilder.java +++ b/compiler/ballerina-lang/src/test/java/io/ballerina/projects/test/resolution/packages/internal/PackageResolutionTestCaseBuilder.java @@ -157,8 +157,9 @@ private static DependencyManifest getDependencyManifest(Path dependenciesTomlPat } PackageDescriptor pkgDesc = Utils.getPkgDescFromNode(node.name().value(), null); + List modules = Utils.getDependencyModules(pkgDesc, attrs.get("modules")); recordedDeps.add(new DependencyManifest.Package(pkgDesc.name(), pkgDesc.org(), pkgDesc.version(), - scope.getValue(), isTransitive, Collections.emptyList(), Collections.emptyList())); + scope.getValue(), isTransitive, Collections.emptyList(), modules)); } return DependencyManifest.from("2.0.0", null, recordedDeps); } diff --git a/compiler/ballerina-lang/src/test/java/io/ballerina/projects/test/resolution/packages/internal/Utils.java b/compiler/ballerina-lang/src/test/java/io/ballerina/projects/test/resolution/packages/internal/Utils.java index 35f450c2acda..ab14b5d375da 100644 --- a/compiler/ballerina-lang/src/test/java/io/ballerina/projects/test/resolution/packages/internal/Utils.java +++ b/compiler/ballerina-lang/src/test/java/io/ballerina/projects/test/resolution/packages/internal/Utils.java @@ -17,6 +17,7 @@ */ package io.ballerina.projects.test.resolution.packages.internal; +import io.ballerina.projects.DependencyManifest; import io.ballerina.projects.DependencyResolutionType; import io.ballerina.projects.ModuleName; import io.ballerina.projects.PackageDependencyScope; @@ -26,6 +27,10 @@ import io.ballerina.projects.PackageVersion; import io.ballerina.projects.environment.ModuleLoadRequest; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + /** * Contains utility methods used throughout the test framework. * @@ -48,6 +53,19 @@ public static PackageDependencyScope getDependencyScope(Object scopeValue) { } } + public static List getDependencyModules(PackageDescriptor pkgDesc, Object modulesValue) { + if (modulesValue == null) { + return Collections.emptyList(); + } + List modules = new ArrayList<>(); + String modulesStr = modulesValue.toString(); + String[] moduleNames = modulesStr.split(","); + for (String moduleName : moduleNames) { + modules.add(new DependencyManifest.Module(pkgDesc.org().value(), pkgDesc.name().value(), moduleName)); + } + return modules; + } + public static ModuleLoadRequest getModuleLoadRequest(String name, PackageDependencyScope scope, DependencyResolutionType resolutionType) { diff --git a/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/Ballerina_toml.dot b/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/Ballerina_toml.dot new file mode 100644 index 000000000000..35c34b6f3d93 --- /dev/null +++ b/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/Ballerina_toml.dot @@ -0,0 +1,3 @@ +digraph "BallerinaToml" { + "samjs/qux.foo:1.0.2" +} diff --git a/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/Dependencies_toml.dot b/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/Dependencies_toml.dot new file mode 100644 index 000000000000..726836dee7ad --- /dev/null +++ b/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/Dependencies_toml.dot @@ -0,0 +1,5 @@ +digraph "example1" { + "samejs/app:0.1.0" -> "samjs/qux.foo:1.0.2" + + "samjs/qux.foo:1.0.2" [modules = "qux.foo"] +} diff --git a/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/app.dot b/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/app.dot new file mode 100644 index 000000000000..0d86bd4fb272 --- /dev/null +++ b/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/app.dot @@ -0,0 +1,3 @@ +digraph "samejs/app:0.1.0" { + "samjs/qux.foo" +} diff --git a/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/case-description.md b/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/case-description.md new file mode 100644 index 000000000000..ee172831ff94 --- /dev/null +++ b/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/case-description.md @@ -0,0 +1,13 @@ +# Package name is hierarchical, there are new versions in the central, and the older version is specified in Ballerina.toml and Dependencies.toml + +1. User's package has `samjs/qux.foo:1.0.2` as a dependency in Dependencies.toml. +2. A newer version `samjs/qux.foo:1.0.5` has been released to central. +3. User specifies `samjs/qux.foo:1.0.2` in Ballerina.toml +4. User now builds the package + +## Expected behavior + +### Sticky == true +No changes to Dependency graph +### Sticky == false +Dependency graph should be updated to have `samjs/qux.foo:1.0.5` diff --git a/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/expected-graph-nosticky.dot b/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/expected-graph-nosticky.dot new file mode 100644 index 000000000000..942fdc3f93d5 --- /dev/null +++ b/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/expected-graph-nosticky.dot @@ -0,0 +1,3 @@ +digraph "example1" { + "samejs/app:0.1.0" -> "samjs/qux.foo:1.0.5" +} diff --git a/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/expected-graph-sticky.dot b/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/expected-graph-sticky.dot new file mode 100644 index 000000000000..496cdc7f2cd2 --- /dev/null +++ b/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/case-0016/expected-graph-sticky.dot @@ -0,0 +1,3 @@ +digraph "example1" { + "samejs/app:0.1.0" -> "samjs/qux.foo:1.0.2" +} diff --git a/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/repositories/central.dot b/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/repositories/central.dot index d33827186532..d3694bd8577f 100644 --- a/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/repositories/central.dot +++ b/compiler/ballerina-lang/src/test/resources/package-resolution/suite-existing_project/repositories/central.dot @@ -102,5 +102,11 @@ digraph central { subgraph "ballerina/http:1.4.0" { "ballerina/http:1.4.0" -> "ballerina/io:1.0.2" } + + subgraph "samjs/qux.foo:1.0.2" { + } + + subgraph "samjs/qux.foo:1.0.5" { + } }