예제 #1
0
        /// <summary>
        /// Process the download url, compatibility adjustments can be made in it.
        /// </summary>
        protected virtual string ProcessUri(IPackage package, string uri)
        {
            if (!string.IsNullOrEmpty(package.GetDistReference()))
            {
                uri = BucketUri.UpdateDistReference(config, uri, package.GetDistReference());
            }

            return(uri);
        }
예제 #2
0
        /// <summary>
        /// Gets file path for specific package.
        /// </summary>
        protected internal virtual string GetDownloadedFilePath(IPackage package, string cwd)
        {
            var uri      = new Uri(package.GetDistUri());
            var filename = Security.Md5($"{cwd}{package}{package.GetDistReference()}{package.GetDistShasum()}");

            return(Path.Combine(GetTempDirectory(), "download", $"{filename}{Path.GetExtension(uri.AbsolutePath)}"));
        }
예제 #3
0
        private void ExecuteUpdate(string cwd, string reference, IPackage target)
        {
            var newReference = UpdateToCommit(cwd, reference, target.GetVersionPretty(), target.GetReleaseDate());

            if (string.IsNullOrEmpty(newReference) ||
                !(target is Package.Package originPackage))
            {
                return;
            }

            if (target.GetDistReference() == target.GetSourceReference())
            {
                originPackage.SetDistReference(newReference);
            }

            originPackage.SetSourceReference(newReference);
        }
예제 #4
0
        private DateTime?GetPackageTimeFromSource(IPackage package)
        {
            var      installedPath = Path.Combine(Environment.CurrentDirectory, installationManager.GetInstalledPath(package));
            var      sourceType    = package.GetSourceType();
            DateTime?ret           = null;

            if (string.IsNullOrEmpty(installedPath) || !Array.Exists(new[] { "git" }, (item) => item == sourceType))
            {
                return(null);
            }

            var sourceReference = package.GetSourceReference() ?? package.GetDistReference();

            DateTime?GetGitDateTime()
            {
                Git.CleanEnvironment();
                if (process.Execute(
                        $"git log -n1 --pretty=%aD {ProcessExecutor.Escape(sourceReference)}",
                        out string output, installedPath) == 0 &&
                    DateTime.TryParse(output.Trim(), out DateTime dateTime))
                {
                    return(dateTime);
                }

                return(null);
            }

            switch (sourceReference)
            {
            case "git":
                ret = GetGitDateTime();
                break;

            default:
                break;
            }

            return(ret);
        }
예제 #5
0
        /// <summary>
        /// Dump the package instance to <see cref="ConfigBucket"/>.
        /// </summary>
        /// <typeparam name="T">The type of the config struct.</typeparam>
        /// <param name="package">The package instance.</param>
        /// <returns>The <see cref="ConfigBucket"/> instance.</returns>
        public T Dump <T>(IPackage package)
            where T : ConfigBucketBase, new()
        {
            var data = new T
            {
                Name               = package.GetNamePretty(),
                Version            = package.GetVersionPretty(),
                VersionNormalized  = package.GetVersion(),
                ReleaseDate        = package.GetReleaseDate(),
                PackageType        = package.GetPackageType(),
                NotificationUri    = package.GetNotificationUri(),
                Binaries           = package.GetBinaries().ZeroAsNull(),
                Archive            = package.GetArchives().ZeroAsNull(),
                Extra              = package.GetExtra(),
                InstallationSource = package.GetInstallationSource(),
            };

            if (!string.IsNullOrEmpty(package.GetSourceType()))
            {
                data.Source = new ConfigResource
                {
                    Type      = package.GetSourceType(),
                    Uri       = package.GetSourceUri(),
                    Reference = package.GetSourceReference(),
                    Mirrors   = package.GetSourceMirrors().ZeroAsNull(),
                };
            }

            if (!string.IsNullOrEmpty(package.GetDistType()))
            {
                data.Dist = new ConfigResource
                {
                    Type      = package.GetDistType(),
                    Uri       = package.GetDistUri(),
                    Reference = package.GetDistReference(),
                    Mirrors   = package.GetDistMirrors().ZeroAsNull(),
                    Shasum    = package.GetDistShasum(),
                };
            }

            data.Requires    = LinksToDictonary(package.GetRequires());
            data.RequiresDev = LinksToDictonary(package.GetRequiresDev());
            data.Conflicts   = LinksToDictonary(package.GetConflicts());
            data.Provides    = LinksToDictonary(package.GetProvides());
            data.Replaces    = LinksToDictonary(package.GetReplaces());

            var suggests = package.GetSuggests();

            if (suggests != null && suggests.Count > 0)
            {
                data.Suggests = new SortedDictionary <string, string>(suggests);
            }

            if (package is IPackageComplete packageComplete)
            {
                data.Licenses     = packageComplete.GetLicenses().ZeroAsNull();
                data.Authors      = packageComplete.GetAuthors().ZeroAsNull();
                data.Description  = packageComplete.GetDescription();
                data.Homepage     = packageComplete.GetHomepage();
                data.Keywords     = packageComplete.GetKeywords().ZeroAsNull();
                data.Repositories = packageComplete.GetRepositories().ZeroAsNull();

                if (packageComplete.IsDeprecated)
                {
                    var replacement = packageComplete.GetReplacementPackage();
                    if (string.IsNullOrEmpty(replacement))
                    {
                        data.Deprecated = true;
                    }
                    else
                    {
                        data.Deprecated = replacement;
                    }
                }

                data.Scripts = packageComplete.GetScripts();

                var supports = packageComplete.GetSupport();
                if (supports != null && supports.Count > 0)
                {
                    data.Support = new SortedDictionary <string, string>(supports);
                }
            }

            if (package is IPackageRoot packageRoot)
            {
                data.MinimumStability = packageRoot.GetMinimumStability();
                data.Platforms        = packageRoot.GetPlatforms();
            }

            if (data.Keywords != null)
            {
                Array.Sort(data.Keywords);
            }

            return(data);
        }