diff --git a/util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator.Tests/GenerationTests.cs b/util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator.Tests/GenerationTests.cs index 3430a8982..48c44a488 100644 --- a/util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator.Tests/GenerationTests.cs +++ b/util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator.Tests/GenerationTests.cs @@ -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); diff --git a/util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator/MavenFactory.cs b/util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator/MavenFactory.cs index 7cec44f85..502926682 100644 --- a/util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator/MavenFactory.cs +++ b/util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator/MavenFactory.cs @@ -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) diff --git a/util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator/MavenFactory2.cs b/util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator/MavenFactory2.cs index 8cdbd1966..48c38ef05 100644 --- a/util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator/MavenFactory2.cs +++ b/util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator/MavenFactory2.cs @@ -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) diff --git a/util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator/MavenRepositoryResolver.cs b/util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator/MavenRepositoryResolver.cs index e1611ccf3..9e29a64ea 100644 --- a/util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator/MavenRepositoryResolver.cs +++ b/util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator/MavenRepositoryResolver.cs @@ -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); }