Skip to content

Commit

Permalink
[binderator] Add binding type and use it to remove 'gson' template. (#…
Browse files Browse the repository at this point in the history
…941)

Some of the final pieces needed to start removing package-specific templates:

- We use the top level `mavenRepositoryType` to default all packages to Google's Maven, and then use the templates to override this to `MavenCentral`. Without templates we will need to specify this directly on the artifact, so add support for an artifact level `mavenRepositoryType`.

- We have several different "types" of packages that we create today:
  - `EmbeddedJar` - Basic use of `<EmbeddedJar>` to include the Java payload in the NuGet package next to the managed bindings `.dll`. (This is equivalent to the preferred `<AndroidLibrary>` in .NET 6+.)
  - `Targets` - Uses `<InputJar>` to create the binding `.dll` and `<None>` to add the Java payload manually into the NuGet package and uses a `.targets` file to add it to the Android application.
  - `NoBindings` - Uses `<None>` to add the Java payload manually into the NuGet package and uses a `.targets` file to add it to the Android application. Does not create managed bindings.
  - `XBD` - Uses `<InputJar>` to create the binding `.dll`. The Java payload is not included in the NuGet package. Instead a `.targets` file is used to download the payload at compile time using `Xamarin.Build.Download`.

The default package type is `targets`, which is what the current default template uses. That is, this is the one that all AndroidX packages currently use.

To specify a different package type, we add a new artifact level `type` attribute. The only currently supported value for this is `androidlibrary` which provides the `EmbeddedJar` package type behavior.

As a proof of concept, migrate `GoogleGson` from the `gson` template to the default template.

### Results
Before:
```json
{
  "groupId": "com.google.code.gson",
  "artifactId": "gson",
  "version": "2.11.0",
  "nugetVersion": "2.11.0.1",
  "nugetId": "GoogleGson",
  "dependencyOnly": false,
  "templateSet": "gson"
}
```
![image](https://github.com/user-attachments/assets/968d3251-52fc-449f-a629-f28c86b44321)

After:
```json
{
  "groupId": "com.google.code.gson",
  "artifactId": "gson",
  "version": "2.11.0",
  "nugetVersion": "2.11.0.1",
  "nugetId": "GoogleGson",
  "dependencyOnly": false,
  "type": "androidlibrary",
  "mavenRepositoryType": "MavenCentral"
}
```
![image](https://github.com/user-attachments/assets/97bed63c-10c3-4827-992c-669f153f8c12)
  • Loading branch information
jpobst committed Aug 22, 2024
1 parent ff23d90 commit a959474
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 311 deletions.
23 changes: 3 additions & 20 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2455,7 +2455,8 @@
"nugetVersion": "2.11.0.1",
"nugetId": "GoogleGson",
"dependencyOnly": false,
"templateSet": "gson"
"type": "androidlibrary",
"mavenRepositoryType": "MavenCentral"
},
{
"groupId": "com.google.crypto.tink",
Expand Down Expand Up @@ -2947,7 +2948,7 @@
"nugetVersion": "121.5.0.1",
"nugetId": "Xamarin.GooglePlayServices.Cast.Framework",
"dependencyOnly": true
},
},
{
"groupId": "com.google.android.gms",
"artifactId": "play-services-cronet",
Expand Down Expand Up @@ -3193,24 +3194,6 @@
}
]
},
{
"name": "gson",
"mavenRepositoryType": "MavenCentral",
"templates": [
{
"templateFile": "templates/gson/Project.cshtml",
"outputFileRule": "generated/{groupid}.{artifactid}/{groupid}.{artifactid}.csproj"
},
{
"templateFile": "source/AndroidXNuGetReadMe.cshtml",
"outputFileRule": "generated/{groupid}.{artifactid}/readme.md"
},
{
"templateFile": "source/AndroidXSolutionFilter.cshtml",
"outputFileRule": "generated/{groupid}.{artifactid}/{groupid}.{artifactid}.slnf"
}
]
},
{
"name": "auto-value",
"mavenRepositoryType": "MavenCentral",
Expand Down
13 changes: 12 additions & 1 deletion source/AndroidXProject.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

<!-- Packaging files -->
<ItemGroup>
@if (Model.ShouldIncludeArtifact) {
@if (Model.ShouldIncludeArtifact && Model.Type == AndroidBinderator.BindingType.Targets) {
<None Include="@(Model.NuGetPackageId).targets" Pack="True" PackagePath="@@(AndroidXNuGetTargetFolders)" />
}
<None Include="..\..\source\PackageLicense.md" Pack="True" PackagePath="LICENSE.md" />
Expand Down Expand Up @@ -96,6 +96,7 @@
</TransformFile>
</ItemGroup>

@if (Model.Type == AndroidBinderator.BindingType.Targets) {
@if (@Model.MavenArtifacts.Count > 0) {
<!-- Java artifacts to bind -->
<ItemGroup>
Expand Down Expand Up @@ -138,6 +139,16 @@
}
}
</ItemGroup>
}

@if (Model.Type == AndroidBinderator.BindingType.AndroidLibrary) {
<ItemGroup>
@foreach (var art in @Model.MavenArtifacts)
{
<AndroidLibrary Include="..\..\externals\@(art.MavenGroupId)\@(art.MavenArtifactId).@(art.MavenArtifactPackaging)" />
}
</ItemGroup>
}

<!-- ProjectReferences -->
<ItemGroup>
Expand Down
222 changes: 0 additions & 222 deletions templates/gson/External-Dependency-Info.txt

This file was deleted.

67 changes: 0 additions & 67 deletions templates/gson/Project.cshtml

This file was deleted.

Loading

0 comments on commit a959474

Please sign in to comment.