Skip to content

Commit

Permalink
Begin streamlining default template.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpobst committed Aug 7, 2024
1 parent 0835812 commit 097359e
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 117 deletions.
Binary file added build/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed icons/Xamarin.AndroidX_1024x1024.png
Binary file not shown.
Binary file removed icons/Xamarin.AndroidX_128x128.png
Binary file not shown.
Binary file removed icons/Xamarin.AndroidX_nuget.png
Binary file not shown.
159 changes: 43 additions & 116 deletions source/AndroidXProject.cshtml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
@using System
@model AndroidBinderator.BindingProjectModel
@using System
@using System.Linq

<Project Sdk="Microsoft.NET.Sdk">

<!-- Build properties -->
<PropertyGroup>
<TargetFrameworks>$(_DefaultTargetFrameworks)</TargetFrameworks>
<IsBindingProject>true</IsBindingProject>
<AssemblyName>@(Model.NuGetPackageId)</AssemblyName>
<AssemblyName>@Model.GetAssemblyName()</AssemblyName>
<AndroidUseIntermediateDesignerFile>false</AndroidUseIntermediateDesignerFile>
<RootNamespace>@(Model.NuGetPackageId.Replace("Xamarin.", ""))</RootNamespace>
<RootNamespace>@Model.GetRootNamespace()</RootNamespace>

<!--
No warnings for:
Expand All @@ -17,59 +19,41 @@
- CS0628: 'member' : new protected member declared in sealed class
- CS0108: 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended.
- CS0809: Obsolete member 'member' overrides non-obsolete member 'member'
- CS1572: XML comment has a param tag for '', but there is no parameter by that name
- CS1572: XML comment has a param tag for '', but there is no parameter by that name
- XAOBS001: While this member is 'public', Google considers it internal API and reserves the right to modify or delete it in the future. Use at your own risk.
-->
<NoWarn>0618;0109;0114;0628;0108;0809;1572</NoWarn>
<NoWarn>0618;0109;0114;0628;0108;0809;1572;XAOBS001</NoWarn>
</PropertyGroup>

@{
string[] artifact_version_parts = Model.NuGetVersion
.Split(new string[] { "-" }, StringSplitOptions.None);
string artifact_version = null;

string artifact_version_release = artifact_version_parts[0];
string[] artifact_version_release_parts = artifact_version_release.Split(new string[] { "." }, StringSplitOptions.None);
artifact_version = string.Join(".", artifact_version_release_parts, 0, 3);

if (artifact_version_parts.Length == 1)
{
// release
}
if (artifact_version_parts.Length == 2)
{
artifact_version += "-" + artifact_version_parts[1];
}

// Whether to bind the Java .jar/.aar
var bind_native_lib = Model.NuGetPackageId != "Xamarin.AndroidX.DataStore.Core.Jvm";

// Whether to include the Java .jar/.aar
var include_native_lib = Model.NuGetPackageId != "Xamarin.AndroidX.DataStore.Core.Jvm";
}

<!-- NuGet package properties -->
<PropertyGroup>
<PackageId>@(Model.NuGetPackageId)</PackageId>
<Title>.NET for Android (formerly Xamarin.Android) AndroidX - @(Model.Name)</Title>
<Summary>.NET for Android (formerly Xamarin.Android) bindings for AndroidX - @(Model.Name)</Summary>
<Description>.NET for Android (formerly Xamarin.Android) bindings for AndroidX library '@(Model.MavenGroupId):@(Model.Name)'.</Description>
<PackageTags>.NET for Android Xamarin AndroidX Xamarin.AndroidX Support Google @(Model.Name) artifact=@(Model.MavenGroupId):@(Model.Name) artifact_versioned=@(Model.MavenGroupId):@(Model.Name):@(artifact_version)</PackageTags>
<Title>.NET for Android bindings for the Android Java library '@(Model.MavenGroupId):@(Model.Name)'.</Title>
<Description>
$(Title)@(Model.NuGetPackageId.StartsWith("Xamarin.AndroidX.Compose") ? " Note this package only adds the Java library to the application. C# bindings are not provided." : string.Empty)

