Пример #1
0
        public static bool TryParseGitSource(string spec, out GitSource package)
        {
            package = null;
            int gitIndex = -1;

            if (string.IsNullOrEmpty(spec) || (gitIndex = spec.IndexOf(".git", StringComparison.OrdinalIgnoreCase)) < 0)
            {
                return(false);
            }
            else
            {
                int index = gitIndex + 4;
                int indexOfLastSlashBeforeGit = -1;
                int indexOfSlash = -1;
                while ((indexOfSlash = spec.IndexOf('/', indexOfLastSlashBeforeGit + 1)) < index && indexOfSlash != -1)
                {
                    indexOfLastSlashBeforeGit = indexOfSlash;
                }

                string gitUrl    = spec.Substring(0, index);
                string subFolder = spec.Substring(index);
                subFolder = subFolder.Trim('/');
                string repoName = gitUrl.Substring(indexOfLastSlashBeforeGit + 1).Replace(".git", string.Empty);
                package = new GitSource(gitUrl, subFolder, repoName);
                return(true);
            }
        }
Пример #2
0
        public void InstallPackages(IEnumerable <string> installationRequests)
        {
            List <string>    localSources = new List <string>();
            List <Package>   packages     = new List <Package>();
            List <GitSource> gitSources   = new List <GitSource>();

            foreach (string request in installationRequests)
            {
                string req = request;

                //If the request string doesn't have any wild cards or probable path indicators,
                //  and doesn't have a "::" delimiter either, try to convert it to "latest package"
                //  form
                if (req.IndexOfAny(new[] { '*', '?', '/', '\\' }) < 0 && req.IndexOf("::", StringComparison.Ordinal) < 0)
                {
                    req += "::*";
                }

                if (Package.TryParse(req, out Package package))
                {
                    packages.Add(package);
                }
                else if (GitSource.TryParseGitSource(req, out GitSource gitSource))
                {
                    gitSources.Add(gitSource);
                }
                else
                {
                    localSources.Add(request);
                }
            }

            if (localSources.Count > 0)
            {
                InstallLocalPackages(localSources);
            }

            if (packages.Count > 0)
            {
                InstallRemotePackages(packages);
            }

            if (gitSources.Count > 0)
            {
                InstallGitSources(gitSources);
            }

            _environmentSettings.SettingsLoader.Save();
        }