/// <summary> /// Initializes a new instance of the <see cref="LoaderValidating"/> class. /// </summary> /// <param name="loader">The base loader instance.</param> /// <param name="versionParser">The version parser instance.</param> public LoaderValidating(ILoaderPackage loader, IVersionParser versionParser = null) { this.loader = loader; this.versionParser = versionParser ?? new BVersionParser(); errors = new List <string>(); warnings = new List <string>(); }
/// <summary> /// Initializes a new instance of the <see cref="RepositoryBucket"/> class. /// </summary> public RepositoryBucket( ConfigRepositoryBucket configRepository, IIO io, Config config, ITransport transport = null, IEventDispatcher eventDispatcher = null, IVersionParser versionParser = null) { if (!Regex.IsMatch(configRepository.Uri, @"^[\w.]+\??://")) { // assume http as the default protocol configRepository.Uri = $"http://{configRepository.Uri}"; } configRepository.Uri = configRepository.Uri.TrimEnd('/'); if (configRepository.Uri.StartsWith("https?", StringComparison.OrdinalIgnoreCase)) { configRepository.Uri = $"https{configRepository.Uri.Substring(6)}"; uriIsIntelligent = true; } if (!Uri.TryCreate(configRepository.Uri, UriKind.RelativeOrAbsolute, out _)) { throw new ConfigException($"Invalid url given for Bucket repository: {configRepository.Uri}"); } // changes will not be applied to configRepository. uri = configRepository.Uri; // force url for gxpack.org to repo.gxpack.org // without converting other addresses. var match = Regex.Match(configRepository.Uri, @"^(?<proto>https?)://gxpack\.org/?$", RegexOptions.IgnoreCase); if (match.Success) { uri = $"{match.Groups["proto"].Value}://repo.gxpack.org"; } baseUri = Regex.Replace(uri, @"(?:/[^/\\\\]+\.json)?(?:[?#].*)?$", string.Empty).TrimEnd('/'); this.configRepository = configRepository; this.io = io; this.transport = transport ?? new TransportHttp(io, config); this.eventDispatcher = eventDispatcher; this.versionParser = versionParser ?? new BVersionParser(); var cacheDir = Path.Combine(config.Get(Settings.CacheDir), CacheFileSystem.FormatCacheFolder(uri)); cache = new CacheFileSystem(cacheDir, io, "a-z0-9.$~"); loader = new LoaderPackage(versionParser); providersByUid = new Dictionary <int, IPackage>(); }
/// <inheritdoc /> protected override void Initialize() { var driver = GetDriver(); if (driver == null) { throw new InvalidArgumentException($"No driver found to handle VCS repository {uri}"); } if (loader == null) { loader = new LoaderPackage(); } var rootIdentifier = driver.GetRootIdentifier(); try { if (driver.HasBucketFile(rootIdentifier)) { var bucketInformation = driver.GetBucketInformation(rootIdentifier); packageName = bucketInformation.Name; } } #pragma warning disable CA1031 catch (System.Exception ex) #pragma warning restore CA1031 { io.WriteError($"<error>Skipped parsing {rootIdentifier}, {ex.Message}</error>", verbosity: Verbosities.VeryVerbose); } foreach (var item in driver.GetTags()) { var originTag = item.Key; var identifier = item.Value; var message = $"Reading {Factory.DefaultBucketFile} of <info>({packageName ?? uri.ToString()})</info> (tag:<comment>{originTag}</comment>)"; if (isVeryVerbose) { io.WriteError(message); } else if (isVerbose) { io.OverwriteError(message, false); } // strip the release- prefix from tags if present. var tag = originTag.Trim().IndexOf("release-", StringComparison.OrdinalIgnoreCase) != 0 ? originTag : originTag.Substring(8); var cachedPackage = GetCachedPackageVersion(tag, identifier, out bool skipped); if (cachedPackage != null) { AddPackage(cachedPackage); continue; } else if (skipped) { emptyReferences.AddLast(identifier); continue; } var parsedTag = ValidateTag(tag); if (string.IsNullOrEmpty(parsedTag)) { io.WriteError($"<warning>Skipped tag {tag}, invalid tag name.</warning>", verbosity: Verbosities.VeryVerbose); continue; } try { var bucketInformation = driver.GetBucketInformation(identifier); if (bucketInformation == null) { io.WriteError($"<warning>Skipped tag {tag}, no {Factory.DefaultBucketFile} file.</warning>", verbosity: Verbosities.VeryVerbose); emptyReferences.AddLast(identifier); continue; } var version = bucketInformation.Version; string versionNormalized; if (!string.IsNullOrEmpty(version)) { versionNormalized = versionParser.Normalize(bucketInformation.Version); } else { version = tag; versionNormalized = parsedTag; } // make sure tag packages have no -dev flag version = Regex.Replace(version, "[.-]?dev$", string.Empty, RegexOptions.IgnoreCase); versionNormalized = Regex.Replace(versionNormalized, "(^dev-|[.-]?dev$)", string.Empty, RegexOptions.IgnoreCase); // broken package, version doesn't match tag if (versionNormalized != parsedTag) { io.WriteError($"<warning>Skipped tag {tag}, tag ({parsedTag}) does not match version ({versionNormalized}) in {Factory.DefaultBucketFile}</warning>", verbosity: Verbosities.VeryVerbose); continue; } var tagPackageName = string.IsNullOrEmpty(bucketInformation.Name) ? bucketInformation.Name : packageName; var existingPackage = this.FindPackage(tagPackageName, versionNormalized); if (existingPackage != null) { io.WriteError( $"<warning>Skipped tag {tag}, it conflicts with an another tag ({existingPackage.GetVersionPretty()}) as both resolve to {versionNormalized} internally</warning>", verbosity: Verbosities.VeryVerbose); continue; } io.WriteError($"Importing tag {tag} ({versionNormalized})", verbosity: Verbosities.VeryVerbose); bucketInformation.Version = version; bucketInformation.VersionNormalized = versionNormalized; AddPackage(loader.Load(PreProcess(driver, bucketInformation, identifier))); } #pragma warning disable CA1031 catch (System.Exception ex) #pragma warning restore CA1031 { string errorMessage; if (ex is TransportException transportException && transportException.HttpStatusCode == HttpStatusCode.NotFound) { emptyReferences.AddLast(identifier); errorMessage = $"no {Factory.DefaultBucketFile} file was found"; }
/// <summary> /// Set a package loader to load package. /// </summary> /// <param name="loader">The package loader instance.</param> public void SetLoader(ILoaderPackage loader) { this.loader = loader; }
/// <summary> /// Initializes a new instance of the <see cref="RepositoryFileSystem"/> class. /// </summary> /// <param name="file">The repository json file.</param> public RepositoryFileSystem(JsonFile file) { this.file = file; dumper = new DumperPackage(); loader = new LoaderPackage(); }
/// <summary> /// Converts a package from <see cref="ConfigBucket"/> instance. /// </summary> /// <typeparam name="T">The type which package will loaded.</typeparam> /// <param name="loader">The loader instance.</param> /// <param name="config">The config bucket instance.</param> /// <returns>Returns package instance.</returns> public static T Load <T>(this ILoaderPackage loader, ConfigBucketBase config) where T : class, IPackage { return((T)loader.Load(config, typeof(T))); }
/// <summary> /// Converts a package from <see cref="ConfigBucket"/> instance. /// </summary> /// <param name="loader">The loader instance.</param> /// <param name="config">The config bucket instance.</param> /// <returns>Returns package instance.</returns> public static IPackageComplete Load(this ILoaderPackage loader, ConfigBucketBase config) { return((IPackageComplete)loader.Load(config, typeof(IPackageComplete))); }
public void Initialize() { loader = new LoaderPackage(); }