Exemplo n.º 1
0
        public Artifact Artifact(Product product)
        {
            var cacheKey = product.ToString();

            if (_resolved.TryGetValue(cacheKey, out var artifact))
            {
                return(artifact);
            }
            switch (ArtifactBuildState)
            {
            case ArtifactBuildState.Released:
                ReleasedVersionResolver.TryResolve(product, this, OsMonikers.CurrentPlatform(), out artifact);
                break;

            case ArtifactBuildState.Snapshot:
                SnapshotApiResolver.TryResolve(product, this, OsMonikers.CurrentPlatform(), null, out artifact);
                break;

            case ArtifactBuildState.BuildCandidate:
                StagingVersionResolver.TryResolve(product, this, BuildHash, out artifact);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(ArtifactBuildState), $"{ArtifactBuildState} not expected here");
            }

            _resolved.TryAdd(cacheKey, artifact);

            return(artifact);
        }
Exemplo n.º 2
0
        public static bool TryResolve(Product product, Version version, OSPlatform os, out Artifact artifact)
        {
            var p            = product.Moniker;
            var downloadPath = $"{ArtifactsUrl}/downloads/{product}";
            var archive      = $"{p}-{version}-{OsMonikers.CurrentPlatformPackageSuffix()}.{product.Extension}";

            if (!product.PlatformDependent || version <= product.PlatformSuffixAfter)
            {
                archive = $"{p}-{version}.{product.Extension}";
            }

            var downloadUrl = $"{downloadPath}/{archive}";

            artifact = new Artifact(product, version, downloadUrl, ArtifactBuildState.Released, null);
            return(true);
        }
        // https://staging.elastic.co/7.2.0-957e3089/downloads/elasticsearch/elasticsearch-7.2.0-linux-x86_64.tar.gz
        // https://staging.elastic.co/7.2.0-957e3089/downloads/elasticsearch-plugins/analysis-icu/analysis-icu-7.2.0.zip
        public static bool TryResolve(Product product, Version version, string buildHash, out Artifact artifact)
        {
            artifact = null;
            if (string.IsNullOrWhiteSpace(buildHash))
            {
                return(false);
            }

            var p           = product.Moniker;
            var stagingRoot = string.Format(StagingUrlFormat, version, buildHash);
            var archive     = $"{p}-{version}-{OsMonikers.CurrentPlatformPackageSuffix()}.{product.Extension}";

            if (!product.PlatformDependent || version <= product.PlatformSuffixAfter)
            {
                archive = $"{p}-{version}.{product.Extension}";
            }

            var downloadUrl = $"{stagingRoot}/downloads/{product}/{archive}";

            artifact = new Artifact(product, version, downloadUrl, ArtifactBuildState.BuildCandidate, buildHash);
            return(true);
        }
Exemplo n.º 4
0
        public static bool TryResolve(Product product, Version version, OSPlatform os, string filters, out Artifact artifact)
        {
            artifact = null;
            var p     = product.SubProduct?.SubProductName ?? product.ProductName;
            var query = p;

            if (product.PlatformDependent && version > product.PlatformSuffixAfter)
            {
                query += $",{OsMonikers.From(os)}";
            }
            else if (product.PlatformDependent)
            {
                query += $",{OsMonikers.CurrentPlatformSearchFilter()}";
            }
            if (!string.IsNullOrWhiteSpace(filters))
            {
                query += $",{filters}";
            }

            var packages = new Dictionary <string, SearchPackage>();

            try
            {
                var json = ApiResolver.FetchJson($"search/{version}/{query}");
                // if packages is empty it turns into an array[] otherwise its a dictionary :/
                packages = JsonSerializer.Deserialize <ArtifactsSearchResponse>(json).Packages;
            }
            catch { }

            if (packages == null || packages.Count == 0)
            {
                return(false);
            }
            var list = packages
                       .OrderByDescending(k => k.Value.Classifier == null ? 1 : 0)
                       .ToArray();

            var ext           = OsMonikers.CurrentPlatformArchiveExtension();
            var shouldEndWith = $"{version}.{ext}";

            if (product.PlatformDependent && version > product.PlatformSuffixAfter)
            {
                shouldEndWith = $"{version}-{OsMonikers.CurrentPlatformPackageSuffix()}.{ext}";
            }
            foreach (var kv in list)
            {
                if (product.PlatformDependent && !kv.Key.EndsWith(shouldEndWith))
                {
                    continue;
                }


                var tokens = PackageProductRegex.Split(kv.Key).Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();
                if (tokens.Length < 2)
                {
                    continue;
                }

                if (!tokens[0].Equals(p, StringComparison.CurrentCultureIgnoreCase))
                {
                    continue;
                }
                if (!tokens[1].Equals(version.ToString(), StringComparison.CurrentCultureIgnoreCase))
                {
                    continue;
                }
                // https://snapshots.elastic.co/7.4.0-677857dd/downloads/elasticsearch-plugins/analysis-icu/analysis-icu-7.4.0-SNAPSHOT.zip
                var buildHash = ApiResolver.GetBuildHash(kv.Value.DownloadUrl);
                artifact = new Artifact(product, version, kv.Value, buildHash);
            }
            return(false);
        }