コード例 #1
0
        /// <summary>
        /// Visists a project.
        /// </summary>
        /// <param name="directory">The directory of the project.</param>
        /// <param name="config">The <see cref="GitDependFile"/> with project configuration information.</param>
        /// <returns>The return code.</returns>
        public ReturnCode VisitProject(string directory, GitDependFile config)
        {
            if (config == null)
            {
                return(ReturnCode = ReturnCode.Success);
            }

            if (string.IsNullOrEmpty(directory) || !_fileSystem.Directory.Exists(directory))
            {
                return(ReturnCode = ReturnCode.DirectoryDoesNotExist);
            }

            foreach (var dependency in config.Dependencies)
            {
                var dependencyDir = _fileSystem.Path.GetFullPath(_fileSystem.Path.Combine(directory, dependency.Directory));
                var dir           = _fileSystem.Path.GetFullPath(_fileSystem.Path.Combine(dependencyDir, dependency.Configuration.Packages.Directory));

                foreach (var file in _fileSystem.Directory.GetFiles(dir, "*.nupkg"))
                {
                    var name = _fileSystem.Path.GetFileNameWithoutExtension(file);


                    if (string.IsNullOrEmpty(name))
                    {
                        continue;
                    }

                    var match = Pattern.Match(name);

                    if (!match.Success)
                    {
                        continue;
                    }

                    var id      = match.Groups["id"].Value;
                    var version = match.Groups["version"].Value;

                    _nuget.WorkingDirectory = directory;

                    foreach (var solution in _fileSystem.Directory.GetFiles(directory, "*.sln", SearchOption.AllDirectories))
                    {
                        var cacheDir = GetCacheDirectory();

                        if (string.IsNullOrEmpty(cacheDir))
                        {
                            return(ReturnCode = ReturnCode.CouldNotCreateCacheDirectory);
                        }

                        _nuget.Restore(solution);
                        _nuget.Update(solution, id, version, cacheDir);
                    }
                }
            }

            _console.WriteLine("================================================================================");
            _console.WriteLine($"Making update commit on {directory}");
            _git.WorkingDirectory = directory;
            _git.Add("*.csproj", @"*\packages.config");
            _console.WriteLine("================================================================================");
            _git.Status();
            _git.Commit("GitDepend: updating dependencies");

            return(ReturnCode = ReturnCode.Success);
        }
コード例 #2
0
        /// <summary>
        /// Visists a project.
        /// </summary>
        /// <param name="directory">The directory of the project.</param>
        /// <param name="config">The <see cref="GitDependFile"/> with project configuration information.</param>
        /// <returns>The return code.</returns>
        public ReturnCode VisitProject(string directory, GitDependFile config)
        {
            if (config == null)
            {
                return(ReturnCode = ReturnCode.Success);
            }

            // If there are specific dependencies specified
            // and this one isn't in the list
            // skip it.
            if (_whitelist.Any() &&
                _whitelist.All(d => !string.Equals(d, config.Name, StringComparison.InvariantCultureIgnoreCase)))
            {
                return(ReturnCode.Success);
            }

            if (string.IsNullOrEmpty(directory) || !_fileSystem.Directory.Exists(directory))
            {
                return(ReturnCode = ReturnCode.DirectoryDoesNotExist);
            }

            StringBuilder commitMessage = new StringBuilder();

            commitMessage.AppendLine("GitDepend: updating dependencies");
            commitMessage.AppendLine();

            var solutions = _fileSystem.Directory.GetFiles(directory, "*.sln", SearchOption.AllDirectories);

            foreach (var solution in solutions)
            {
                _nuget.Restore(solution);
            }

            foreach (var solution in solutions)
            {
                var path = solution.Remove(0, directory.Length + 1);
                commitMessage.AppendLine(path);

                foreach (var dependency in config.Dependencies)
                {
                    // If there are specific dependencies specified
                    // and this one isn't in the list
                    // skip it.
                    if (_whitelist.Any() &&
                        _whitelist.All(d => !string.Equals(d, dependency.Configuration.Name, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        continue;
                    }

                    var dependencyDir = _fileSystem.Path.GetFullPath(_fileSystem.Path.Combine(directory, dependency.Directory));
                    var dir           = _fileSystem.Path.GetFullPath(_fileSystem.Path.Combine(dependencyDir, dependency.Configuration.Packages.Directory));

                    foreach (var file in _fileSystem.Directory.GetFiles(dir, "*.nupkg"))
                    {
                        var name = _fileSystem.Path.GetFileNameWithoutExtension(file);


                        if (string.IsNullOrEmpty(name))
                        {
                            continue;
                        }

                        var match = Pattern.Match(name);

                        if (!match.Success)
                        {
                            continue;
                        }

                        var id      = match.Groups["id"].Value;
                        var version = match.Groups["version"].Value;

                        commitMessage.AppendLine($"* {id}.{version}");

                        _nuget.WorkingDirectory = directory;

                        var cacheDir = GetCacheDirectory();

                        if (string.IsNullOrEmpty(cacheDir))
                        {
                            return(ReturnCode = ReturnCode.CouldNotCreateCacheDirectory);
                        }

                        _nuget.Update(solution, id, version, cacheDir);

                        var package = $"{id}.{version}";
                        if (!UpdatedPackages.Contains(package))
                        {
                            UpdatedPackages.Add(package);
                        }
                    }
                }
            }

            _console.WriteLine("================================================================================");
            _console.WriteLine($"Making update commit on {directory}");
            _git.WorkingDirectory = directory;
            _git.Add("*.csproj", @"*\packages.config");
            _console.WriteLine("================================================================================");
            _git.Status();

            _git.Commit(commitMessage.ToString());

            return(ReturnCode = ReturnCode.Success);
        }