Skip to content

Commit

Permalink
Merge pull request #4 from NAXAM/3-revise-a-tag-regex-and-support-bin…
Browse files Browse the repository at this point in the history
…tray

Revise a tag regex and support Bintray
  • Loading branch information
Redth authored Oct 15, 2020
2 parents 0a226bd + 2caa2da commit 0ac30a5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 9 deletions.
43 changes: 43 additions & 0 deletions MavenNet.Tests/JCenterTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Xunit;
using System.Linq;
using System;
using System.Threading.Tasks;

namespace MavenNet.Tests
{
public class JcenterTest
{
const string JCENTER_URL_REPO = "https://dl.bintray.com/kommunicate/Kommunicate-Android-Chat-SDK/";

[Fact]
public async Task Test_Refresh_URL()
{
var repo = MavenRepository.FromUrl(JCENTER_URL_REPO);
await repo.Refresh();

Assert.True(repo.Groups.Any());
}

[Fact]
public async Task Test_Project_URL()
{
var repo = MavenRepository.FromUrl(JCENTER_URL_REPO);
await repo.Refresh();

var project = await repo.GetProjectAsync("io.kommunicate.sdk", "kommunicateui", "2.0.5");

Assert.True(project != null);
}

[Fact]
public async Task Test_GroupIds_Project_URL()
{
var repo = MavenRepository.FromUrl(JCENTER_URL_REPO);
await repo.Refresh("io.kommunicate.sdk");

var project = await repo.GetProjectAsync("io.kommunicate.sdk", "kommunicateui", "2.0.5");

Assert.True(project != null);
}
}
}
16 changes: 11 additions & 5 deletions MavenNet/FileBasedMavenRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected override async Task<IEnumerable<string>> GetGroupIdsAsync()
protected override async Task<IEnumerable<Artifact>> GetArtifactsAsync(string groupId)
{
var artifacts = new List<Artifact>();
const string VERSION_REREX = "^\\d+";

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

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

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

if (!string.IsNullOrEmpty(artifactDir) && versions != null && versions.Any())
if (!string.IsNullOrEmpty(artifactDir) && versions != null && versions.Any(x => Regex.IsMatch(x, VERSION_REREX)))
artifacts.Add(new Artifact(artifactDir, groupId, versions.ToArray()));
}

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

// See if this group was already detected and exit our recursion if so
if (!string.IsNullOrEmpty(groupId) && groupIds.Any(gid => gid.Equals(groupId, StringComparison.OrdinalIgnoreCase)))
return;
// if (string.IsNullOrEmpty(groupId)
// && groupIds.Any(gid => gid.Equals(groupId, StringComparison.OrdinalIgnoreCase))
// )
// return;

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

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

// If we found the maven-metadata.xml file, we are on an artifact folder
// We can stop recursing subdirs at this point since we found artifact info
if (!string.IsNullOrEmpty (metadataItem))
{
groupIds.Add(groupId);
if (!groupIds.Any(x => string.Equals(x, groupId, StringComparison.OrdinalIgnoreCase))) {
groupIds.Add(groupId);
}
}
else
{
Expand Down
8 changes: 4 additions & 4 deletions MavenNet/UrlMavenRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override Task Refresh()

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

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

var html = await LoadTextFileAsync(path);

var matches = Regex.Matches(html, rxPattern, RegexOptions.Singleline);
var matches = Regex.Matches(html, rxPattern, RegexOptions.Multiline);

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

list.Add(dir.Trim('/'));
list.Add(dir.Trim('/').Trim(':'));
}

return list;
}

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

var list = new List<string>();
string html = null;
Expand Down

0 comments on commit 0ac30a5

Please sign in to comment.