Skip to content

Commit 76a0a93

Browse files
authored
Merge pull request #9 from jpobst/populate
Allow MavenCentral repo to bypass 100 artifact limit.
2 parents 527d493 + a7d57ba commit 76a0a93

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

MavenNet/MavenCentralRepository.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ protected override async Task<IEnumerable<Artifact>> GetArtifactsAsync(string gr
5656
return artifacts;
5757
}
5858

59+
// Optimization that avoids the Maven search, which also avoids the 100 row limit
60+
protected override async Task<IEnumerable<Artifact>> GetArtifactsAsync(string groupId, params string[] artifactIds)
61+
{
62+
var artifacts = new List<Artifact>();
63+
64+
foreach (var aid in artifactIds) {
65+
try {
66+
using (var s = await OpenMavenMetadataFile(groupId, aid).ConfigureAwait(false)) {
67+
var metadata = MavenMetadataParser.Parse(s);
68+
69+
artifacts.Add(new Artifact(aid, groupId, metadata.AllVersions.ToArray()));
70+
}
71+
} catch { }
72+
}
73+
74+
return artifacts;
75+
}
76+
5977
protected override Task<IEnumerable<string>> GetGroupIdsAsync()
6078
{
6179
return Task.FromResult<IEnumerable<string>>(new List<string>());

MavenNet/MavenRepository.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public static FileBasedMavenRepository FromDirectory(string directoryPath)
4141
protected abstract Task<Stream> OpenFileAsync(string path);
4242
protected abstract Task<IEnumerable<string>> GetGroupIdsAsync();
4343
protected abstract Task<IEnumerable<Artifact>> GetArtifactsAsync(string groupId);
44+
protected async virtual Task<IEnumerable<Artifact>> GetArtifactsAsync(string groupId, params string[] artifactIds) => (await GetArtifactsAsync(groupId)).Where(a => artifactIds.Contains(a.Id));
4445
protected abstract string CombinePaths(params string[] parts);
4546

4647
public virtual async Task Refresh()
@@ -87,6 +88,25 @@ public virtual Task Refresh(params Group[] groups)
8788
return Task.CompletedTask;
8889
}
8990

91+
public virtual async Task Populate(string groupId, params string[] artifactIds)
92+
{
93+
var g = Groups.FirstOrDefault(a => a.Id == groupId);
94+
95+
if (g is null) {
96+
g = new Group(groupId);
97+
Groups.Add(g);
98+
}
99+
100+
var artifacts = await GetArtifactsAsync(groupId, artifactIds).ConfigureAwait(false);
101+
102+
// Set a reference to this repository implementation
103+
foreach (var a in artifacts)
104+
{
105+
a.Repository = this;
106+
g.Artifacts.Add(a);
107+
}
108+
}
109+
90110
public virtual Task<Stream> OpenArtifactPomFile(string groupId, string artifactId, string version)
91111
{
92112
var path = CombinePaths(CombinePaths(groupId.Split('.')), artifactId, version, artifactId + "-" + version + ".pom");

0 commit comments

Comments
 (0)