Exemplo n.º 1
0
        public void Exec(SubCommandRunningContext context)
        {
            string intermediateFolder = _options.IntermediateFolder;
            string versionName        = _options.VersionName ?? string.Empty;
            var    outputFile         = string.IsNullOrEmpty(_options.DependencyFile) ? Path.Combine(Directory.GetCurrentDirectory(), "dep.json") : _options.DependencyFile;

            var dependency = Load(intermediateFolder, versionName);

            Logger.LogInfo("Exporting dependency file...");
            try
            {
                var expandedDependency = dependency == null ?
                                         ExpandedDependencyMap.Empty :
                                         ExpandedDependencyMap.ConstructFromDependencyGraph(dependency);
                using (var fs = File.Create(outputFile))
                {
                    using var writer = new StreamWriter(fs);
                    expandedDependency.Save(writer);
                }

                Logger.LogInfo($"Dependency file exported at path: {outputFile}.");
            }
            catch (Exception ex)
            {
                LogErrorAndThrow($"Unable to export dependency file: {ex.Message}", ex);
            }
        }
Exemplo n.º 2
0
        public void Exec(SubCommandRunningContext context)
        {
            string intermediateFolder = _options.IntermediateFolder;
            string versionName        = _options.VersionName ?? string.Empty;
            var    dependencyFile     = string.IsNullOrEmpty(_options.DependencyFile) ? Path.Combine(Directory.GetCurrentDirectory(), "dep.json") : _options.DependencyFile;
            var    buildInfo          = BuildInfo.Load(intermediateFolder);

            if (buildInfo == null)
            {
                LogErrorAndThrow($"Cache files in the folder {intermediateFolder} are corrupted!", null);
            }
            var dg = buildInfo.Versions.FirstOrDefault(v => v.VersionName == versionName)?.Dependency;

            if (dg == null)
            {
                Logger.LogInfo($"Cache files for version {versionName} is not found!", null);
            }
            Logger.LogInfo($"Exporting dependency file...");
            try
            {
                var edg = dg == null ? ExpandedDependencyMap.Empty : ExpandedDependencyMap.ConstructFromDependencyGraph(dg);
                using (var fs = File.Create(dependencyFile))
                    using (var writer = new StreamWriter(fs))
                    {
                        edg.Save(writer);
                    }
                Logger.LogInfo($"Dependency file exported at path: {dependencyFile}.");
            }
            catch (Exception ex)
            {
                LogErrorAndThrow($"Unable to export dependency file: {ex.Message}", ex);
            }
        }
Exemplo n.º 3
0
        public void BasicTest()
        {
            // A.md -> B.md include
            // B.md -> C.md file
            // B.md -> C.md bookmark
            // D.md -> B.md file
            var dg = new DependencyGraph();

            dg.ReportDependency(new[] {
                new DependencyItem("~/A.md", "~/B.md", "~/A.md", DependencyTypeName.Include),
                new DependencyItem("~/B.md", "~/C.md", "~/B.md", DependencyTypeName.File),
                new DependencyItem("~/B.md", "~/C.md", "~/B.md", DependencyTypeName.Bookmark),
                new DependencyItem("~/D.md", "~/B.md", "~/D.md", DependencyTypeName.File),
            });
            var edg = ExpandedDependencyMap.ConstructFromDependencyGraph(dg);

            Assert.Equal(
                new[]
            {
                new ExpandedDependencyItem("~/A.md", "~/B.md", DependencyTypeName.Include),
                new ExpandedDependencyItem("~/A.md", "~/C.md", DependencyTypeName.Bookmark),
                new ExpandedDependencyItem("~/A.md", "~/C.md", DependencyTypeName.File),
            },
                edg.GetDependencyFrom("~/A.md").OrderBy(i => i.ToString()));
            Assert.Equal(
                new[]
            {
                new ExpandedDependencyItem("~/B.md", "~/C.md", DependencyTypeName.Bookmark),
                new ExpandedDependencyItem("~/B.md", "~/C.md", DependencyTypeName.File),
            },
                edg.GetDependencyFrom("~/B.md").OrderBy(i => i.ToString()));
            Assert.Equal(
                Enumerable.Empty <ExpandedDependencyItem>(),
                edg.GetDependencyFrom("~/C.md").OrderBy(i => i.ToString()));
            Assert.Equal(
                new[]
            {
                new ExpandedDependencyItem("~/D.md", "~/B.md", DependencyTypeName.File),
            },
                edg.GetDependencyFrom("~/D.md").OrderBy(i => i.ToString()));
            Assert.Equal(
                Enumerable.Empty <ExpandedDependencyItem>(),
                edg.GetDependencyTo("~/A.md").OrderBy(i => i.ToString()));
            Assert.Equal(
                new[]
            {
                new ExpandedDependencyItem("~/A.md", "~/B.md", DependencyTypeName.Include),
                new ExpandedDependencyItem("~/D.md", "~/B.md", DependencyTypeName.File),
            },
                edg.GetDependencyTo("~/B.md").OrderBy(i => i.ToString()));
            Assert.Equal(
                new[]
            {
                new ExpandedDependencyItem("~/A.md", "~/C.md", DependencyTypeName.Bookmark),
                new ExpandedDependencyItem("~/A.md", "~/C.md", DependencyTypeName.File),
                new ExpandedDependencyItem("~/B.md", "~/C.md", DependencyTypeName.Bookmark),
                new ExpandedDependencyItem("~/B.md", "~/C.md", DependencyTypeName.File),
            },
                edg.GetDependencyTo("~/C.md").OrderBy(i => i.ToString()));
            Assert.Equal(
                Enumerable.Empty <ExpandedDependencyItem>(),
                edg.GetDependencyTo("~/D.md").OrderBy(i => i.ToString()));
        }