@(!string.IsNullOrWhiteSpace(Model.MavenDescription) ? $"Library description: {Model.MavenDescription}" : string.Empty)
</Description>
<PackageTags>xamarin artifact=@(Model.MavenGroupId):@(Model.Name) artifact_versioned=@(Model.MavenGroupId):@(Model.Name):@(Model.GetArtifactVersion())</PackageTags>
<PackageLicenseExpression>MIT AND Apache-2.0</PackageLicenseExpression>
<PackageIcon>icon.png</PackageIcon>
<PackageVersion>@(Model.NuGetVersion)$(PackageVersionSuffix)</PackageVersion>
<!-- Include symbol files (*.pdb) in the built .nupkg -->
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>

<!-- Packaging files -->
<ItemGroup>
@if (include_native_lib) {
@if (Model.ShouldIncludeArtifact) {
<None Include="@(Model.NuGetPackageId).targets" Pack="True" PackagePath="@@(AndroidXNuGetTargetFolders)" />
}
<None Include="..\..\source\PackageLicense.md" Pack="True" PackagePath="LICENSE.md" />
<None Include="..\..\External-Dependency-Info.txt" Pack="True" PackagePath="THIRD-PARTY-NOTICES.txt" />
<None Include="..\..\icons\Xamarin.AndroidX_nuget.png" Pack="True" PackagePath="icon.png" />
<None Include="..\..\build\icon.png" Pack="True" PackagePath="icon.png" />
<None Include=".\readme.md" Pack="True" PackagePath="readme.md" />
</ItemGroup>

<!-- Proguard files -->
@if (@Model.MavenArtifacts.Count > 0) {
<ItemGroup>
@foreach (var art in @Model.MavenArtifacts) {
Expand All @@ -80,6 +64,7 @@
</ItemGroup>
}

<!-- Binding compilation files -->
<ItemGroup>
<!-- Include AssemblyInfo.cs -->
<Compile Include="..\..\source\AssemblyInfo.cs" />
Expand All @@ -105,26 +90,12 @@
</TransformFile>
</ItemGroup>

<ItemGroup>
@foreach (var art in @Model.MavenArtifacts) {
if (!bind_native_lib) {
continue;
}

if (art.MavenArtifactPackaging == "aar") {
<None Include="..\..\externals\@(art.MavenGroupId)\@(art.MavenArtifactId).aar" Pack="True" PackagePath="aar\@(art.MavenGroupId).@(art.MavenArtifactId).aar" />
} else {
<None Include="..\..\externals\@(art.MavenGroupId)\@(art.MavenArtifactId).jar" Pack="True" PackagePath="jar\@(art.MavenGroupId).@(art.MavenArtifactId).jar" />
}
}
</ItemGroup>


@if (@Model.MavenArtifacts.Count > 0) {
<!-- Java artifacts to bind -->
<ItemGroup>
@foreach (var art in @Model.MavenArtifacts)
{
if (!include_native_lib) {
if (!Model.ShouldBindArtifact) {
continue;
}

Expand All @@ -147,81 +118,37 @@
</ItemGroup>
}

<!-- Java artifacts to include in the NuGet package -->
<ItemGroup>
@foreach (var art in @Model.MavenArtifacts) {
if (!Model.ShouldIncludeArtifact) {
continue;
}

if (art.MavenArtifactPackaging == "aar") {
<None Include="..\..\externals\@(art.MavenGroupId)\@(art.MavenArtifactId).aar" Pack="True" PackagePath="aar\@(art.MavenGroupId).@(art.MavenArtifactId).aar" />
} else {
<None Include="..\..\externals\@(art.MavenGroupId)\@(art.MavenArtifactId).jar" Pack="True" PackagePath="jar\@(art.MavenGroupId).@(art.MavenArtifactId).jar" />
}
}
</ItemGroup>

<!-- ProjectReferences -->
<ItemGroup>
<!-- ProjectReference -->
@foreach (var dep in @Model.NuGetDependencies) {
if (dep.IsProjectReference) {
<ProjectReference Include="..\..\generated\@(dep.MavenArtifact.MavenGroupId).@(dep.MavenArtifact.MavenArtifactId)\@(dep.MavenArtifact.MavenGroupId).@(dep.MavenArtifact.MavenArtifactId).csproj" PrivateAssets="none" PackageVersion="@GetProjectVersionString(dep.MavenArtifact.MavenArtifactVersion, dep.NuGetVersion)" />
<ProjectReference Include="..\..\generated\@(dep.MavenArtifact.MavenGroupId).@(dep.MavenArtifact.MavenArtifactId)\@(dep.MavenArtifact.MavenGroupId).@(dep.MavenArtifact.MavenArtifactId).csproj" PrivateAssets="none" PackageVersion="@dep.GetProjectVersionString()" />
}
}
</ItemGroup>


<!-- PackageReferences -->
<ItemGroup>
<!-- PackageReference -->
@foreach (var dep in @Model.NuGetDependencies) {
if (!dep.IsProjectReference) {
<PackageReference Include="@(dep.NuGetPackageId)" Version="@GetVersionString(dep.MavenArtifact.MavenArtifactVersion, dep.NuGetVersion)" PrivateAssets="none" />
<PackageReference Include="@(dep.NuGetPackageId)" Version="@dep.GetPackageVersionString()" PrivateAssets="none" />
}
}
</ItemGroup>

<!-- Compose nuget package details until Compose support is implemented -->
@if (@Model.NuGetPackageId.StartsWith("Xamarin.AndroidX.Compose"))
{
<PropertyGroup>
<Summary>.NET for Android (formerly Xamarin.Android) bindings for AndroidX - @(Model.Name) (bindings without managed callable wrappers (C#) and are only used for including Java files)</Summary>
<Description>.NET for Android (formerly Xamarin.Android) bindings for AndroidX - @(Model.Name) (bindings without managed callable wrappers (C#) and are only used for including Java files) artifact=@(Model.MavenGroupId):@(Model.Name) artifact_versioned=@(Model.MavenGroupId):@(Model.Name):@(artifact_version)</Description>
</PropertyGroup>
}

@{
string GetProjectVersionString (string mavenVersion, string nugetVersion)
{
var adjusted_string = GetVersionString (mavenVersion, nugetVersion);

// If nothing changed, return empty string
if (adjusted_string == nugetVersion)
return null;

return adjusted_string;
}

string GetVersionString (string mavenVersion, string nugetVersion)
{
// If this isn't an exact version we don't use this code
if (!mavenVersion.StartsWith ('[') || !mavenVersion.EndsWith (']') || mavenVersion.Contains (','))
return nugetVersion;

// An exact version is requested like "1.2.0", however we want to let the revision (4th NuGet number) float,
// so that our updates that don't change the Java artifact can still be used.
// That is, if the POM specifies "1.2.0" and the dependency NuGet is already "1.2.0.4", we want to allow:
// 1.2.0.4 >= x < 1.2.1
// NuGet expresses that as "[1.2.0.4, 1.2.1)", so that's what we need to create.
var lower_bound = nugetVersion;

var nuget_first = 0;
var nuget_second = 0;
var nuget_third = 0;

var nuget_parts = nugetVersion.Split ('.');

if (nuget_parts.Length > 0 && int.TryParse (nuget_parts [0], out var p1))
nuget_first = p1;

if (nuget_parts.Length > 1 && int.TryParse (nuget_parts [1], out var p2))
nuget_second = p2;

if (nuget_parts.Length > 2 && int.TryParse (nuget_parts [2], out var p3))
nuget_third = p3;

// Bump the third number
nuget_third++;

var upper_bound = $"{nuget_first}.{nuget_second}.{nuget_third}";

// Put it all together
return $"[{lower_bound}, {upper_bound})";
}
}
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

<ItemGroup>
<None Include="..\..\..\source\PackageLicense.md" Pack="True" PackagePath="LICENSE.md" />
<None Include="..\..\..\icons\Xamarin.AndroidX_nuget.png" Pack="True" PackagePath="icon.png" />
<None Include="..\..\..\build\icon.png" Pack="True" PackagePath="icon.png" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using MavenNet.Models;
Expand All @@ -8,6 +9,8 @@ namespace AndroidBinderator
{
public static class Extensions
{
public static bool HasValue ([NotNullWhen (true)] this string? str) => !string.IsNullOrWhiteSpace (str);

public static string OrEmpty (this string? value) => value ?? string.Empty;

public static string GroupAndArtifactId (this Dependency dependency) => $"{dependency.GroupId}.{dependency.ArtifactId}";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace AndroidBinderator
{
Expand Down Expand Up @@ -39,6 +40,26 @@ public class BindingProjectModel
public List<MavenArtifactLicense> Licenses { get; } = new List<MavenArtifactLicense> ();

public List<MavenArtifactDeveloper> Developers { get; } = new List<MavenArtifactDeveloper> ();

public string GetAssemblyName () => AssemblyName.HasValue () ? AssemblyName : NuGetPackageId ?? string.Empty;

public string GetArtifactVersion () => MavenArtifacts.FirstOrDefault ()?.MavenArtifactVersion ?? string.Empty;

public string GetRootNamespace ()
{
if (Metadata.TryGetValue ("rootNamespace", out var rootNamespace))
return rootNamespace;

return NuGetPackageId!.Replace ("Xamarin.", "");
}

// TODO: Move this to config.json
// Whether to bind the Java .jar/.aar
public bool ShouldBindArtifact => NuGetPackageId != "Xamarin.AndroidX.DataStore.Core.Jvm";

// TODO: Move this to config.json
// Whether to include the Java .jar/.aar in the NuGet package
public bool ShouldIncludeArtifact => NuGetPackageId != "Xamarin.AndroidX.DataStore.Core.Jvm";
}

public class MavenArtifactLicense
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,59 @@ public class NuGetDependencyModel
public MavenArtifactModel? MavenArtifact { get; set; }

public Dictionary<string, string> Metadata { get; set; } = new Dictionary<string, string>();

// Gets the version string needed for a NuGet package dependency, which we adjust to allow floating revisions
public string GetPackageVersionString ()
{
var mavenVersion = MavenArtifact!.MavenArtifactVersion!;
var nugetVersion = NuGetVersion!;

// If this isn't an exact version we don't use this code
if (!mavenVersion.StartsWith ('[') || !mavenVersion.EndsWith (']') || mavenVersion.Contains (','))
return nugetVersion;

// An exact version is requested like "1.2.0", however we want to let the revision (4th NuGet number) float,
// so that our updates that don't change the Java artifact can still be used.
// That is, if the POM specifies "1.2.0" and the dependency NuGet is already "1.2.0.4", we want to allow:
// 1.2.0.4 >= x < 1.2.1
// NuGet expresses that as "[1.2.0.4, 1.2.1)", so that's what we need to create.
var lower_bound = nugetVersion;

var nuget_first = 0;
var nuget_second = 0;
var nuget_third = 0;

var nuget_parts = nugetVersion.Split ('.');

if (nuget_parts.Length > 0 && int.TryParse (nuget_parts [0], out var p1))
nuget_first = p1;

if (nuget_parts.Length > 1 && int.TryParse (nuget_parts [1], out var p2))
nuget_second = p2;

if (nuget_parts.Length > 2 && int.TryParse (nuget_parts [2], out var p3))
nuget_third = p3;

// Bump the third number
nuget_third++;

var upper_bound = $"{nuget_first}.{nuget_second}.{nuget_third}";

// Put it all together
return $"[{lower_bound}, {upper_bound})";
}

// Gets the version string needed for a project dependency, which we adjust to allow floating revisions
public string? GetProjectVersionString ()
{
var nugetVersion = NuGetVersion!;
var adjusted_string = GetPackageVersionString ();

// If nothing changed, return empty string
if (adjusted_string == nugetVersion)
return null;

return adjusted_string;
}
}
}

0 comments on commit 097359e

Please sign in to comment.