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

Update MavenProjectManager to override the PackageVersionExistsAsync method #409

Merged
merged 1 commit into from
Mar 14, 2023
Merged
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
35 changes: 35 additions & 0 deletions src/Shared/PackageManagers/MavenProjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,41 @@ public override async Task<IEnumerable<string>> EnumerateVersionsAsync(PackageUR
}
}

/// <inheritdoc />
public override async Task<bool> PackageVersionExistsAsync(PackageURL purl, bool useCache = true)
{
Logger.Trace("PackageVersionExists {0}", purl?.ToString());
if (purl is null || purl.Name is null || purl.Namespace is null)
{
return false;
}
try
{
string packageNamespace = purl.Namespace.Replace('.', '/');
string packageName = purl.Name;
string feedUrl = (purl?.Qualifiers?["repository_url"] ?? ENV_MAVEN_ENDPOINT).EnsureTrailingSlash();
HttpClient httpClient = CreateHttpClient();

string? content = await GetHttpStringCache(httpClient, $"{feedUrl}{packageNamespace}/{packageName}/{purl.Version}/", useCache);
if (string.IsNullOrWhiteSpace(content))
{
return false;
}

return true;
}
catch (HttpRequestException ex) when (ex.StatusCode == HttpStatusCode.NotFound)
{
Logger.Debug("Package version doesn't exist (404): {0}", ex.Message);
return false;
}
catch (Exception ex)
{
Logger.Debug("Unable to check for version existence: {0}", ex.Message);
throw;
}
}

/// <inheritdoc />
public override async Task<string?> GetMetadataAsync(PackageURL purl, bool useCache = true)
{
Expand Down