Пример #1
0
        public static string GetNugetPackageVersion(string packageName, string nugetRunCommand, bool preRelease)
        {
            var shellRunner = new ShellRunner();

            ConsoleWriter.WriteProgressWithoutSave("Get package verion for " + packageName);

            shellRunner.Run($"{nugetRunCommand} list {packageName} -NonInteractive" + (preRelease ? " -PreRelease" : ""));
            foreach (var line in shellRunner.Output.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries))
            {
                var lineTokens = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (lineTokens.Length == 2 && lineTokens[0].Equals(packageName, StringComparison.InvariantCultureIgnoreCase))
                {
                    var msg = $"Got package version: {lineTokens[1]} for {packageName}";
                    Log.Info(msg);
                    ConsoleWriter.WriteInfo(msg);
                    return(lineTokens[1]);
                }
            }

            var message = $"not found package version for package {packageName}. nuget output: " + shellRunner.Output + shellRunner.Errors;

            Log.Debug(message);
            ConsoleWriter.WriteWarning(message);
            return(null);
        }
Пример #2
0
        private ShellRunner PrepareShellRunner()
        {
            var runner = new ShellRunner();

            if (buildSettings.ShowOutput)
            {
                runner.OnOutputChange += ModuleBuilderHelper.WriteLine;
                return(runner);
            }

            if (buildSettings.ShowProgress)
            {
                runner.OnOutputChange += ModuleBuilderHelper.WriteProgress;
            }

            if (buildSettings.ShowAllWarnings)
            {
                runner.OnOutputChange += ModuleBuilderHelper.WriteIfWarning;
                return(runner);
            }

            if (buildSettings.ShowObsoleteWarnings)
            {
                runner.OnOutputChange += ModuleBuilderHelper.WriteIfObsoleteFull;
                return(runner);
            }

            if (buildSettings.ShowWarningsSummary)
            {
                runner.OnOutputChange += ModuleBuilderHelper.WriteIfObsoleteGrouped;
            }
            return(runner);
        }
Пример #3
0
        public static string GetMsBuildVersion(string fullPathToMsBuild)
        {
            if (!File.Exists(fullPathToMsBuild))
            {
                return(null);
            }

            try
            {
                var shellRunner = new ShellRunner();
                var exitCode    = shellRunner.RunOnce(Path.GetFileName(fullPathToMsBuild) + " -version", Path.GetDirectoryName(fullPathToMsBuild), TimeSpan.FromSeconds(10));
                if (exitCode == 0 && !string.IsNullOrEmpty(shellRunner.Output))
                {
                    var versionMatches = Regex.Matches(shellRunner.Output, @"^(?<version>\d+(\.\d+)+)", RegexOptions.ExplicitCapture | RegexOptions.Multiline);
                    if (versionMatches.Count > 0)
                    {
                        var version = versionMatches[versionMatches.Count - 1].Groups["version"].Value;
                        if (!string.IsNullOrEmpty(version))
                        {
                            return(version);
                        }
                    }
                }
                else
                {
                    Log.LogDebug("Failed to get msbuild version for " + fullPathToMsBuild);
                }
            }
            catch (Exception e)
            {
                Log.LogWarning("Failed to get MSBuild version from " + fullPathToMsBuild, e);
            }
            return(null);
        }
Пример #4
0
 public GitRepository(string moduleName, string workspace, ILog log)
 {
     ModuleName        = moduleName;
     Workspace         = workspace;
     RepoPath          = Path.Combine(workspace, moduleName);
     GitRepository.log = log;
     runner            = new ShellRunner(GitRepository.log);
     IsGitRepo         = Directory.Exists(Path.Combine(workspace, moduleName, ".git"));
 }
Пример #5
0
        public static bool HasRemoteBranch(string url, string branchName)
        {
            if (string.IsNullOrEmpty(branchName))
            {
                return(false);
            }
            var runner = new ShellRunner();

            runner.Run($"git ls-remote {url} {branchName}");
            return(runner.Output.Contains("refs/heads"));
        }
