Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,31 @@ namespace Xamarin.AndroidBinderator.Tests
public class GenerationTests : BaseTest
{
[Theory]
[InlineData (MavenRepoType.Google)]
[InlineData (MavenRepoType.MavenCentral)]
public void VersionDiscoveryUsesUpstreamOnCI (MavenRepoType type)
{
var actual = MavenRepositoryResolver.Resolve (type, "", MavenRepositoryOperation.VersionDiscovery, runningOnCI: true);

Assert.Equal (type, actual.type);
Assert.Equal ("", actual.location);
}

[Theory]
[InlineData (false, MavenRepoType.Google, "", MavenRepoType.Google, "")]
[InlineData (true, MavenRepoType.Google, "", MavenRepoType.Url, MavenRepositoryResolver.DotNetPublicMaven)]
[InlineData (false, MavenRepoType.MavenCentral, "", MavenRepoType.MavenCentral, "")]
[InlineData (true, MavenRepoType.MavenCentral, "", MavenRepoType.Url, MavenRepositoryResolver.DotNetPublicMaven)]
[InlineData (true, MavenRepoType.Google, "", MavenRepoType.Google, "")]
[InlineData (true, MavenRepoType.Url, "https://example.com/maven", MavenRepoType.Url, "https://example.com/maven")]
public void MavenCentralUsesMirrorOnlyOnCI (
[InlineData (true, MavenRepoType.Directory, "C:\\maven", MavenRepoType.Directory, "C:\\maven")]
public void BinderationUsesMirrorOnlyOnCI (
bool runningOnCI,
MavenRepoType type,
string location,
MavenRepoType expectedType,
string expectedLocation)
{
var actual = MavenRepositoryResolver.Resolve (type, location, runningOnCI);
var actual = MavenRepositoryResolver.Resolve (type, location, MavenRepositoryOperation.Binderation, runningOnCI);

Assert.Equal (expectedType, actual.type);
Assert.Equal (expectedLocation, actual.location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public static MavenRepository GetMavenRepository (BindingConfig config, MavenArt
{
// Precendence: Artifact > TemplateSet > Config
if (artifact.MavenRepositoryType.HasValue)
return MavenRepositoryResolver.Resolve (artifact.MavenRepositoryType.Value, artifact.MavenRepositoryLocation!);
return MavenRepositoryResolver.Resolve (artifact.MavenRepositoryType.Value, artifact.MavenRepositoryLocation!, MavenRepositoryOperation.VersionDiscovery);

var template = config.GetTemplateSet (artifact.TemplateSet);

if (template.MavenRepositoryType.HasValue)
return MavenRepositoryResolver.Resolve (template.MavenRepositoryType.Value, template.MavenRepositoryLocation!);
return MavenRepositoryResolver.Resolve (template.MavenRepositoryType.Value, template.MavenRepositoryLocation!, MavenRepositoryOperation.VersionDiscovery);

return MavenRepositoryResolver.Resolve (config.MavenRepositoryType, config.MavenRepositoryLocation!);
return MavenRepositoryResolver.Resolve (config.MavenRepositoryType, config.MavenRepositoryLocation!, MavenRepositoryOperation.VersionDiscovery);
}

static MavenRepository GetOrCreateRepository (MavenRepoType type, string location)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ public static Project GetPomForArtifactParent (BindingConfig config, Artifact pa
{
// Precendence: Artifact > TemplateSet > Config
if (artifact.MavenRepositoryType.HasValue)
return MavenRepositoryResolver.Resolve (artifact.MavenRepositoryType.Value, artifact.MavenRepositoryLocation!);
return MavenRepositoryResolver.Resolve (artifact.MavenRepositoryType.Value, artifact.MavenRepositoryLocation!, MavenRepositoryOperation.Binderation);

var template = config.GetTemplateSet (artifact.TemplateSet);

if (template.MavenRepositoryType.HasValue)
return MavenRepositoryResolver.Resolve (template.MavenRepositoryType.Value, template.MavenRepositoryLocation!);
return MavenRepositoryResolver.Resolve (template.MavenRepositoryType.Value, template.MavenRepositoryLocation!, MavenRepositoryOperation.Binderation);

return MavenRepositoryResolver.Resolve (config.MavenRepositoryType, config.MavenRepositoryLocation!);
return MavenRepositoryResolver.Resolve (config.MavenRepositoryType, config.MavenRepositoryLocation!, MavenRepositoryOperation.Binderation);
}

static CachedMavenRepository GetOrCreateRepository (MavenRepoType type, string location)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

namespace AndroidBinderator;

internal enum MavenRepositoryOperation
{
Binderation,
VersionDiscovery,
}

internal static class MavenRepositoryResolver
{
public const string DotNetPublicMaven = "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public-maven/maven/v1";

public static (MavenRepoType type, string location) Resolve (MavenRepoType type, string location)
=> Resolve (type, location, string.Equals (Environment.GetEnvironmentVariable ("RUNNINGONCI"), "true", StringComparison.OrdinalIgnoreCase));
public static (MavenRepoType type, string location) Resolve (MavenRepoType type, string location, MavenRepositoryOperation operation)
=> Resolve (type, location, operation, string.Equals (Environment.GetEnvironmentVariable ("RUNNINGONCI"), "true", StringComparison.OrdinalIgnoreCase));

internal static (MavenRepoType type, string location) Resolve (MavenRepoType type, string location, bool runningOnCI)
=> runningOnCI && type == MavenRepoType.MavenCentral
internal static (MavenRepoType type, string location) Resolve (MavenRepoType type, string location, MavenRepositoryOperation operation, bool runningOnCI)
=> runningOnCI && operation == MavenRepositoryOperation.Binderation && type is MavenRepoType.Google or MavenRepoType.MavenCentral
? (MavenRepoType.Url, DotNetPublicMaven)
: (type, location);
}
Loading