From cbcb942e57278d90d297791fdcb7628fa7aeb364 Mon Sep 17 00:00:00 2001 From: Aleksi Juvani Date: Thu, 6 Apr 2017 18:47:13 +0300 Subject: [PATCH] Validate NuGet package names with the NuGet API --- src/actions/vstudio/vs2010_nuget.lua | 30 ++++++++++++++++++++++++++++ src/base/validation.lua | 6 ++++++ 2 files changed, 36 insertions(+) diff --git a/src/actions/vstudio/vs2010_nuget.lua b/src/actions/vstudio/vs2010_nuget.lua index 1aa23797..c61d38f6 100644 --- a/src/actions/vstudio/vs2010_nuget.lua +++ b/src/actions/vstudio/vs2010_nuget.lua @@ -41,6 +41,36 @@ end + local validatedPackages = {} + + function nuget2010.validatePackages(prj) + if #prj.nuget == 0 then + return + end + + for _, package in ipairs(prj.nuget) do + local id = nuget2010.packageId(package) + local version = nuget2010.packageVersion(package) + + if not validatedPackages[id] then + printf("Examining NuGet package '%s'...", id) + io.flush() + + local response, err, code = http.get(string.format("https://api.nuget.org/v3/registration1/%s/index.json", id:lower())) + + if err ~= "OK" then + if code == 404 then + p.error("NuGet package '%s' for project '%s' couldn't be found in the repository", id, prj.name) + else + p.error("NuGet API error (%d)\n%s", code, err) + end + end + end + validatedPackages[id] = package + end + end + + -- -- Generates the packages.config file. -- diff --git a/src/base/validation.lua b/src/base/validation.lua index 1744fc77..4ef19290 100644 --- a/src/base/validation.lua +++ b/src/base/validation.lua @@ -61,6 +61,7 @@ m.actionSupportsKind, m.projectRulesExist, m.projectValuesInScope, + m.projectNuGetPackages, } end @@ -223,6 +224,11 @@ end + function m.projectNuGetPackages(prj) + p.vstudio.nuget2010.validatePackages(prj) + end + + function m.uniqueProjectIds(wks) local uuids = {} for prj in p.workspace.eachproject(wks) do