private string CheckAbove(string modulePath, PackageRef package, string platform) { var module = ModuleInfo.Load(Path.Combine(modulePath, "Build", "Module.xml")); var found = module.Packages.Select(x => (PackageRef?)x) .FirstOrDefault(x => string.Compare(x.Value.Uri, package.Uri, StringComparison.InvariantCulture) == 0); if (found != null) { return Path.Combine(modulePath, found.Value.Folder); } bool isNestedInPlatformFolder; var parent = this.GetParentModule(modulePath, platform, out isNestedInPlatformFolder); if (parent != null) { var above = this.CheckAbove(parent, package, platform); if (above != null) { return above; } var directoryName = new DirectoryInfo(modulePath).Name; if (isNestedInPlatformFolder) { directoryName = new DirectoryInfo(Path.Combine(modulePath, "..")).Name; } var across = this.CheckAcross(parent, package, directoryName, platform); if (across != null) { return across; } } return null; }
public string DiscoverExistingPackagePath(string moduleRoot, PackageRef package, string platform) { // Check the ModuleInfo.xml files of other modules in the // hierarchy in this order: // * Above us (this ensures the common libraries are at the highest point) // * Across from us (in the same folder) up to our name alphabetically // * Below us bool isNestedInPlatformFolder; var parentModule = this.GetParentModule(moduleRoot, platform, out isNestedInPlatformFolder); if (parentModule != null) { var above = this.CheckAbove(parentModule, package, platform); if (above != null) { return above; } var directoryName = new DirectoryInfo(moduleRoot).Name; if (isNestedInPlatformFolder) { directoryName = new DirectoryInfo(Path.Combine(moduleRoot, "..")).Name; } var across = this.CheckAcross(parentModule, package, directoryName, platform); if (across != null) { return across; } } return null; }
private string CheckAcross(string modulePath, PackageRef package, string originalDirectoryName, string platform) { var directory = new DirectoryInfo(modulePath); foreach (var subdirectory in directory.GetDirectories()) { if (string.Compare(subdirectory.Name, originalDirectoryName, StringComparison.InvariantCultureIgnoreCase) >= 0) { // This directory is either the original directory or // a directory with a later alphabetical order. We ignore // it (this is how we resolve whether A should use B's package // or B should use A's package). continue; } if (File.Exists(Path.Combine(subdirectory.FullName, "Build", "Module.xml"))) { var module = ModuleInfo.Load(Path.Combine(subdirectory.FullName, "Build", "Module.xml")); var found = module.Packages.Select(x => (PackageRef?)x) .FirstOrDefault(x => string.Compare(x.Value.Uri, package.Uri, StringComparison.InvariantCulture) == 0); if (found != null) { return Path.Combine(subdirectory.FullName, found.Value.Folder); } var submodules = module.GetSubmodules(); foreach (var submodule in submodules) { var below = this.CheckBelow(submodule.Path, package, platform); if (below != null) { return below; } } } if (File.Exists(Path.Combine(subdirectory.FullName, platform, "Build", "Module.xml"))) { var module = ModuleInfo.Load(Path.Combine(subdirectory.FullName, platform, "Build", "Module.xml")); var found = module.Packages.Select(x => (PackageRef?)x) .FirstOrDefault(x => string.Compare(x.Value.Uri, package.Uri, StringComparison.InvariantCulture) == 0); if (found != null) { return Path.Combine(subdirectory.FullName, platform, found.Value.Folder); } var submodules = module.GetSubmodules(); foreach (var submodule in submodules) { var below = this.CheckBelow(submodule.Path, package, platform); if (below != null) { return below; } } } } return null; }
public int Execute(Execution execution) { if (File.Exists(Path.Combine("Build", "Module.xml"))) { throw new InvalidOperationException("This directory already has a module setup."); } var url = execution.StartProjectTemplateURL; var branch = "master"; if (url.LastIndexOf('@') > url.LastIndexOf('/')) { // A branch / commit ref is specified. branch = url.Substring(url.LastIndexOf('@') + 1); url = url.Substring(0, url.LastIndexOf('@')); } var packageRef = new PackageRef { Uri = url, GitRef = branch, Folder = string.Empty }; // If no project name is specified, use the name of the current directory. if (string.IsNullOrWhiteSpace(execution.StartProjectName)) { var dir = new DirectoryInfo(Environment.CurrentDirectory); execution.StartProjectName = dir.Name; Console.WriteLine("Using current directory name '" + dir.Name + "' as name of new module."); } // The module can not be loaded before this point because it doesn't // yet exist. this.m_PackageManager.Resolve(null, packageRef, "Template", execution.StartProjectName, false); if (execution.DisableProjectGeneration) { Console.WriteLine("Module has been initialized."); return(0); } Console.WriteLine("Module has been initialized. Performing --generate to create projects."); var module = ModuleInfo.Load(Path.Combine("Build", "Module.xml")); return(this.m_ActionDispatch.PerformAction( module, "generate", execution.Platform, execution.EnabledServices.ToArray(), execution.DisabledServices.ToArray(), execution.ServiceSpecificationPath, execution.DebugServiceResolution, execution.DisablePackageResolution, execution.DisableHostProjectGeneration) ? 0 : 1); }
public int Execute(Execution execution) { if (File.Exists(Path.Combine("Build", "Module.xml"))) { throw new InvalidOperationException("This directory already has a module setup."); } var url = execution.StartProjectTemplateURL; var branch = "master"; if (url.LastIndexOf('@') > url.LastIndexOf('/')) { // A branch / commit ref is specified. branch = url.Substring(url.LastIndexOf('@') + 1); url = url.Substring(0, url.LastIndexOf('@')); } var packageRef = new PackageRef { Uri = url, GitRef = branch, Folder = string.Empty }; // If no project name is specified, use the name of the current directory. if (string.IsNullOrWhiteSpace(execution.StartProjectName)) { var dir = new DirectoryInfo(Environment.CurrentDirectory); execution.StartProjectName = dir.Name; Console.WriteLine("Using current directory name '" + dir.Name + "' as name of new module."); } // The module can not be loaded before this point because it doesn't // yet exist. this.m_PackageManager.Resolve(null, packageRef, "Template", execution.StartProjectName, false); if (execution.DisableProjectGeneration) { Console.WriteLine("Module has been initialized."); return 0; } Console.WriteLine("Module has been initialized. Performing --generate to create projects."); var module = ModuleInfo.Load(Path.Combine("Build", "Module.xml")); return this.m_ActionDispatch.PerformAction( module, "generate", execution.Platform, execution.EnabledServices.ToArray(), execution.DisabledServices.ToArray(), execution.ServiceSpecificationPath, execution.DebugServiceResolution, execution.DisablePackageResolution, execution.DisableHostProjectGeneration) ? 0 : 1; }
public void Resolve(string workingDirectory, ModuleInfo module, PackageRef reference, string platform, string templateName, bool?source, bool forceUpgrade, bool?safeResolve) { var metadata = Lookup(workingDirectory, module, reference, platform, templateName, source, forceUpgrade, safeResolve); if (metadata == null) { return; } Resolve(workingDirectory, metadata, reference, templateName, source, forceUpgrade, safeResolve); }
public IPackageMetadata Lookup(string workingDirectory, ModuleInfo module, PackageRef reference, string platform, string templateName, bool?source, bool forceUpgrade, bool?safeResolve) { if (!_featureManager.IsFeatureEnabled(Feature.PackageManagement)) { return(null); } if (module != null && reference.Folder != null) { var existingPath = this.m_PackageLocator.DiscoverExistingPackagePath(module.Path, reference, platform); if (existingPath != null && Directory.Exists(existingPath)) { RedirectableConsole.WriteLine("Found an existing working copy of this package at " + existingPath); Directory.CreateDirectory(Path.Combine(workingDirectory, reference.Folder)); using (var writer = new StreamWriter(Path.Combine(workingDirectory, reference.Folder, ".redirect"))) { writer.WriteLine(existingPath); } return(null); } else { if (File.Exists(Path.Combine(workingDirectory, reference.Folder, ".redirect"))) { try { File.Delete(Path.Combine(workingDirectory, reference.Folder, ".redirect")); } catch { } } } } var request = new PackageRequestRef( reference.Uri, reference.GitRef, platform, forceUpgrade, reference.IsStaticReference); return(_packageLookup.Lookup(workingDirectory, request)); }
public string GetGlobalToolInstallationPath(PackageRef reference) { var toolsPath = this.GetToolsPath(); var sha1 = new SHA1Managed(); var urlHashBytes = sha1.ComputeHash(Encoding.UTF8.GetBytes(reference.Uri)); var urlHashString = BitConverter.ToString(urlHashBytes).Replace("-", "").ToLowerInvariant(); var toolPath = Path.Combine(toolsPath, urlHashString); if (!Directory.Exists(toolPath)) { Directory.CreateDirectory(toolPath); } return toolPath; }
private void ResolveLibrarySource(PackageRef reference, string source, bool forceUpgrade) { if (File.Exists(Path.Combine(reference.Folder, ".git")) || Directory.Exists(Path.Combine(reference.Folder, ".git"))) { if (!forceUpgrade) { Console.WriteLine("Git submodule / repository already present at " + reference.Folder); return; } } this.EmptyReferenceFolder(reference.Folder); var package = m_PackageCache.GetSourcePackage(source, reference.GitRef); package.ExtractTo(reference.Folder); }
public int Execute(Execution execution) { var url = execution.PackageUrl; var module = ModuleInfo.Load(Path.Combine("Build", "Module.xml")); if (module.Packages == null) { module.Packages = new List <PackageRef>(); } var branch = "master"; if (url.LastIndexOf('@') > url.LastIndexOf('/')) { // A branch / commit ref is specified. branch = url.Substring(url.LastIndexOf('@') + 1); url = url.Substring(0, url.LastIndexOf('@')); } var uri = new Uri(url); var package = new PackageRef { Uri = url, GitRef = branch, Folder = uri.AbsolutePath.Trim('/').Split('/').Last() }; if (Directory.Exists(package.Folder)) { throw new InvalidOperationException(package.Folder + " already exists"); } if (module.Packages.Any(x => x.Uri == package.Uri)) { Console.WriteLine("WARNING: Package with URI " + package.Uri + " is already present; ignoring request to add package."); return(0); } Console.WriteLine("Adding " + url + " as " + package.Folder + "..."); module.Packages.Add(package); module.Save(Path.Combine("Build", "Module.xml")); return(0); }
public PackageRef Parse(string url) { var branch = "master"; if (url.LastIndexOf('@') > url.LastIndexOf('/') || (url.IndexOf('@') > 0 && url.IndexOf('/') == -1)) { // A branch / commit ref is specified. branch = url.Substring(url.LastIndexOf('@') + 1); url = url.Substring(0, url.LastIndexOf('@')); } try { var uri = new Uri(url); var folder = uri.AbsolutePath.Replace("%7C", "/").Replace('|', '/').Trim('/').Split('/').Last(); if (folder.EndsWith(".nupkg")) { folder = folder.Substring(0, folder.Length - ".nupkg".Length); } var package = new PackageRef { Uri = url, GitRef = branch, Folder = folder }; return(package); } catch (UriFormatException) { if (url.IndexOf("/") == -1) { // This is just a package name, not a full URI. Treat it as a NuGet v3 package reference. return(new PackageRef { Uri = "https-nuget-v3://api.nuget.org/v3/index.json|" + url, GitRef = branch, Folder = url }); } throw; } }
private void ResolveTemplateSource(PackageRef reference, string templateName, string source) { if (reference.Folder != string.Empty) { throw new InvalidOperationException("Reference folder must be empty for template type."); } if (Directory.Exists(".staging")) { PathUtils.AggressiveDirectoryDelete(".staging"); } var package = m_PackageCache.GetSourcePackage(source, reference.GitRef); package.ExtractTo(".staging"); this.ApplyProjectTemplateFromStaging(templateName); }
public int Execute(Execution execution) { var url = execution.PackageUrl; var module = ModuleInfo.Load(Path.Combine("Build", "Module.xml")); if (module.Packages == null) { module.Packages = new List<PackageRef>(); } var branch = "master"; if (url.LastIndexOf('@') > url.LastIndexOf('/')) { // A branch / commit ref is specified. branch = url.Substring(url.LastIndexOf('@') + 1); url = url.Substring(0, url.LastIndexOf('@')); } var uri = new Uri(url); var package = new PackageRef { Uri = url, GitRef = branch, Folder = uri.AbsolutePath.Trim('/').Split('/').Last() }; if (Directory.Exists(package.Folder)) { throw new InvalidOperationException(package.Folder + " already exists"); } if (module.Packages.Any(x => x.Uri == package.Uri)) { Console.WriteLine("WARNING: Package with URI " + package.Uri + " is already present; ignoring request to add package."); return 0; } Console.WriteLine("Adding " + url + " as " + package.Folder + "..."); module.Packages.Add(package); module.Save(Path.Combine("Build", "Module.xml")); return 0; }
public string DiscoverExistingPackagePath(string moduleRoot, PackageRef package, string platform) { var redirectedUri = _packageRedirector.RedirectPackageUrl(package.Uri); if (redirectedUri.StartsWith("local-pointer://", StringComparison.InvariantCultureIgnoreCase)) { // This is a locally redirected package, where the redirect goes straight to another folder // on the local computer (alternatively local-git:// will still clone from the target // folder, while this allows you to work on the target folder directly). return(redirectedUri.Substring("local-pointer://".Length)); } // Check the ModuleInfo.xml files of other modules in the // hierarchy in this order: // * Above us (this ensures the common libraries are at the highest point) // * Across from us (in the same folder) up to our name alphabetically // * Below us bool isNestedInPlatformFolder; var parentModule = this.GetParentModule(moduleRoot, platform, out isNestedInPlatformFolder); if (parentModule != null) { var above = this.CheckAbove(parentModule, package, platform); if (above != null) { return(above); } var directoryName = new DirectoryInfo(moduleRoot).Name; if (isNestedInPlatformFolder) { directoryName = new DirectoryInfo(Path.Combine(moduleRoot, "..")).Name; } var across = this.CheckAcross(parentModule, package, directoryName, platform); if (across != null) { return(across); } } return(null); }
public string DiscoverExistingPackagePath(string moduleRoot, PackageRef package, string platform) { var redirectedUri = _packageRedirector.RedirectPackageUrl(package.Uri); if (redirectedUri.StartsWith("local-pointer://", StringComparison.InvariantCultureIgnoreCase)) { // This is a locally redirected package, where the redirect goes straight to another folder // on the local computer (alternatively local-git:// will still clone from the target // folder, while this allows you to work on the target folder directly). return redirectedUri.Substring("local-pointer://".Length); } // Check the ModuleInfo.xml files of other modules in the // hierarchy in this order: // * Above us (this ensures the common libraries are at the highest point) // * Across from us (in the same folder) up to our name alphabetically // * Below us bool isNestedInPlatformFolder; var parentModule = this.GetParentModule(moduleRoot, platform, out isNestedInPlatformFolder); if (parentModule != null) { var above = this.CheckAbove(parentModule, package, platform); if (above != null) { return above; } var directoryName = new DirectoryInfo(moduleRoot).Name; if (isNestedInPlatformFolder) { directoryName = new DirectoryInfo(Path.Combine(moduleRoot, "..")).Name; } var across = this.CheckAcross(parentModule, package, directoryName, platform); if (across != null) { return across; } } return null; }
public int Execute(Execution execution) { if (File.Exists(Path.Combine("Build", "Module.xml"))) { throw new InvalidOperationException("This directory already has a module setup."); } var url = execution.StartProjectTemplateURL; var branch = "master"; if (url.LastIndexOf('@') > url.LastIndexOf('/')) { // A branch / commit ref is specified. branch = url.Substring(url.LastIndexOf('@') + 1); url = url.Substring(0, url.LastIndexOf('@')); } var packageRef = new PackageRef { Uri = url, GitRef = branch, Folder = string.Empty }; // The module can not be loaded before this point because it doesn't // yet exist. this.m_PackageManager.Resolve(null, packageRef, "Template", execution.StartProjectName, false); Console.WriteLine("Module has been initialized. Performing --generate to create projects."); var module = ModuleInfo.Load(Path.Combine("Build", "Module.xml")); return(this.m_ActionDispatch.PerformAction( module, "generate", execution.Platform, execution.EnabledServices.ToArray(), execution.DisabledServices.ToArray(), execution.ServiceSpecificationPath) ? 0 : 1); }
public PackageRef Parse(string url) { var branch = "master"; if (url.LastIndexOf('@') > url.LastIndexOf('/')) { // A branch / commit ref is specified. branch = url.Substring(url.LastIndexOf('@') + 1); url = url.Substring(0, url.LastIndexOf('@')); } var uri = new Uri(url); var package = new PackageRef { Uri = url, GitRef = branch, Folder = uri.AbsolutePath.Replace("%7C", "/").Replace('|', '/').Trim('/').Split('/').Last() }; return package; }
public string GetToolExecutablePath(string toolName) { var executableFile = _packageGlobalTool.ResolveGlobalToolIfPresent(toolName); if (executableFile == null && _knownTools.ContainsKey(toolName.ToLowerInvariant())) { var package = new PackageRef { Uri = _knownTools[toolName.ToLowerInvariant()], GitRef = "master", Folder = null }; Console.WriteLine("Installing {0}...", _knownTools[toolName.ToLowerInvariant()]); _packageManager.Resolve(null, package, _hostPlatformDetector.DetectPlatform(), null, false, true); } else { return executableFile; } return _packageGlobalTool.ResolveGlobalToolIfPresent(toolName); }
private string CheckAcross(string modulePath, PackageRef package, string originalDirectoryName) { var directory = new DirectoryInfo(modulePath); foreach (var subdirectory in directory.GetDirectories()) { if (string.Compare(subdirectory.Name, originalDirectoryName, StringComparison.InvariantCultureIgnoreCase) >= 0) { // This directory is either the original directory or // a directory with a later alphabetical order. We ignore // it (this is how we resolve whether A should use B's package // or B should use A's package). continue; } if (File.Exists(Path.Combine(subdirectory.FullName, "Build", "Module.xml"))) { var module = ModuleInfo.Load(Path.Combine(subdirectory.FullName, "Build", "Module.xml")); var found = module.Packages.Select(x => (PackageRef?)x) .FirstOrDefault(x => string.Compare(x.Value.Uri, package.Uri, StringComparison.InvariantCulture) == 0); if (found != null) { return(Path.Combine(subdirectory.FullName, found.Value.Folder)); } var submodules = module.GetSubmodules(); foreach (var submodule in submodules) { var below = this.CheckBelow(submodule.Path, package); if (below != null) { return(below); } } } } return(null); }
public PackageRef Parse(string url) { var branch = "master"; if (url.LastIndexOf('@') > url.LastIndexOf('/')) { // A branch / commit ref is specified. branch = url.Substring(url.LastIndexOf('@') + 1); url = url.Substring(0, url.LastIndexOf('@')); } var uri = new Uri(url); var package = new PackageRef { Uri = url, GitRef = branch, Folder = uri.AbsolutePath.Replace("%7C", "/").Replace('|', '/').Trim('/').Split('/').Last() }; return(package); }
public string GetToolExecutablePath(string toolName) { var executableFile = _packageGlobalTool.ResolveGlobalToolIfPresent(toolName); if (executableFile == null && _knownTools.ContainsKey(toolName.ToLowerInvariant())) { var package = new PackageRef { Uri = _knownTools[toolName.ToLowerInvariant()], GitRef = "master", Folder = null }; RedirectableConsole.WriteLine("Installing {0}...", _knownTools[toolName.ToLowerInvariant()]); _packageManager.Resolve(Environment.CurrentDirectory, null, package, _hostPlatformDetector.DetectPlatform(), null, false, true, false); } else { return(executableFile); } return(_packageGlobalTool.ResolveGlobalToolIfPresent(toolName)); }
private string CheckAbove(string modulePath, PackageRef package, string platform) { var module = ModuleInfo.Load(Path.Combine(modulePath, "Build", "Module.xml")); var found = module.Packages.Select(x => (PackageRef?)x) .FirstOrDefault(x => string.Compare(x.Value.Uri, package.Uri, StringComparison.InvariantCulture) == 0); if (found != null) { return(Path.Combine(modulePath, found.Value.Folder)); } bool isNestedInPlatformFolder; var parent = this.GetParentModule(modulePath, platform, out isNestedInPlatformFolder); if (parent != null) { var above = this.CheckAbove(parent, package, platform); if (above != null) { return(above); } var directoryName = new DirectoryInfo(modulePath).Name; if (isNestedInPlatformFolder) { directoryName = new DirectoryInfo(Path.Combine(modulePath, "..")).Name; } var across = this.CheckAcross(parent, package, directoryName, platform); if (across != null) { return(across); } } return(null); }
private string CheckBelow(string modulePath, PackageRef package, string platform) { var module = ModuleInfo.Load(Path.Combine(modulePath, "Build", "Module.xml")); var found = module.Packages.Select(x => (PackageRef?)x) .FirstOrDefault(x => string.Compare(x.Value.Uri, package.Uri, StringComparison.InvariantCulture) == 0); if (found != null) { return(Path.Combine(modulePath, found.Value.Folder)); } var submodules = module.GetSubmodules(); foreach (var submodule in submodules) { var below = this.CheckBelow(submodule.Path, package, platform); if (below != null) { return(below); } } return(null); }
public int Execute(Execution execution) { var url = execution.PackageUrl; var branch = "master"; if (url.LastIndexOf('@') > url.LastIndexOf('/')) { // A branch / commit ref is specified. branch = url.Substring(url.LastIndexOf('@') + 1); url = url.Substring(0, url.LastIndexOf('@')); } var package = new PackageRef { Uri = url, GitRef = branch, Folder = null }; Console.WriteLine("Installing " + url + "..."); this.m_PackageManager.Resolve(null, package, this.m_HostPlatformDetector.DetectPlatform(), null, false, true); return 0; }
private static ModuleInfo LoadInternal(XDocument doc, string modulePath, Func <ModuleInfo> fallback) { var def = new ModuleInfo(); var xsi = doc.Root == null ? null : doc.Root.Attribute(XName.Get("xsi", "http://www.w3.org/2000/xmlns/")); if (xsi != null && xsi.Value == "http://www.w3.org/2001/XMLSchema-instance") { return(fallback()); } Func <string, string> getStringValue = name => { if (doc.Root == null) { return(null); } var elem = doc.Root.Element(XName.Get(name)); if (elem == null) { return(null); } return(elem.Value); }; def.Name = getStringValue("Name"); def.Path = modulePath; def.DefaultAction = getStringValue("DefaultAction"); def.DefaultLinuxPlatforms = getStringValue("DefaultLinuxPlatforms"); def.DefaultMacOSPlatforms = getStringValue("DefaultMacOSPlatforms"); def.DefaultWindowsPlatforms = getStringValue("DefaultWindowsPlatforms"); def.DefaultStartupProject = getStringValue("DefaultStartupProject"); def.SupportedPlatforms = getStringValue("SupportedPlatforms"); def.DisableSynchronisation = getStringValue("DisableSynchronisation") == "true"; def.GenerateNuGetRepositories = getStringValue("GenerateNuGetRepositories") == "true"; def.Packages = new List <PackageRef>(); if (doc.Root != null) { var packagesElem = doc.Root.Element(XName.Get("Packages")); if (packagesElem != null) { var packages = packagesElem.Elements(); foreach (var package in packages) { var packageRef = new PackageRef { Folder = package.Attribute(XName.Get("Folder")).Value, GitRef = package.Attribute(XName.Get("GitRef")).Value, Uri = package.Attribute(XName.Get("Uri")).Value, Platforms = null, }; var platforms = package.Attribute(XName.Get("Platforms")); var platformsArray = platforms?.Value.Split(','); if (platformsArray?.Length > 0) { packageRef.Platforms = platformsArray; } def.Packages.Add(packageRef); } } var featureSetElem = doc.Root.Element(XName.Get("FeatureSet")); if (featureSetElem != null) { def.FeatureSet = new List <Feature>(); var features = featureSetElem.Elements(); foreach (var feature in features) { def.FeatureSet.Add((Feature)Enum.Parse(typeof(Feature), feature.Value)); } } else { def.FeatureSet = null; } // Check if the feature set is present and if it does not contain // the PackageManagement feature. If that feature isn't there, we // ignore any of the data in Packages and just set the value to // an empty list. if (def.FeatureSet != null && !def.FeatureSet.Contains(Feature.PackageManagement)) { def.Packages.Clear(); } } return(def); }
private void ResolveLibraryBinary(PackageRef reference, string platform, string source, bool forceUpgrade) { if (File.Exists(Path.Combine(reference.Folder, platform, ".pkg"))) { if (!forceUpgrade) { Console.WriteLine("Protobuild binary package already present at " + Path.Combine(reference.Folder, platform)); return; } } var folder = Path.Combine(reference.Folder, platform); Console.WriteLine("Creating and emptying " + folder); if (File.Exists(Path.Combine(reference.Folder, ".pkg"))) { if (Directory.Exists(folder)) { // Only clear out the target's folder if the reference folder // already contains binary packages (for other platforms) this.EmptyReferenceFolder(folder); } } else { // The reference folder is holding source code, so clear it // out entirely. this.EmptyReferenceFolder(reference.Folder); } Directory.CreateDirectory(folder); Console.WriteLine("Marking " + reference.Folder + " as ignored for Git"); GitUtils.MarkIgnored(reference.Folder); var package = m_PackageCache.GetBinaryPackage(reference.Uri, reference.GitRef, platform); if (package == null) { this.ResolveLibrarySource(reference, source, forceUpgrade); return; } package.ExtractTo(folder); // Only copy ourselves to the binary folder if both "Build/Module.xml" and // "Build/Projects" exist in the binary package's folder. This prevents us // from triggering the "create new module?" logic if the package hasn't been // setup correctly. if (Directory.Exists(Path.Combine(folder, "Build", "Projects")) && File.Exists(Path.Combine(folder, "Build", "Module.xml"))) { var sourceProtobuild = Assembly.GetEntryAssembly().Location; File.Copy(sourceProtobuild, Path.Combine(folder, "Protobuild.exe"), true); try { var chmodStartInfo = new ProcessStartInfo { FileName = "chmod", Arguments = "a+x Protobuild.exe", WorkingDirectory = folder, CreateNoWindow = true, UseShellExecute = false }; Process.Start(chmodStartInfo); } catch (ExecEnvironment.SelfInvokeExitException) { throw; } catch { } } var file = File.Create(Path.Combine(folder, ".pkg")); file.Close(); file = File.Create(Path.Combine(reference.Folder, ".pkg")); file.Close(); Console.WriteLine("Binary resolution complete"); }
public void Resolve(ModuleInfo module, PackageRef reference, string platform, string templateName, bool? source, bool forceUpgrade = false) { if (module != null && reference.Folder != null) { var existingPath = this.m_PackageLocator.DiscoverExistingPackagePath(module.Path, reference, platform); if (existingPath != null) { Console.WriteLine("Found an existing working copy of this package at " + existingPath); Directory.CreateDirectory(reference.Folder); using (var writer = new StreamWriter(Path.Combine(reference.Folder, ".redirect"))) { writer.WriteLine(existingPath); } return; } else { if (File.Exists(Path.Combine(reference.Folder, ".redirect"))) { try { File.Delete(Path.Combine(reference.Folder, ".redirect")); } catch { } } } } if (reference.Folder == null) { Console.WriteLine("Resolving package with null reference folder; this package must be a global tool."); } string sourceUri, type; Dictionary<string, string> downloadMap, archiveTypeMap, resolvedHash; IPackageTransformer transformer; _packageLookup.Lookup( reference.Uri, platform, !forceUpgrade && reference.IsCommitReference, out sourceUri, out type, out downloadMap, out archiveTypeMap, out resolvedHash, out transformer); // Resolve Git reference to Git commit hash. var refUri = reference.Uri; var refFolder = reference.Folder; var gitCommit = resolvedHash.ContainsKey(reference.GitRef) ? resolvedHash[reference.GitRef] : reference.GitRef; reference = new PackageRef { Uri = refUri, Folder = refFolder, GitRef = gitCommit }; string toolFolder = null; if (type == PackageManager.PACKAGE_TYPE_TEMPLATE && templateName == null) { throw new InvalidOperationException( "Template referenced as part of module packages. Templates can only be used " + "with the --start option."); } else if (type == PackageManager.PACKAGE_TYPE_LIBRARY) { Directory.CreateDirectory(reference.Folder); if (source == null) { if (File.Exists(Path.Combine(reference.Folder, ".git")) || Directory.Exists(Path.Combine(reference.Folder, ".git"))) { Console.WriteLine("Git repository present at " + Path.Combine(reference.Folder, ".git") + "; leaving as source version."); source = true; } else { Console.WriteLine("Package type not specified (and no file at " + Path.Combine(reference.Folder, ".git") + "), requesting binary version."); source = false; } } } else if (type == PackageManager.PACKAGE_TYPE_GLOBAL_TOOL) { toolFolder = this.m_PackageGlobalTool.GetGlobalToolInstallationPath(reference); source = false; } if (source.Value && !string.IsNullOrWhiteSpace(sourceUri)) { switch (type) { case PackageManager.PACKAGE_TYPE_LIBRARY: this.ResolveLibrarySource(reference, sourceUri, forceUpgrade); break; case PackageManager.PACKAGE_TYPE_TEMPLATE: this.ResolveTemplateSource(reference, templateName, sourceUri); break; } } else { switch (type) { case PackageManager.PACKAGE_TYPE_LIBRARY: this.ResolveLibraryBinary(reference, platform, sourceUri, forceUpgrade); break; case PackageManager.PACKAGE_TYPE_TEMPLATE: this.ResolveTemplateBinary(reference, templateName, platform, sourceUri); break; case PackageManager.PACKAGE_TYPE_GLOBAL_TOOL: this.ResolveGlobalToolBinary(reference, toolFolder, platform, forceUpgrade); break; } } }
private void ResolveTemplateBinary(PackageRef reference, string templateName, string platform, string sourceUri) { if (reference.Folder != string.Empty) { throw new InvalidOperationException("Reference folder must be empty for template type."); } if (Directory.Exists(".staging")) { PathUtils.AggressiveDirectoryDelete(".staging"); } Directory.CreateDirectory(".staging"); var package = m_PackageCache.GetBinaryPackage(reference.Uri, reference.GitRef, platform); if (package == null) { this.ResolveTemplateSource(reference, templateName, sourceUri); return; } package.ExtractTo(".staging"); ApplyProjectTemplateFromStaging(templateName); }
public void Resolve(string workingDirectory, IPackageMetadata metadata, PackageRef reference, string templateName, bool?source, bool forceUpgrade, bool?safeResolve) { if (reference.Folder == null) { if (metadata.PackageType == PACKAGE_TYPE_GLOBAL_TOOL) { } else { throw new InvalidOperationException( "No target folder was provided for package resolution, and the resulting package is not " + "a global tool."); } } else { if (metadata.PackageType == PackageManager.PACKAGE_TYPE_TEMPLATE && templateName == null) { throw new InvalidOperationException( "Template referenced as part of module packages. Templates can only be used " + "with the --start option."); } else if (metadata.PackageType == PackageManager.PACKAGE_TYPE_LIBRARY) { Directory.CreateDirectory(Path.Combine(workingDirectory, reference.Folder)); if (new DirectoryInfo(Path.Combine(workingDirectory, reference.Folder)).GetFiles().Length > 0 || new DirectoryInfo(Path.Combine(workingDirectory, reference.Folder)).GetDirectories().Length > 0) { if (!File.Exists(Path.Combine(workingDirectory, reference.Folder, ".git")) && !Directory.Exists(Path.Combine(workingDirectory, reference.Folder, ".git")) && !File.Exists(Path.Combine(workingDirectory, reference.Folder, ".pkg"))) { bool shouldSafeResolve; if (safeResolve.HasValue) { // If the user specifies it on the command line, use that setting. shouldSafeResolve = safeResolve.Value; } else { if (!_featureManager.IsFeatureEnabled(Feature.SafeResolutionDisabled)) { // If the module doesn't have this feature set enabled, we default // to using safe package resolution. shouldSafeResolve = true; } else { // If the module does have this feature set enabled, or is using the // full feature set, we default to turning safe resolution off. shouldSafeResolve = false; } } if (shouldSafeResolve) { RedirectableConsole.ErrorWriteLine( "WARNING: The package directory '" + reference.Folder + "' already exists and contains " + "files and/or subdirectories, but neither a .pkg file nor a .git file or subdirectory exists. " + "This indicates the package directory contains data that is not been instantiated or managed " + "by Protobuild. Since there is no safe way to initialize the package in this directory " + "without a potential loss of data, Protobuild will not modify the contents of this folder " + "during package resolution. If the folder does not contains the required package " + "dependencies, the project generation or build may unexpectedly fail."); return; } } } if (source == null) { if (File.Exists(Path.Combine(workingDirectory, reference.Folder, ".git")) || Directory.Exists(Path.Combine(workingDirectory, reference.Folder, ".git"))) { RedirectableConsole.WriteLine("Git repository present at " + Path.Combine(workingDirectory, reference.Folder, ".git") + "; leaving as source version."); source = true; } else { RedirectableConsole.WriteLine("Package type not specified (and no file at " + Path.Combine(workingDirectory, reference.Folder, ".git") + "), requesting binary version."); source = false; } } } } metadata.Resolve(workingDirectory, metadata, reference.Folder, templateName, forceUpgrade, source); }
private string CheckBelow(string modulePath, PackageRef package, string platform) { var module = ModuleInfo.Load(Path.Combine(modulePath, "Build", "Module.xml")); var found = module.Packages.Select(x => (PackageRef?)x) .FirstOrDefault(x => string.Compare(x.Value.Uri, package.Uri, StringComparison.InvariantCulture) == 0); if (found != null) { return Path.Combine(modulePath, found.Value.Folder); } var submodules = module.GetSubmodules(); foreach (var submodule in submodules) { var below = this.CheckBelow(submodule.Path, package, platform); if (below != null) { return below; } } return null; }
public void Resolve(ModuleInfo module, PackageRef reference, string platform, string templateName, bool?source, bool forceUpgrade = false) { if (module != null) { var existingPath = this.m_PackageLocator.DiscoverExistingPackagePath(module.Path, reference); if (existingPath != null) { Console.WriteLine("Found an existing working copy of this package at " + existingPath); Directory.CreateDirectory(reference.Folder); using (var writer = new StreamWriter(Path.Combine(reference.Folder, ".redirect"))) { writer.WriteLine(existingPath); } return; } else { if (File.Exists(Path.Combine(reference.Folder, ".redirect"))) { try { File.Delete(Path.Combine(reference.Folder, ".redirect")); } catch { } } } } string sourceUri, type; Dictionary <string, string> downloadMap, archiveTypeMap, resolvedHash; _packageLookup.Lookup( reference.Uri, platform, true, out sourceUri, out type, out downloadMap, out archiveTypeMap, out resolvedHash); if (type == PackageManager.PACKAGE_TYPE_TEMPLATE && templateName == null) { throw new InvalidOperationException( "Template referenced as part of module packages. Templates can only be used " + "with the --start option."); } else if (type == PackageManager.PACKAGE_TYPE_LIBRARY) { Directory.CreateDirectory(reference.Folder); if (source == null) { if (File.Exists(Path.Combine(reference.Folder, ".git")) || Directory.Exists(Path.Combine(reference.Folder, ".git"))) { Console.WriteLine("Git repository present at " + Path.Combine(reference.Folder, ".git") + "; leaving as source version."); source = true; } else { Console.WriteLine("Package type not specified (and no file at " + Path.Combine(reference.Folder, ".git") + "), requesting binary version."); source = false; } } } if (source.Value && !string.IsNullOrWhiteSpace(sourceUri)) { switch (type) { case PackageManager.PACKAGE_TYPE_LIBRARY: this.ResolveLibrarySource(reference, sourceUri, forceUpgrade); break; case PackageManager.PACKAGE_TYPE_TEMPLATE: this.ResolveTemplateSource(reference, templateName, sourceUri); break; } } else { switch (type) { case PackageManager.PACKAGE_TYPE_LIBRARY: this.ResolveLibraryBinary(reference, platform, sourceUri, forceUpgrade); break; case PackageManager.PACKAGE_TYPE_TEMPLATE: this.ResolveTemplateBinary(reference, templateName, platform, sourceUri); break; } } }
private static ModuleInfo LoadInternal(XDocument doc, string modulePath, Func <ModuleInfo> fallback) { var def = new ModuleInfo(); var xsi = doc.Root == null ? null : doc.Root.Attribute(XName.Get("xsi", "http://www.w3.org/2000/xmlns/")); if (xsi != null && xsi.Value == "http://www.w3.org/2001/XMLSchema-instance") { return(fallback()); } Func <string, string> getStringValue = name => { if (doc.Root == null) { return(null); } var elem = doc.Root.Element(XName.Get(name)); if (elem == null) { return(null); } return(elem.Value); }; def.Name = getStringValue("Name"); def.Authors = getStringValue("Authors"); def.Description = getStringValue("Description"); def.ProjectUrl = getStringValue("ProjectUrl"); def.LicenseUrl = getStringValue("LicenseUrl"); def.IconUrl = getStringValue("IconUrl"); def.GitRepositoryUrl = getStringValue("GitRepositoryUrl"); def.SemanticVersion = getStringValue("SemanticVersion"); def.Path = modulePath; def.DefaultAction = getStringValue("DefaultAction"); def.DefaultLinuxPlatforms = getStringValue("DefaultLinuxPlatforms"); def.DefaultMacOSPlatforms = getStringValue("DefaultMacOSPlatforms"); def.DefaultWindowsPlatforms = getStringValue("DefaultWindowsPlatforms"); def.DefaultStartupProject = getStringValue("DefaultStartupProject"); def.SupportedPlatforms = getStringValue("SupportedPlatforms"); def.DisableSynchronisation = getStringValue("DisableSynchronisation") == "true"; def.GenerateNuGetRepositories = getStringValue("GenerateNuGetRepositories") == "true"; def.Packages = new List <PackageRef>(); if (doc.Root != null) { var packagesElem = doc.Root.Element(XName.Get("Packages")); if (packagesElem != null) { var packages = packagesElem.Elements(); foreach (var package in packages) { var folder = package.Attribute(XName.Get("Folder"))?.Value; var gitRef = package.Attribute(XName.Get("GitRef"))?.Value; var uri = package.Attribute(XName.Get("Uri"))?.Value; var repository = package.Attribute(XName.Get("Repository"))?.Value; var packageName = package.Attribute(XName.Get("Package"))?.Value; var version = package.Attribute(XName.Get("Version"))?.Value; if (!string.IsNullOrWhiteSpace(repository) && !string.IsNullOrWhiteSpace(packageName) && !string.IsNullOrWhiteSpace(version)) { // This is NuGet v3 package. Rather than writing a different interface, // we just automatically form a URI that complies with the rest of the // package resolution system. uri = repository; if (!string.IsNullOrWhiteSpace(uri)) { uri = uri.Replace("https://", "https-nuget-v3://"); uri = uri.Replace("http://", "http-nuget-v3://"); uri += $"|{packageName}"; } gitRef = version; } if (string.IsNullOrWhiteSpace(folder) && !string.IsNullOrWhiteSpace(packageName)) { folder = packageName; } if (string.IsNullOrWhiteSpace(folder) || string.IsNullOrWhiteSpace(gitRef) || string.IsNullOrWhiteSpace(uri)) { RedirectableConsole.ErrorWriteLine("WARNING: Invalid package declaration in module; skipping package."); continue; } var packageRef = new PackageRef { Folder = folder, GitRef = gitRef, Uri = uri, Platforms = null, }; var platforms = package.Attribute(XName.Get("Platforms")); var platformsArray = platforms?.Value.Split(','); if (platformsArray?.Length > 0) { packageRef.Platforms = platformsArray; } def.Packages.Add(packageRef); } } var featureSetElem = doc.Root.Element(XName.Get("FeatureSet")); if (featureSetElem != null) { def.FeatureSet = new List <Feature>(); var features = featureSetElem.Elements(); foreach (var feature in features) { try { def.FeatureSet.Add((Feature)Enum.Parse(typeof(Feature), feature.Value)); } catch { RedirectableConsole.ErrorWriteLine("Unknown feature in Module.xml; ignoring: " + feature.Value); } } } else { def.FeatureSet = null; } // Check if the feature set is present and if it does not contain // the PackageManagement feature. If that feature isn't there, we // ignore any of the data in Packages and just set the value to // an empty list. if (def.FeatureSet != null && !def.FeatureSet.Contains(Feature.PackageManagement)) { def.Packages.Clear(); } } return(def); }
private void ResolveGlobalToolBinary(PackageRef reference, string toolFolder, string platform, bool forceUpgrade) { if (File.Exists(Path.Combine(toolFolder, ".pkg"))) { if (!forceUpgrade) { Console.WriteLine("Protobuild binary package already present at " + toolFolder); return; } } Console.WriteLine("Creating and emptying " + toolFolder); this.EmptyReferenceFolder(toolFolder); Directory.CreateDirectory(toolFolder); Console.WriteLine("Installing " + reference.Uri + " at " + reference.GitRef); var package = m_PackageCache.GetBinaryPackage(reference.Uri, reference.GitRef, platform); if (package == null) { Console.WriteLine("The specified global tool package is not available for this platform."); return; } package.ExtractTo(toolFolder); var file = File.Create(Path.Combine(toolFolder, ".pkg")); file.Close(); this.m_PackageGlobalTool.ScanPackageForToolsAndInstall(toolFolder); Console.WriteLine("Binary resolution complete"); }
public void Resolve(ModuleInfo module, PackageRef reference, string platform, string templateName, bool? source, bool forceUpgrade = false) { if (!_featureManager.IsFeatureEnabled(Feature.PackageManagement)) { return; } if (module != null && reference.Folder != null) { var existingPath = this.m_PackageLocator.DiscoverExistingPackagePath(module.Path, reference, platform); if (existingPath != null && Directory.Exists(existingPath)) { Console.WriteLine("Found an existing working copy of this package at " + existingPath); Directory.CreateDirectory(reference.Folder); using (var writer = new StreamWriter(Path.Combine(reference.Folder, ".redirect"))) { writer.WriteLine(existingPath); } return; } else { if (File.Exists(Path.Combine(reference.Folder, ".redirect"))) { try { File.Delete(Path.Combine(reference.Folder, ".redirect")); } catch { } } } } var request = new PackageRequestRef( reference.Uri, reference.GitRef, platform, !forceUpgrade && reference.IsCommitReference); var metadata = _packageLookup.Lookup(request); string toolFolder = null; if (reference.Folder == null) { if (metadata.PackageType == PACKAGE_TYPE_GLOBAL_TOOL) { } else { throw new InvalidOperationException( "No target folder was provided for package resolution, and the resulting package is not " + "a global tool."); } } else { if (metadata.PackageType == PackageManager.PACKAGE_TYPE_TEMPLATE && templateName == null) { throw new InvalidOperationException( "Template referenced as part of module packages. Templates can only be used " + "with the --start option."); } else if (metadata.PackageType == PackageManager.PACKAGE_TYPE_LIBRARY) { Directory.CreateDirectory(reference.Folder); if (new DirectoryInfo(reference.Folder).GetFiles().Length > 0 || new DirectoryInfo(reference.Folder).GetDirectories().Length > 0) { if (!File.Exists(Path.Combine(reference.Folder, ".git")) && !Directory.Exists(Path.Combine(reference.Folder, ".git")) && !File.Exists(Path.Combine(reference.Folder, ".pkg"))) { Console.Error.WriteLine( "WARNING: The package directory '" + reference.Folder + "' already exists and contains " + "files and/or subdirectories, but neither a .pkg file nor a .git file or subdirectory exists. " + "This indicates the package directory contains data that is not been instantiated or managed " + "by Protobuild. Since there is no safe way to initialize the package in this directory " + "without a potential loss of data, Protobuild will not modify the contents of this folder " + "during package resolution. If the folder does not contains the required package " + "dependencies, the project generation or build may unexpectedly fail."); return; } } if (source == null) { if (File.Exists(Path.Combine(reference.Folder, ".git")) || Directory.Exists(Path.Combine(reference.Folder, ".git"))) { Console.WriteLine("Git repository present at " + Path.Combine(reference.Folder, ".git") + "; leaving as source version."); source = true; } else { Console.WriteLine("Package type not specified (and no file at " + Path.Combine(reference.Folder, ".git") + "), requesting binary version."); source = false; } } } } metadata.Resolve(metadata, reference.Folder, templateName, forceUpgrade, source); }
public void Resolve(ModuleInfo module, PackageRef reference, string platform, string templateName, bool?source, bool forceUpgrade = false) { if (!_featureManager.IsFeatureEnabled(Feature.PackageManagement)) { return; } if (module != null && reference.Folder != null) { var existingPath = this.m_PackageLocator.DiscoverExistingPackagePath(module.Path, reference, platform); if (existingPath != null && Directory.Exists(existingPath)) { Console.WriteLine("Found an existing working copy of this package at " + existingPath); Directory.CreateDirectory(reference.Folder); using (var writer = new StreamWriter(Path.Combine(reference.Folder, ".redirect"))) { writer.WriteLine(existingPath); } return; } else { if (File.Exists(Path.Combine(reference.Folder, ".redirect"))) { try { File.Delete(Path.Combine(reference.Folder, ".redirect")); } catch { } } } } var request = new PackageRequestRef( reference.Uri, reference.GitRef, platform, !forceUpgrade && reference.IsCommitReference); var metadata = _packageLookup.Lookup(request); string toolFolder = null; if (reference.Folder == null) { if (metadata.PackageType == PACKAGE_TYPE_GLOBAL_TOOL) { } else { throw new InvalidOperationException( "No target folder was provided for package resolution, and the resulting package is not " + "a global tool."); } } else { if (metadata.PackageType == PackageManager.PACKAGE_TYPE_TEMPLATE && templateName == null) { throw new InvalidOperationException( "Template referenced as part of module packages. Templates can only be used " + "with the --start option."); } else if (metadata.PackageType == PackageManager.PACKAGE_TYPE_LIBRARY) { Directory.CreateDirectory(reference.Folder); if (new DirectoryInfo(reference.Folder).GetFiles().Length > 0 || new DirectoryInfo(reference.Folder).GetDirectories().Length > 0) { if (!File.Exists(Path.Combine(reference.Folder, ".git")) && !Directory.Exists(Path.Combine(reference.Folder, ".git")) && !File.Exists(Path.Combine(reference.Folder, ".pkg"))) { Console.Error.WriteLine( "WARNING: The package directory '" + reference.Folder + "' already exists and contains " + "files and/or subdirectories, but neither a .pkg file nor a .git file or subdirectory exists. " + "This indicates the package directory contains data that is not been instantiated or managed " + "by Protobuild. Since there is no safe way to initialize the package in this directory " + "without a potential loss of data, Protobuild will not modify the contents of this folder " + "during package resolution. If the folder does not contains the required package " + "dependencies, the project generation or build may unexpectedly fail."); return; } } if (source == null) { if (File.Exists(Path.Combine(reference.Folder, ".git")) || Directory.Exists(Path.Combine(reference.Folder, ".git"))) { Console.WriteLine("Git repository present at " + Path.Combine(reference.Folder, ".git") + "; leaving as source version."); source = true; } else { Console.WriteLine("Package type not specified (and no file at " + Path.Combine(reference.Folder, ".git") + "), requesting binary version."); source = false; } } } } metadata.Resolve(metadata, reference.Folder, templateName, forceUpgrade, source); }