public static void Transform(this IPackageTransformer packageTransformer, string destination, IEnumerable <string> fileToTransformPatterns, IEnumerable <string> pathToDeletePatterns, string source, IEnumerable <string> transformationNames) { if (packageTransformer == null) { throw new ArgumentNullException(nameof(packageTransformer)); } packageTransformer.Transform(true, destination, fileToTransformPatterns, pathToDeletePatterns, source, transformationNames); }
public TransformedPackageMetadata( string sourceUri, string packageType, string platform, string gitRef, IPackageTransformer transformer, ResolveMetadataDelegate resolve, GetProtobuildPackageBinaryDelegate getProtobuildPackageBinary) { SourceURI = sourceUri; PackageType = packageType; Platform = platform; GitRef = gitRef; Transformer = transformer; Resolve = resolve; GetProtobuildPackageBinary = getProtobuildPackageBinary; }
public void Lookup( string uri, string platform, bool preferCacheLookup, out string sourceUri, out string type, out Dictionary<string, string> downloadMap, out Dictionary<string, string> archiveTypeMap, out Dictionary<string, string> resolvedHash, out IPackageTransformer transformer) { uri = _packageRedirector.RedirectPackageUrl(uri); transformer = null; if (uri.StartsWith("local-git://", StringComparison.InvariantCultureIgnoreCase)) { sourceUri = uri.Substring("local-git://".Length); type = PackageManager.PACKAGE_TYPE_LIBRARY; downloadMap = new Dictionary<string, string>(); archiveTypeMap = new Dictionary<string, string>(); resolvedHash = new Dictionary<string, string>(); return; } if (uri.StartsWith("http-git://", StringComparison.InvariantCultureIgnoreCase)) { sourceUri = "http://" + uri.Substring("http-git://".Length); type = PackageManager.PACKAGE_TYPE_LIBRARY; downloadMap = new Dictionary<string, string>(); archiveTypeMap = new Dictionary<string, string>(); resolvedHash = new Dictionary<string, string>(); return; } if (uri.StartsWith("https-git://", StringComparison.InvariantCultureIgnoreCase)) { sourceUri = "https://" + uri.Substring("https-git://".Length); type = PackageManager.PACKAGE_TYPE_LIBRARY; downloadMap = new Dictionary<string, string>(); archiveTypeMap = new Dictionary<string, string>(); resolvedHash = new Dictionary<string, string>(); return; } if (uri.StartsWith("http-nuget://", StringComparison.InvariantCultureIgnoreCase)) { sourceUri = "http://" + uri.Substring("http-nuget://".Length); type = PackageManager.PACKAGE_TYPE_LIBRARY; downloadMap = new Dictionary<string, string>(); archiveTypeMap = new Dictionary<string, string>(); resolvedHash = new Dictionary<string, string>(); transformer = _nugetPackageTransformer; return; } if (uri.StartsWith("https-nuget://", StringComparison.InvariantCultureIgnoreCase)) { sourceUri = "https://" + uri.Substring("https-nuget://".Length); type = PackageManager.PACKAGE_TYPE_LIBRARY; downloadMap = new Dictionary<string, string>(); archiveTypeMap = new Dictionary<string, string>(); resolvedHash = new Dictionary<string, string>(); transformer = _nugetPackageTransformer; return; } var baseUri = new Uri(uri); var apiUri = new Uri(baseUri.ToString().TrimEnd('/') + "/api"); dynamic apiData = null; var performOnlineLookup = true; if (preferCacheLookup) { performOnlineLookup = false; if (File.Exists(this.GetLookupCacheFilename(uri))) { try { using (var reader = new StreamReader(this.GetLookupCacheFilename(uri))) { apiData = JSON.ToDynamic(reader.ReadToEnd()); } } catch (ExecEnvironment.SelfInvokeExitException) { throw; } catch { performOnlineLookup = true; } } else { performOnlineLookup = true; } } if (performOnlineLookup) { try { string jsonString; apiData = this.GetJSON(apiUri, out jsonString); if (apiData.has_error) { throw new InvalidOperationException((string)apiData.error); } try { using (var writer = new StreamWriter(this.GetLookupCacheFilename(uri))) { writer.Write(jsonString); } } catch (IOException ex) { Console.WriteLine("WARNING: Unable to save cached result of request."); } } catch (WebException) { // Attempt to retrieve it from the lookup cache. if (File.Exists(this.GetLookupCacheFilename(uri))) { var shouldThrow = false; try { using (var reader = new StreamReader(this.GetLookupCacheFilename(uri))) { apiData = JSON.ToDynamic(reader.ReadToEnd()); } } catch (ExecEnvironment.SelfInvokeExitException) { throw; } catch { shouldThrow = true; } if (shouldThrow) { throw; } } else { throw; } } catch (InvalidOperationException) { // Attempt to retrieve it from the lookup cache. if (File.Exists(this.GetLookupCacheFilename(uri))) { var shouldThrow = false; try { using (var reader = new StreamReader(this.GetLookupCacheFilename(uri))) { apiData = JSON.ToDynamic(reader.ReadToEnd()); } } catch (ExecEnvironment.SelfInvokeExitException) { throw; } catch { shouldThrow = true; } if (shouldThrow) { throw; } } else { throw; } } } if (apiData == null) { throw new InvalidOperationException("apiData is null"); } sourceUri = (string)apiData.result.package.gitUrl; type = (string)apiData.result.package.type; if (!string.IsNullOrWhiteSpace(sourceUri)) { try { new Uri(sourceUri); } catch (ExecEnvironment.SelfInvokeExitException) { throw; } catch { throw new InvalidOperationException( "Received invalid Git URL when loading package from " + apiUri); } } else { Console.WriteLine("WARNING: This package does not have a source repository set."); } downloadMap = new Dictionary<string, string>(); archiveTypeMap = new Dictionary<string, string>(); resolvedHash = new Dictionary<string, string>(); foreach (var ver in apiData.result.versions) { if (ver.platformName != platform) { continue; } if (!downloadMap.ContainsKey(ver.versionName)) { downloadMap.Add(ver.versionName, ver.downloadUrl); archiveTypeMap.Add(ver.versionName, ver.archiveType); resolvedHash.Add(ver.versionName, ver.versionName); } } foreach (var branch in apiData.result.branches) { if (!downloadMap.ContainsKey(branch.versionName)) { continue; } if (!downloadMap.ContainsKey(branch.branchName)) { downloadMap.Add(branch.branchName, downloadMap[branch.versionName]); archiveTypeMap.Add(branch.branchName, archiveTypeMap[branch.versionName]); resolvedHash.Add(branch.branchName, branch.versionName); } } }
protected internal NewPackageTransformCommand(IPackageTransformer packageTransformer) { this.PackageTransformer = packageTransformer ?? throw new ArgumentNullException(nameof(packageTransformer)); }