Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 9823836

Browse files
authored
Merge branch 'main' into feature/kotlinx-coroutines-1.5.1
2 parents 9808cce + c687486 commit 9823836

File tree

6 files changed

+67
-9
lines changed

6 files changed

+67
-9
lines changed

Util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator.Tool/Xamarin.AndroidBinderator.Tool.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<PropertyGroup>
1414
<PackageId>Xamarin.AndroidBinderator.Tool</PackageId>
15-
<PackageVersion>0.4.6</PackageVersion>
15+
<PackageVersion>0.4.7</PackageVersion>
1616
<Title>Xamarin Android Binderator</Title>
1717
<PackageDescription>A tool for generating Xamarin.Android Binding projects from Razor templates and Maven Repository data.</PackageDescription>
1818
<PackageProjectUrl>https://go.microsoft.com/fwlink/?linkid=2100525</PackageProjectUrl>

Util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator/Config/BindingConfig.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ public class BindingConfig
5656
[JsonProperty("additionalProjects")]
5757
public List<string> AdditionalProjects { get; set; } = new List<string>();
5858

59+
/// True to consider 'Runtime' dependencies from a POM file, False to ignore them.
60+
[JsonProperty("strictRuntimeDependencies")]
61+
public bool StrictRuntimeDependencies { get; set; }
62+
63+
[JsonProperty("excludedRuntimeDependencies")]
64+
public string ExcludedRuntimeDependencies { get; set; }
65+
5966
[JsonProperty("metadata")]
6067
public Dictionary<string, string> Metadata { get; set; } = new Dictionary<string, string>();
6168
}

Util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator/Config/MavenArtifactConfig.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,10 @@ public string NugetVersion {
4646

4747
[JsonProperty("metadata")]
4848
public Dictionary<string, string> Metadata { get; set; } = new Dictionary<string, string>();
49+
50+
[JsonProperty("excludedRuntimeDependencies")]
51+
public string ExcludedRuntimeDependencies { get; set; }
52+
53+
public string GroupAndArtifactId => $"{GroupId}.{ArtifactId}";
4954
}
5055
}

Util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator/Engine.cs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ static async Task DownloadArtifacts(MavenRepository maven, BindingConfig config,
290290
static List<BindingProjectModel> BuildProjectModels(BindingConfig config, TemplateConfig template, Dictionary<string, Project> mavenProjects)
291291
{
292292
var projectModels = new List<BindingProjectModel>();
293+
var exceptions = new List<Exception>();
293294

294295
var baseMetadata = new Dictionary<string, string>();
295296
MergeValues(baseMetadata, config.Metadata);
@@ -330,7 +331,6 @@ static List<BindingProjectModel> BuildProjectModels(BindingConfig config, Templa
330331
var artifactExtractDir = Path.Combine(artifactDir, mavenArtifact.ArtifactId);
331332

332333
var proguardFile = Path.Combine(artifactExtractDir, "proguard.txt");
333-
var exceptions = new List<Exception>();
334334

335335
projectModel.MavenArtifacts.Add(new MavenArtifactModel
336336
{
@@ -348,8 +348,7 @@ static List<BindingProjectModel> BuildProjectModels(BindingConfig config, Templa
348348
// Gather maven dependencies to try and map out nuget dependencies
349349
foreach (var mavenDep in mavenProject.Dependencies)
350350
{
351-
// We only really care about 'compile' scoped dependencies (also null/blank means compile)
352-
if (!string.IsNullOrEmpty(mavenDep.Scope) && !mavenDep.Scope.ToLowerInvariant().Equals("compile"))
351+
if (!ShouldIncludeDependency(config, mavenArtifact, mavenDep, exceptions))
353352
continue;
354353

355354
mavenDep.Version = FixVersion(mavenDep.Version);
@@ -360,6 +359,11 @@ static List<BindingProjectModel> BuildProjectModels(BindingConfig config, Templa
360359
&& ma.ArtifactId == mavenDep.ArtifactId
361360
&& mavenDep.Satisfies(ma.Version));
362361

362+
if (depMapping is null && mavenDep.IsRuntimeDependency()) {
363+
exceptions.Add(new Exception($"Artifact '{mavenArtifact.GroupAndArtifactId}' has unknown 'Runtime' dependency '{mavenDep.GroupAndArtifactId()}'. Either fulfill or exclude this dependency."));
364+
continue;
365+
}
366+
363367
if (depMapping == null)
364368
{
365369
StringBuilder sb = new StringBuilder();
@@ -411,17 +415,41 @@ static List<BindingProjectModel> BuildProjectModels(BindingConfig config, Templa
411415
}
412416
});
413417
}
414-
if (exceptions.Any())
415-
{
416-
throw new AggregateException(exceptions.ToArray());
417-
}
418418

419419
}
420420

421+
if (exceptions.Any())
422+
throw new AggregateException(exceptions.ToArray());
423+
421424

422425
return projectModels;
423426
}
424427

428+
static bool ShouldIncludeDependency(BindingConfig config, MavenArtifactConfig artifact, Dependency dependency, List<Exception> exceptions)
429+
{
430+
// We always care about 'compile' scoped dependencies
431+
if (dependency.IsCompileDependency())
432+
return true;
433+
434+
// If we're not processing Runtime dependencies then ignore the rest
435+
if (!config.StrictRuntimeDependencies)
436+
return false;
437+
438+
// The only other thing we may care about is 'runtime', bail if this isn't 'runtime'
439+
if (!dependency.IsRuntimeDependency())
440+
return false;
441+
442+
// Check 'artifact' list
443+
if (artifact.ExcludedRuntimeDependencies.OrEmpty().Split(',').Contains(dependency.GroupAndArtifactId(), StringComparer.OrdinalIgnoreCase))
444+
return false;
445+
446+
// Check 'global' list
447+
if (config.ExcludedRuntimeDependencies.OrEmpty ().Split (',').Contains (dependency.GroupAndArtifactId (), StringComparer.OrdinalIgnoreCase))
448+
return false;
449+
450+
return true;
451+
}
452+
425453
static string GetRelativePath(string filespec, string folder)
426454
{
427455
Uri pathUri = new Uri(filespec);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using MavenNet.Models;
5+
6+
namespace AndroidBinderator
7+
{
8+
public static class Extensions
9+
{
10+
public static string OrEmpty (this string value) => value ?? string.Empty;
11+
12+
public static string GroupAndArtifactId (this Dependency dependency) => $"{dependency.GroupId}.{dependency.ArtifactId}";
13+
14+
public static bool IsCompileDependency (this Dependency dependency) => string.IsNullOrWhiteSpace (dependency.Scope) || dependency.Scope.ToLowerInvariant ().Equals ("compile");
15+
16+
public static bool IsRuntimeDependency (this Dependency dependency) => dependency != null && dependency.Scope.ToLowerInvariant ().Equals ("runtime");
17+
}
18+
}

Util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<PropertyGroup>
11-
<PackageVersion>2.2.6</PackageVersion>
11+
<PackageVersion>2.2.7</PackageVersion>
1212
<PackageId>Xamarin.AndroidBinderator</PackageId>
1313
<Title>Xamarin.AndroidBinderator</Title>
1414
<PackageDescription>An engine to generate Xamarin Binding projects from Maven repositories with a JSON config and razor templates.</PackageDescription>

0 commit comments

Comments
 (0)