public async Task GivenTwoManifestWithSameDependency_WhenChainCalculated_ThenOneDependency()
        {
            var dependencyManifest = CreateTestManifest("dependency-a", 1, 0, 0);

            var manifestLoader = CreateMockManifestLoader(dependencyManifest);

            var installManifestA = CreateTestManifest("to-install-a", 1, 0, 0, dependencyManifest);
            var installManifestB = CreateTestManifest("to-install-b", 1, 0, 0, dependencyManifest);

            var dependencyChain = new DependencyChain();
            await dependencyChain.AddDependenciesFromManifest(manifestLoader, installManifestA);

            await dependencyChain.AddDependenciesFromManifest(manifestLoader, installManifestB);

            dependencyChain.NeededDependencies.Count.ShouldBe(1);
        }
        public async Task GivenSecondManifestWithCompatibleDependencyLoaded_WhenChainCalculated_ThenOneDependency()
        {
            var dependencyManifest1 = CreateTestManifest("dependency-a", 1, 0, 0);
            var dependencyManifest2 = CreateTestManifest("dependency-a", 1, 2, 0);

            var manifestLoader = CreateMockManifestLoader(dependencyManifest1, dependencyManifest2);

            var installManifestA = CreateTestManifest("to-install-a", 1, 0, 0, dependencyManifest1);
            var installManifestB = CreateTestManifest("to-install-b", 1, 0, 0, dependencyManifest2);

            var dependencyChain = new DependencyChain();
            await dependencyChain.AddDependenciesFromManifest(manifestLoader, installManifestB);

            await dependencyChain.AddDependenciesFromManifest(manifestLoader, installManifestA);

            dependencyChain.NeededDependencies.Count.ShouldBe(1);
            dependencyChain.NeededDependencies.First().Version.ShouldBe(dependencyManifest2.SemanticVersion);
        }
Пример #3
0
        private static async Task <int> Execute(CommandArgument url, CommandOption dataFolder)
        {
            try
            {
                if (string.IsNullOrEmpty(url.Value))
                {
                    Console.WriteLine("Please specify a module url to install from");
                    return(1);
                }

                FoundryDataFolder foundryDataFolder;
                if (dataFolder.HasValue())
                {
                    foundryDataFolder = FoundryDataFolder.FromDirectoryPath(dataFolder.Value());
                }
                else
                {
                    foundryDataFolder = FoundryDataFolder.FromCurrentDirectory();
                }

                if (foundryDataFolder == null)
                {
                    return(1);
                }

                var manifestLoader = new ManifestLoader();
                await foundryDataFolder.ReadAllManifests(manifestLoader);

                var manifest = await manifestLoader.FromUri(new Uri(url.Value));

                if (manifest == null)
                {
                    return(1);
                }

                var dependencyChain = new DependencyChain();
                dependencyChain.AddCurrentlyInstalledDependencies(manifestLoader, foundryDataFolder);
                await dependencyChain.AddDependenciesFromManifest(manifestLoader, manifest);

                foreach (var dependency in dependencyChain.NeededDependencies)
                {
                    Console.WriteLine();
                    var dependencyManifest = await dependency.GetFullManifest(manifestLoader);

                    await dependencyManifest.Install(foundryDataFolder);
                }

                Console.WriteLine();
                return(await manifest.Install(foundryDataFolder));
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
                return(1);
            }
        }
        public async Task GivenAlreadyInstalledDependency_WhenChainCalculated_ThenOneDependency()
        {
            var dependencyManifest1 = CreateTestManifest("dependency-a", 1, 2, 0);
            var dependencyManifest2 = CreateTestManifest("dependency-a", 1, 0, 0);

            var manifestLoader = CreateMockManifestLoader(dependencyManifest1, dependencyManifest2);

            var alreadyInstalledManifest = CreateTestManifest("installed", 1, 0, 0, dependencyManifest1);
            var installManifest          = CreateTestManifest("to-install", 1, 0, 0, dependencyManifest2);

            var dependencyChain = new DependencyChain();

            await dependencyChain.AddDependenciesFromManifest(manifestLoader, alreadyInstalledManifest);

            await dependencyChain.AddDependenciesFromManifest(manifestLoader, installManifest);

            dependencyChain.NeededDependencies.Count.ShouldBe(1);
            dependencyChain.NeededDependencies.First().Version.ShouldBe(dependencyManifest1.GetSemanticVersion());
        }
        public async Task GivenManifestsWithSharedDownstreamDependency_WhenChainCalculated_ThenSharedLoadedOnce()
        {
            var dependencyManifest1 = CreateTestManifest("dependency-a", 1, 0, 0);
            var dependencyManifest2 = CreateTestManifest("dependency-b", 1, 0, 0);
            var dependencyManifest3 = CreateTestManifest("dependency-c", 1, 0, 0, dependencyManifest1);

            var manifestLoader = CreateMockManifestLoader(dependencyManifest1, dependencyManifest2, dependencyManifest3);

            var installManifestA = CreateTestManifest("to-install-a", 1, 0, 0, dependencyManifest1);
            var installManifestB = CreateTestManifest("to-install-b", 1, 0, 0, dependencyManifest2, dependencyManifest3);

            var dependencyChain = new DependencyChain();
            await dependencyChain.AddDependenciesFromManifest(manifestLoader, installManifestA);

            await dependencyChain.AddDependenciesFromManifest(manifestLoader, installManifestB);

            dependencyChain.NeededDependencies.Count.ShouldBe(3);
            dependencyChain.NeededDependencies.First().Version.ShouldBe(dependencyManifest2.SemanticVersion);
        }
        public async Task GivenTwoManifestWithIncompatibleDependency_WhenChainCalculated_ThenIncompatible()
        {
            var dependencyManifest1 = CreateTestManifest("dependency-a", 1, 0, 0);
            var dependencyManifest2 = CreateTestManifest("dependency-a", 2, 0, 0);

            var manifestLoader = CreateMockManifestLoader(dependencyManifest1, dependencyManifest2);

            var installManifestA = CreateTestManifest("to-install-a", 1, 0, 0, dependencyManifest1);
            var installManifestB = CreateTestManifest("to-install-b", 1, 0, 0, dependencyManifest2);

            var dependencyChain = new DependencyChain();
            await dependencyChain.AddDependenciesFromManifest(manifestLoader, installManifestA);

            var exception = await Should.ThrowAsync <Exception>(async() =>
            {
                await dependencyChain.AddDependenciesFromManifest(manifestLoader, installManifestB);
            });

            exception.Message.ShouldBe("Incompatible dependency chain");
        }
        public async Task GivenCircularDependency_WhenChainCalculated_ThenResolved()
        {
            var dependencyManifest1 = CreateTestManifest("dependency-a", 1, 0, 0);
            var dependencyManifest2 = CreateTestManifest("dependency-b", 1, 0, 0, dependencyManifest1);
            var dependencyManifest3 = CreateTestManifest("dependency-c", 1, 0, 0, dependencyManifest2);

            dependencyManifest1.Dependencies = new List <Dependency> {
                dependencyManifest3.ToDependency()
            };

            var manifestLoader = CreateMockManifestLoader(dependencyManifest1, dependencyManifest2, dependencyManifest3);

            var installManifestA = CreateTestManifest("to-install-a", 1, 0, 0, dependencyManifest3);

            var dependencyChain = new DependencyChain();
            await dependencyChain.AddDependenciesFromManifest(manifestLoader, installManifestA);

            dependencyChain.NeededDependencies.Count.ShouldBe(3);
            dependencyChain.NeededDependencies.First().Version.ShouldBe(dependencyManifest2.SemanticVersion);
        }
