Skip to content

Commit 0ac30a5

Browse files
authored
Merge pull request #4 from NAXAM/3-revise-a-tag-regex-and-support-bintray
Revise a tag regex and support Bintray
2 parents 0a226bd + 2caa2da commit 0ac30a5

File tree

3 files changed

+58
-9
lines changed

3 files changed

+58
-9
lines changed

MavenNet.Tests/JCenterTest.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Xunit;
2+
using System.Linq;
3+
using System;
4+
using System.Threading.Tasks;
5+
6+
namespace MavenNet.Tests
7+
{
8+
public class JcenterTest
9+
{
10+
const string JCENTER_URL_REPO = "https://dl.bintray.com/kommunicate/Kommunicate-Android-Chat-SDK/";
11+
12+
[Fact]
13+
public async Task Test_Refresh_URL()
14+
{
15+
var repo = MavenRepository.FromUrl(JCENTER_URL_REPO);
16+
await repo.Refresh();
17+
18+
Assert.True(repo.Groups.Any());
19+
}
20+
21+
[Fact]
22+
public async Task Test_Project_URL()
23+
{
24+
var repo = MavenRepository.FromUrl(JCENTER_URL_REPO);
25+
await repo.Refresh();
26+
27+
var project = await repo.GetProjectAsync("io.kommunicate.sdk", "kommunicateui", "2.0.5");
28+
29+
Assert.True(project != null);
30+
}
31+
32+
[Fact]
33+
public async Task Test_GroupIds_Project_URL()
34+
{
35+
var repo = MavenRepository.FromUrl(JCENTER_URL_REPO);
36+
await repo.Refresh("io.kommunicate.sdk");
37+
38+
var project = await repo.GetProjectAsync("io.kommunicate.sdk", "kommunicateui", "2.0.5");
39+
40+
Assert.True(project != null);
41+
}
42+
}
43+
}

MavenNet/FileBasedMavenRepository.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ protected override async Task<IEnumerable<string>> GetGroupIdsAsync()
2727
protected override async Task<IEnumerable<Artifact>> GetArtifactsAsync(string groupId)
2828
{
2929
var artifacts = new List<Artifact>();
30+
const string VERSION_REREX = "^\\d+";
3031

3132
var groupDir = CombinePaths(groupId.Split('.'));
3233

@@ -36,7 +37,7 @@ protected override async Task<IEnumerable<Artifact>> GetArtifactsAsync(string gr
3637

3738
var versions = await GetDirectoriesAsync(CombinePaths(groupDir, artifactDir)).ConfigureAwait(false);
3839

39-
if (!string.IsNullOrEmpty(artifactDir) && versions != null && versions.Any())
40+
if (!string.IsNullOrEmpty(artifactDir) && versions != null && versions.Any(x => Regex.IsMatch(x, VERSION_REREX)))
4041
artifacts.Add(new Artifact(artifactDir, groupId, versions.ToArray()));
4142
}
4243

@@ -53,20 +54,25 @@ async Task recurseDir(string path, List<string> groupIds)
5354
groupId = groupId.Substring(0, groupId.LastIndexOf('.'));
5455

5556
// See if this group was already detected and exit our recursion if so
56-
if (!string.IsNullOrEmpty(groupId) && groupIds.Any(gid => gid.Equals(groupId, StringComparison.OrdinalIgnoreCase)))
57-
return;
57+
// if (string.IsNullOrEmpty(groupId)
58+
// && groupIds.Any(gid => gid.Equals(groupId, StringComparison.OrdinalIgnoreCase))
59+
// )
60+
// return;
5861

5962
// If we got this far, we aren't trying to process a duplicate group name, so continue looking for maven-metadata.xml
6063
var files = await GetFilesAsync(path).ConfigureAwait(false);
6164

6265
// Look for maven-metadata.xml
63-
var metadataItem = files?.FirstOrDefault(f => f.Equals("maven-metadata.xml", StringComparison.OrdinalIgnoreCase));
66+
var metadataItem = files?.FirstOrDefault(f => f.Equals("maven-metadata.xml", StringComparison.OrdinalIgnoreCase)
67+
|| f.Equals(":maven-metadata.xml", StringComparison.OrdinalIgnoreCase));
6468

6569
// If we found the maven-metadata.xml file, we are on an artifact folder
6670
// We can stop recursing subdirs at this point since we found artifact info
6771
if (!string.IsNullOrEmpty (metadataItem))
6872
{
69-
groupIds.Add(groupId);
73+
if (!groupIds.Any(x => string.Equals(x, groupId, StringComparison.OrdinalIgnoreCase))) {
74+
groupIds.Add(groupId);
75+
}
7076
}
7177
else
7278
{

MavenNet/UrlMavenRepository.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public override Task Refresh()
4141

4242
public override async Task<IEnumerable<string>> GetDirectoriesAsync(string path)
4343
{
44-
const string rxPattern = @"<a\s+href\s?=\s?""(?<dir>.*?)"".*?";
44+
const string rxPattern = @"<a.*\s+href\s?=\s?""(?<dir>.*?)""";
4545

4646
var list = new List<string>();
4747
//var html = htmlListingCache?[path] ?? await LoadTextFileAsync(path).ConfigureAwait (false);
@@ -51,7 +51,7 @@ public override async Task<IEnumerable<string>> GetDirectoriesAsync(string path)
5151

5252
var html = await LoadTextFileAsync(path);
5353

54-
var matches = Regex.Matches(html, rxPattern, RegexOptions.Singleline);
54+
var matches = Regex.Matches(html, rxPattern, RegexOptions.Multiline);
5555

5656
foreach (Match m in matches)
5757
{
@@ -60,15 +60,15 @@ public override async Task<IEnumerable<string>> GetDirectoriesAsync(string path)
6060
if (string.IsNullOrEmpty(dir) || !dir.EndsWith ("/", StringComparison.OrdinalIgnoreCase))
6161
continue;
6262

63-
list.Add(dir.Trim('/'));
63+
list.Add(dir.Trim('/').Trim(':'));
6464
}
6565

6666
return list;
6767
}
6868

6969
public override async Task<IEnumerable<string>> GetFilesAsync(string path)
7070
{
71-
const string rxPattern = @"<a\s+href\s?=\s?""(?<dir>.*?)"">";
71+
const string rxPattern = @"<a.*\s+href\s?=\s?""(?<dir>.+?)""";
7272

7373
var list = new List<string>();
7474
string html = null;

0 commit comments

Comments
 (0)