Пример #6
0
        public GitRepository(string moduleName, string workspace, ILogger log)
        {
            this.log    = log;
            runner      = new ShellRunner(log);
            buildHelper = BuildHelper.Shared;

            ModuleName = moduleName;
            Workspace  = workspace;
            RepoPath   = Path.Combine(workspace, moduleName);

            IsGitRepo = Directory.Exists(Path.Combine(workspace, moduleName, ".git"));
        }
Пример #7
0
        private static void UpdateGitPackage(Package package)
        {
            var runner  = new ShellRunner(Log);
            var timeout = TimeSpan.FromMinutes(1);

            var remoteHash = GetRepositoryHeadHash(package);
            var localHash  = Helper.GetPackageCommitHash(package.Name);

            if (remoteHash != null && remoteHash.Equals(localHash))
            {
                return;
            }

            for (var i = 0; i < 3; i++)
            {
                using (var tempDir = new TempDirectory())
                {
                    if (runner.RunOnce(
                            $"git clone {package.Url} \"{Path.Combine(tempDir.Path, package.Name)}\"",
                            Directory.GetCurrentDirectory(),
                            timeout)
                        != 0)
                    {
                        if (runner.HasTimeout && i < 2)
                        {
                            timeout = TimeoutHelper.IncreaseTimeout(timeout);
                            continue;
                        }

                        throw new CementException(
                                  $"Failed to update package {package.Name}:\n{runner.Output}\nError message:\n{runner.Errors}\n" +
                                  $"Ensure that command 'git clone {package.Url}' works in cmd");
                    }

                    lock (Helper.PackageLockObject)
                    {
                        if (!Directory.Exists(Helper.GetGlobalCementDirectory()))
                        {
                            Directory.CreateDirectory(Helper.GetGlobalCementDirectory());
                        }
                        File.Copy(
                            Path.Combine(tempDir.Path, package.Name, "modules"),
                            Helper.GetPackagePath(package.Name), true);
                        Helper.WritePackageCommitHash(package.Name, remoteHash);
                    }

                    break;
                }
            }
        }
Пример #8
0
        private static void PrintBuildFailResult(Dep dep, string buildName, ShellRunner runner)
        {
            ConsoleWriter.WriteBuildError(
                $"Failed to build {dep.Name}{(dep.Configuration == null ? "" : "/" + dep.Configuration)} {buildName}");
            foreach (var line in runner.Output.Split('\n'))
            {
                ModuleBuilderHelper.WriteLine(line);
            }

            ConsoleWriter.WriteLine();
            ConsoleWriter.WriteInfo("Errors summary:");
            foreach (var line in runner.Output.Split('\n'))
            {
                ModuleBuilderHelper.WriteIfErrorToStandartStream(line);
            }
        }
Пример #9
0
        private static string RunVsDevCmd()
        {
            var path = FindVsDevCmd();

            if (path == null)
            {
                Log.Debug("VsDevCmd.bat not found");
                return(null);
            }
            Log.Info($"VsDevCmd found in {path}");
            var command = $"\"{path}\" && set";
            var runner  = new ShellRunner();

            if (runner.Run(command) != 0)
            {
                Log.Debug("VsDevCmd.bat not working");
                return(null);
            }
            return(runner.Output);
        }
Пример #10
0
        private static string GetRepositoryHeadHash(Package package)
        {
            var runner  = new ShellRunner(Log);
            var timeout = TimeSpan.FromMinutes(1);

            var exitCode = runner.RunOnce($"git ls-remote {package.Url} HEAD", Directory.GetCurrentDirectory(), timeout);

            if (exitCode != 0)
            {
                var errorMessage = $"Cannot get hash code of package '{package.Name}' ({package.Url})\n" +
                                   "Git output:\n\n" +
                                   runner.Errors;

                throw new CementException(errorMessage);
            }

            var output = runner.Output;

            return(output.Split().FirstOrDefault());
        }
Пример #11
0
 public Cleaner(ShellRunner shellRunner)
 {
     this.shellRunner = shellRunner;
 }
Пример #12
0
 public Cleaner(ILogger <Cleaner> log, ShellRunner shellRunner, ConsoleWriter consoleWriter)
 {
     this.log           = log;
     this.shellRunner   = shellRunner;
     this.consoleWriter = consoleWriter;
 }