Пример #8
0
        private static async Task <int> Execute(CommandOption dataFolder)
        {
            try
            {
                FoundryDataFolder foundryDataFolder;
                if (dataFolder.HasValue())
                {
                    foundryDataFolder = FoundryDataFolder.FromDirectoryPath(dataFolder.Value());
                }
                else
                {
                    foundryDataFolder = FoundryDataFolder.FromCurrentDirectory();
                }

                if (foundryDataFolder == null)
                {
                    return(1);
                }

                var manifestLoader    = new ManifestLoader();
                var manifestsToUpdate = new List <Manifest>();

                foreach (var manifest in await foundryDataFolder.ReadAllManifests(manifestLoader))
                {
                    Console.WriteLine();
                    Console.WriteLine($"Checking {manifest.Name} for updates");
                    var latestManifest = await GetLatestManifest(manifestLoader, manifest);

                    if (latestManifest == null)
                    {
                        continue;
                    }

                    if (latestManifest.GetSemanticVersion() > manifest.GetSemanticVersion())
                    {
                        Console.WriteLine($"Queuing update for {latestManifest.Name} from {manifest.GetSemanticVersion().ToNormalizedString()} to {latestManifest.GetSemanticVersion().ToNormalizedString()}");
                        manifestsToUpdate.Add(latestManifest);
                    }
                }

                var dependencyChain = new DependencyChain();
                dependencyChain.AddCurrentlyInstalledDependencies(manifestLoader, foundryDataFolder);

                foreach (var toUpdate in manifestsToUpdate)
                {
                    await dependencyChain.AddDependenciesFromManifest(manifestLoader, toUpdate);
                }

                foreach (var dependency in dependencyChain.NeededDependencies)
                {
                    Console.WriteLine();
                    var dependencyManifest = await dependency.GetFullManifest(manifestLoader);

                    await dependencyManifest.Install(foundryDataFolder);
                }

                foreach (var toUpdate in manifestsToUpdate)
                {
                    Console.WriteLine();
                    await toUpdate.Install(foundryDataFolder);
                }

                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(1);
            }
        }