Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "CLI: Add nightly package source to the package source mappings" #18999

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ private async Task SwitchSolutionsToStable(List<string> solutionPaths)
var solutionAngularFolder = GetSolutionAngularFolder(solutionFolder);

_packageSourceManager.Remove(solutionFolder, "ABP Nightly");
_packageSourceManager.RemovePackageSourceMapping(solutionFolder, "ABP Nightly");

await _nugetPackagesVersionUpdater.UpdateSolutionAsync(
solutionPath,
Expand Down Expand Up @@ -178,13 +177,10 @@ private async Task SwitchProjectsToNightlyPreview(List<string> projects)
foreach (var project in projects)
{
var folder = Path.GetDirectoryName(project);
var solutionFolder = FindSolutionFolder(project) ?? folder;

_packageSourceManager.Add(solutionFolder, "ABP Nightly",
_packageSourceManager.Add(FindSolutionFolder(project) ?? folder, "ABP Nightly",
"https://www.myget.org/F/abp-nightly/api/v3/index.json");

_packageSourceManager.AddPackageSourceMapping(solutionFolder, "ABP Nightly", "Volo.*");

await _nugetPackagesVersionUpdater.UpdateSolutionAsync(
project,
true);
Expand All @@ -204,8 +200,6 @@ private async Task SwitchSolutionsToNightlyPreview(List<string> solutionPaths)

_packageSourceManager.Add(solutionFolder, "ABP Nightly",
"https://www.myget.org/F/abp-nightly/api/v3/index.json");

_packageSourceManager.AddPackageSourceMapping(solutionFolder, "ABP Nightly", "Volo.*");

if (solutionPath != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,88 +108,6 @@ public void Remove(string solutionFolder, string sourceKey)
}
}

public void AddPackageSourceMapping(string solutionFolder, string sourceKey, string sourceValue)
{
var nugetConfigPath = GetNugetConfigPath(solutionFolder);
if (!File.Exists(nugetConfigPath))
{
return;
}

var fileContent = File.ReadAllText(nugetConfigPath);
if (fileContent.Contains($"<packageSource key=\"{sourceKey}\">"))
{
return;
}

try
{
var doc = new XmlDocument() { PreserveWhitespace = true };

doc.Load(GenerateStreamFromString(fileContent));

var sourceNodes = doc.SelectNodes("/configuration/packageSourceMapping");

var newNode = doc.CreateElement("packageSource");

var keyAttr = doc.CreateAttribute("key");
keyAttr.Value = sourceKey;
newNode.Attributes.Append(keyAttr);

var packageNode = doc.CreateElement("package");

var patternAttr = doc.CreateAttribute("pattern");
patternAttr.Value = sourceValue;
packageNode.Attributes.Append(patternAttr);

newNode.AppendChild(packageNode);

sourceNodes?[0]?.AppendChild(newNode);

File.WriteAllText(nugetConfigPath, doc.OuterXml);
}
catch
{
Logger.LogWarning($"Adding \"{sourceValue}\" ({sourceKey}) to package source mapping FAILED.");
}
}

public void RemovePackageSourceMapping(string solutionFolder, string sourceKey)
{
var nugetConfigPath = GetNugetConfigPath(solutionFolder);
if (!File.Exists(nugetConfigPath))
{
return;
}

var fileContent = File.ReadAllText(nugetConfigPath);
if (!fileContent.Contains($"<packageSource key=\"{sourceKey}\">"))
{
return;
}

Logger.LogInformation($"Removing \"{sourceKey}\" from nuget package source mappings...");

try
{
var doc = new XmlDocument() { PreserveWhitespace = true };

doc.Load(GenerateStreamFromString(fileContent));

var nodes = doc.SelectNodes($"/configuration/packageSourceMapping/packageSource[@key='{sourceKey}']");
if (nodes != null && nodes.Count > 0)
{
nodes[0]!.ParentNode?.RemoveChild(nodes[0]);
}

File.WriteAllText(nugetConfigPath, doc.OuterXml);
}
catch
{
Logger.LogWarning($"Removing \"{sourceKey}\" from package source mappings FAILED.");
}
}

private static string GetNugetConfigPath(string solutionFolder)
{
return Path.Combine(solutionFolder, "NuGet.Config");
Expand Down
Loading