예제 #1
0
        public static int AddModule(Package package, string moduleName, string pushUrl, string fetchUrl)
        {
            if (fetchUrl.StartsWith("https://git.skbkontur.ru/"))
            {
                throw new CementException("HTTPS url not allowed for gitlab. You should use SSH url.");
            }
            using (var tempDir = new TempDirectory())
            {
                var repo = new GitRepository("modules_git", tempDir.Path, Log);
                repo.Clone(package.Url);
                if (FindModule(repo, moduleName) != null)
                {
                    ConsoleWriter.Shared.WriteError("Module " + moduleName + " already exists in " + package.Name);
                    return(-1);
                }

                WriteModuleDescription(moduleName, pushUrl, fetchUrl, repo);

                var message = "(!)cement comment: added module '" + moduleName + "'";
                repo.Commit(new[] { "-am", message });
                repo.Push("master");
            }

            ConsoleWriter.Shared.WriteOk($"Successfully added {moduleName} to {package.Name} package.");

            PackageUpdater.UpdatePackages();

            return(0);
        }
예제 #2
0
        protected override int Execute()
        {
            var cwd = Directory.GetCurrentDirectory();

            configuration = string.IsNullOrEmpty(configuration) ? "full-build" : configuration;

            Log.Info("Updating packages");
            PackageUpdater.UpdatePackages();
            var modules = Helper.GetModules();

            var moduleName = Path.GetFileName(cwd);

            var curRepo = new GitRepository(moduleName, Helper.CurrentWorkspace, Log);

            if (curRepo.IsGitRepo)
            {
                curRepo.TryUpdateUrl(modules.FirstOrDefault(m => m.Name.Equals(moduleName)));
            }
            HooksHelper.InstallHooks(moduleName);

            var getter = new ModuleGetter(
                Helper.GetModules(),
                new Dep(moduleName, null, configuration),
                policy,
                mergedBranch,
                verbose,
                localBranchForce);

            getter.GetDeps();


            Log.Info("SUCCESS UPDATE DEPS");
            return(0);
        }
예제 #3
0
        protected override int Execute()
        {
            Log.Info("Updating packages");
            PackageUpdater.UpdatePackages();
            var cwd    = Directory.GetCurrentDirectory();
            var module = Path.GetFileName(cwd);

            var curRepo = new GitRepository(module, Helper.CurrentWorkspace, Log);

            if (treeish == null)
            {
                treeish = curRepo.CurrentLocalTreeish().Value;
            }

            var getter = new ModuleGetter(
                Helper.GetModules(),
                new Dep(module, treeish),
                policy,
                null,
                verbose);

            getter.GetModule();

            return(0);
        }
