Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions MavenNet.Tests/MavenNet.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFrameworks>net6</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
Expand Down
32 changes: 31 additions & 1 deletion MavenNet.Tests/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,35 @@ public async Task Test_GroupIds_Project_MAVENCENTRAL()

Assert.True(project.Dependencies?.Any());
}
}

[Fact]
public async Task Test_GroupIds_Project_MAVENCENTRAL_1()
{
var repo = MavenRepository.FromMavenCentral();
MavenRepository.HttpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36");
await repo.Refresh("com.google.accompanist");

var project = await repo.GetProjectAsync("com.google.accompanist", "accompanist-appcompat-theme", "0.30.1");

Assert.True(project != null);

Assert.True(project.Dependencies?.Any());
}

[Fact]
public async Task Test_GroupIds_Project_MAVENCENTRAL_2()
{
var repo = MavenRepository.FromMavenCentral();
MavenRepository.HttpClient.DefaultRequestHeaders.Clear();
await repo.Refresh("com.google.accompanist");

try
{
var project = await repo.GetProjectAsync("com.google.accompanist", "accompanist-appcompat-theme", "0.30.1");
}
finally
{
}
}
}
}
9 changes: 5 additions & 4 deletions MavenNet/MavenCentralRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ protected override string CombinePaths(params string[] parts)
return string.Join(new string(PathSeparator, 1), parts);
}

static readonly HttpClient http = new HttpClient();

protected override async Task<IEnumerable<Artifact>> GetArtifactsAsync(string groupId)
{
var artifacts = new List<Artifact>();

var url = $"http://search.maven.org/solrsearch/select?q=g:%22{groupId}%22&rows=100&wt=json";

var data = await http.GetStringAsync(url);
// enable by default?
// HttpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36");

var data = await HttpClient.GetStringAsync(url);

var json = JObject.Parse(data);

Expand Down Expand Up @@ -83,7 +84,7 @@ protected override Task<Stream> OpenFileAsync(string path)
{
var url = $"https://repo1.maven.org/maven2/{path}";

return http.GetStreamAsync(url);
return HttpClient.GetStreamAsync(url);
}
}
}
4 changes: 2 additions & 2 deletions MavenNet/MavenNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<Compile Remove="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NuGet.Versioning" Version="5.9.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NuGet.Versioning" Version="6.5.0" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions MavenNet/MavenRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
using System.IO;
using System.Threading.Tasks;
using MavenNet.Models;
using System.Net.Http;

namespace MavenNet
{
public abstract class MavenRepository : IMavenRepository
{
public static readonly HttpClient HttpClient = new HttpClient();

public static GoogleMavenRepository FromGoogle()
{
return new GoogleMavenRepository();
Expand Down