예제 #4
0
        public async Task WhenThereAreUpdates_CountIsAsExpected(
            int numberOfUpdates,
            int existingCommitsPerBranch,
            bool consolidateUpdates,
            bool pullRequestExists,
            int expectedUpdates,
            int expectedPrs
            )
        {
            var updateSelection      = Substitute.For <IPackageUpdateSelection>();
            var collaborationFactory = Substitute.For <ICollaborationFactory>();
            var gitDriver            = Substitute.For <IGitDriver>();
            var existingCommitFilder = Substitute.For <IExistingCommitFilter>();

            UpdateSelectionAll(updateSelection);

            gitDriver.GetCurrentHead().Returns("def");
            gitDriver.CheckoutNewBranch(Arg.Any <string>()).Returns(true);

            collaborationFactory
            .CollaborationPlatform
            .PullRequestExists(Arg.Any <ForkData>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(pullRequestExists);

            var packageUpdater = new PackageUpdater(collaborationFactory,
                                                    existingCommitFilder,
                                                    Substitute.For <IUpdateRunner>(),
                                                    Substitute.For <INuKeeperLogger>());

            var updates = Enumerable.Range(1, numberOfUpdates)
                          .Select(_ => PackageUpdates.UpdateSet())
                          .ToList();

            var filteredUpdates = updates.Skip(existingCommitsPerBranch).ToList().AsReadOnly();

            existingCommitFilder.Filter(Arg.Any <IGitDriver>(), Arg.Any <IReadOnlyCollection <PackageUpdateSet> >(), Arg.Any <string>(), Arg.Any <string>()).Returns(filteredUpdates);

            var settings = MakeSettings(consolidateUpdates);

            var(repoUpdater, _) = MakeRepositoryUpdater(
                updateSelection, updates, packageUpdater);

            var repo = MakeRepositoryData();

            var count = await repoUpdater.Run(gitDriver, repo, settings);

            Assert.That(count, Is.EqualTo(expectedUpdates), "Returned count of updates");

            await collaborationFactory.CollaborationPlatform.Received(expectedPrs)
            .OpenPullRequest(
                Arg.Any <ForkData>(),
                Arg.Any <PullRequestRequest>(),
                Arg.Any <IEnumerable <string> >());

            await gitDriver.Received(expectedUpdates).Commit(Arg.Any <string>());
        }
예제 #5
0
        public void PackageConfigTestLine()
        {
            var packageUpdater = new PackageUpdater(new FileInterface());

            string line = @"<package id=""NLog"" version=""4.5.3"" targetFramework=""net461"" />";

            string result = packageUpdater.ProcessLine(line, "NLog", "9.9.9");

            result.Should().Be(@"<package id=""NLog"" version=""9.9.9"" targetFramework=""net461"" />");
        }
예제 #6
0
        public void PackageConfigTestLine_MissingVersion()
        {
            var packageUpdater = new PackageUpdater(new FileInterface());

            string line = @"<package id=""NLog"" targetFramework=""net461"" />";

            Action act = () => { packageUpdater.ProcessLine(line, "NLog", "9.9.9"); };

            act.Should().Throw <Exception>()
            .WithMessage("versionEquals not found");
        }
예제 #7
0
        public void UpdateSDKTest()
        {
            string test     = @"<?xml version=""1.0"" encoding=""utf - 8""?>
                            <Project Sdk = ""Microsoft.NET.Sdk""> 
                            </Project>";
            string expected = @"<?xml version=""1.0"" encoding=""utf - 8""?>
                            <Project Sdk = ""Microsoft.NET.Sdk.Web""> 
                            </Project>";
            var    result   = new PackageUpdater(XDocument.Parse(test), _logger).UpdateSDK();

            Assert.True(XNode.DeepEquals(XDocument.Parse(expected), result));
        }
예제 #8
0
        protected override int Execute()
        {
            var currentModuleDirectory = Helper.GetModuleDirectory(Directory.GetCurrentDirectory());
            var currentModule          = Path.GetFileName(currentModuleDirectory);

            PackageUpdater.UpdatePackages();
            project = Yaml.GetProjectFileName(project, currentModule);

            var moduleToInsert = Helper.TryFixModuleCase(dep.Name);

            dep = new Dep(moduleToInsert, dep.Treeish, dep.Configuration);
            var configuration = dep.Configuration;

            if (!Helper.HasModule(moduleToInsert))
            {
                ConsoleWriter.WriteError($"Can't find module '{moduleToInsert}'");
                return(-1);
            }

            if (!Directory.Exists(Path.Combine(Helper.CurrentWorkspace, moduleToInsert)))
            {
                GetAndBuild(dep);
            }

            Log.Debug(
                $"{moduleToInsert + (configuration == null ? "" : Helper.ConfigurationDelimiter + configuration)} -> {project}");

            CheckBranch();

            Log.Info("Getting install data for " + moduleToInsert + Helper.ConfigurationDelimiter + configuration);
            var installData = InstallParser.Get(moduleToInsert, configuration);

            if (!installData.BuildFiles.Any())
            {
                ConsoleWriter.WriteWarning($"No install files found in '{moduleToInsert}'");
                return(0);
            }

            AddModuleToCsproj(installData);
            if (testReplaces)
            {
                return(hasReplaces ? -1 : 0);
            }

            if (!File.Exists(Path.Combine(currentModuleDirectory, Helper.YamlSpecFile)))
            {
                throw new CementException(
                          "No module.yaml file. You should patch deps file manually or convert old spec to module.yaml (cm convert-spec)");
            }
            DepsPatcherProject.PatchDepsForProject(currentModuleDirectory, dep, project);
            return(0);
        }
예제 #9
0
        private static Package GetPackage(string packageName)
        {
            PackageUpdater.UpdatePackages();
            var packages = Helper.GetPackages();

            var package = packageName == null
                ? packages.FirstOrDefault(p => p.Type == "git")
                : packages.FirstOrDefault(p => p.Name == packageName);

            if (package == null)
            {
                throw new CementException("Unable to find " + packageName + " in package list");
            }
            return(package);
        }
예제 #10
0
        public void UpdatePackagesTest(string input)
        {
            string expected = @"<?xml version=""1.0"" encoding=""utf - 8""?>
                            <Project Sdk = ""Microsoft.NET.Sdk.Web"">
                              <ItemGroup>
                                <PackageReference Include = ""Microsoft.CSharp"" Version = ""4.7.0"" />
                                <PackageReference Include = ""Serilog"" Version = ""2.8.0"" />
                                <PackageReference Include = ""CoreWCF.NetTcp"" Version = ""1.1.0"" />
                                <PackageReference Include = ""CoreWCF.Primitives"" Version = ""1.1.0"" />
                                <PackageReference Include = ""CoreWCF.ConfigurationManager"" Version = ""1.1.0"" />
                                <PackageReference Include = ""CoreWCF.Http"" Version = ""1.1.0"" />
                                <PackageReference Include = ""CoreWCF.WebHttp"" Version = ""1.1.0"" />
                              </ItemGroup>
                            </Project>";
            var    result   = new PackageUpdater(XDocument.Parse(input), _logger).UpdatePackages();

            Assert.True(XNode.DeepEquals(XDocument.Parse(expected), result));
        }
 private static void CheckUpdateQueue()
 {
     if (_currentUpdater == null || _currentUpdater.Done)
     {
         if (_packageUpdateQueue.Count == 0)
         {
             _currentUpdater = null;
             _updateHooked   = false;
             // ReSharper disable once DelegateSubtraction
             EditorApplication.update -= CheckUpdateQueue;
             UnityEngine.Debug.Log($"<color=#FF0><b>[LPM Utils]</b></color> All done!");
         }
         else
         {
             _currentUpdater = _packageUpdateQueue.Dequeue();
             _currentUpdater.Update();
         }
     }
 }
예제 #12
0
        public int Run(string[] args)
        {
            ParseArgs(args);

            if (simple)
            {
                PrintSimpleLocalWithYaml();
                return(0);
            }

            PackageUpdater.UpdatePackages();
            var packages = Helper.GetPackages();

            foreach (var package in packages)
            {
                PrintPackage(package);
            }
            ConsoleWriter.Shared.ClearLine();
            return(0);
        }
예제 #13
0
        protected override int Execute()
        {
            var workspace = Directory.GetCurrentDirectory();

            if (!Helper.IsCurrentDirectoryModule(Path.Combine(workspace, module)))
            {
                throw new CementTrackException($"{workspace} is not cement workspace directory.");
            }

            configuration = string.IsNullOrEmpty(configuration) ? "full-build" : configuration;

            Log.LogInformation("Updating packages");
            PackageUpdater.UpdatePackages();

            GetModule();
            cycleDetector.WarnIfCycle(module, configuration, Log);

            Log.LogInformation("SUCCESS get " + module);
            return(0);
        }
예제 #14
0
        private static Package GetPackage(string packageName)
        {
            PackageUpdater.UpdatePackages();
            var packages = Helper.GetPackages();

            if (packages.Count > 1 && packageName == null)
            {
                throw new CementException($"Specify --package={string.Join("|", packages.Select(p => p.Name))}");
            }

            var package = packageName == null
                ? packages.FirstOrDefault(p => p.Type == "git")
                : packages.FirstOrDefault(p => p.Name == packageName);

            if (package == null)
            {
                throw new CementException("Unable to find " + packageName + " in package list");
            }
            return(package);
        }
예제 #15
0
        public void PackageConfigProcessFile_MakeSurCompletePackageNameIsMatched()
        {
            string contents = @"<?xml version=""1.0"" encoding=""utf-8""?>
           <packages>
             <package id =""NLog.Config"" version=""4.5.3"" targetFramework=""net461"" />
           </packages>";

            List <string> lines = contents.Split(new[] { Environment.NewLine }, StringSplitOptions.None).ToList();

            var packageUpdater = new PackageUpdater(new FileInterface());

            List <string> result = packageUpdater.ProcessFileContents(lines, "NLog", "9.9.9");

            string joined = string.Join(Environment.NewLine, result.ToArray());

            joined.Should().Be(@"<?xml version=""1.0"" encoding=""utf-8""?>
           <packages>
             <package id =""NLog.Config"" version=""4.5.3"" targetFramework=""net461"" />
           </packages>");
        }
예제 #16
0
        public async Task WhenThereAreUpdates_CountIsAsExpected(int numberOfUpdates, bool consolidateUpdates, int expectedUpdates, int expectedPrs)
        {
            var updateSelection      = Substitute.For <IPackageUpdateSelection>();
            var collaborationFactory = Substitute.For <ICollaborationFactory>();
            var gitDriver            = Substitute.For <IGitDriver>();

            UpdateSelectionAll(updateSelection);

            var packageUpdater = new PackageUpdater(collaborationFactory,
                                                    Substitute.For <IUpdateRunner>(),
                                                    Substitute.For <INuKeeperLogger>());

            var updates = Enumerable.Range(1, numberOfUpdates)
                          .Select(_ => PackageUpdates.UpdateSet())
                          .ToList();

            var settings = MakeSettings(consolidateUpdates);

            var(repoUpdater, _) = MakeRepositoryUpdater(
                updateSelection, updates, packageUpdater);

            var repo = MakeRepositoryData();

            gitDriver.GetCurrentHead().Returns("def");

            var count = await repoUpdater.Run(gitDriver, repo, settings);

            Assert.That(count, Is.EqualTo(expectedUpdates));

            await collaborationFactory.CollaborationPlatform.Received(expectedPrs)
            .OpenPullRequest(
                Arg.Any <ForkData>(),
                Arg.Any <PullRequestRequest>(),
                Arg.Any <IEnumerable <string> >());

            gitDriver.Received(numberOfUpdates)
            .Commit(Arg.Any <string>());
        }