Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java-runtime] simplify mono.MonoPackageManager.LoadApplication() #9655

Merged
merged 1 commit into from
Jan 7, 2025

Conversation

jonathanpeppers
Copy link
Member

We currently have code that loads MonoRuntimeProvider.Bundled.java and parses Java code comments between:

// Mono Runtime Initialization {{{
android.content.pm.ApplicationInfo applicationInfo = context.getApplicationInfo ();
String[] apks = null;
String[] splitApks = applicationInfo.splitSourceDirs;
if (splitApks != null && splitApks.length > 0) {
    apks = new String[splitApks.length + 1];
    apks [0] = applicationInfo.sourceDir;
    System.arraycopy (splitApks, 0, apks, 1, splitApks.length);
} else {
    apks = new String[] { applicationInfo.sourceDir };
}
mono.MonoPackageManager.LoadApplication (context, applicationInfo, apks);
// }}}

These lines are used for any Instrumentation type, such as:

https://github.com/dotnet/java-interop/blob/2c06b3c2a11833aea0e9b51aac2a72195bd64539/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers.CallableWrapperMembers/CallableWrapperType.cs#L238-L241

To refactor and cleanup, we can:

  • Make mono.MonoPackageManager.LoadApplication() only take in a single Context context parameter.

  • Move the Java code that looks at applicationInfo.splitSourceDirs inside mono.MonoPackageManager.LoadApplication().

  • Reduce the code in the // Mono Runtime Initialization {{{ block to a single line.

  • Now we no longer need to load the MonoRuntimeProvider.Bundled.java file during a build, we can simply declare the one line of Java code as a C# string.

This will make refactoring <GenerateJavaStubs/> easier in future PRs.

We currently have code that loads `MonoRuntimeProvider.Bundled.java`
and parses Java code comments between:

    // Mono Runtime Initialization {{{
    android.content.pm.ApplicationInfo applicationInfo = context.getApplicationInfo ();
    String[] apks = null;
    String[] splitApks = applicationInfo.splitSourceDirs;
    if (splitApks != null && splitApks.length > 0) {
        apks = new String[splitApks.length + 1];
        apks [0] = applicationInfo.sourceDir;
        System.arraycopy (splitApks, 0, apks, 1, splitApks.length);
    } else {
        apks = new String[] { applicationInfo.sourceDir };
    }
    mono.MonoPackageManager.LoadApplication (context, applicationInfo, apks);
    // }}}

These lines are used for any `Instrumentation` type, such as:

https://github.com/dotnet/java-interop/blob/2c06b3c2a11833aea0e9b51aac2a72195bd64539/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers.CallableWrapperMembers/CallableWrapperType.cs#L238-L241

To refactor and cleanup, we can:

* Make `mono.MonoPackageManager.LoadApplication()` only take in a
  single `Context context` parameter.

* Move the Java code that looks at `applicationInfo.splitSourceDirs`
  inside `mono.MonoPackageManager.LoadApplication()`.

* Reduce the code in the `// Mono Runtime Initialization {{{` block to
  a single line.

* Now we no longer need to load the `MonoRuntimeProvider.Bundled.java`
  file during a build, we can simply declare the one line of Java code
  as a C# string.

This will make refactoring `<GenerateJavaStubs/>` easier in future PRs.
@jonathanpeppers
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

public static void LoadApplication (Context context, ApplicationInfo runtimePackage, String[] apks)
public static void LoadApplication (Context context)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API is "internal" and fine to change parameters?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be "internal", in that "nobody other than us" should be invoking it…

If nobody hits it in .NET 10 previews, it's fine! 🤪

@jonathanpeppers

This comment was marked as outdated.

@jonpryor jonpryor merged commit 6af0a5d into main Jan 7, 2025
61 checks passed
@jonpryor jonpryor deleted the dev/peppers/MonoPackageManager branch January 7, 2025 23:38
grendello added a commit that referenced this pull request Jan 9, 2025
* main:
  Add `$(Nullable)` = `annotations` to projects using NRT annotations without NRT enabled. (#9660)
  [Xamarin.Android.Build.Tasks] Add %(NuGetPackage*) to TaskItems (#9559)
  Bump to dotnet/java-interop@ee47652d (#9659)
  [XABT] Remove <CollectAssemblyFilesForArchive/> from FastDeployment (#9650)
  [Mono.Android] Generate API docs for API level 35 (#9647)
  [java-runtime] simplify `mono.MonoPackageManager.LoadApplication()` (#9655)
  [Mono.Android] Bind Android API-Baklava DP2. (#9653)
  [build+macOS] Remove quarantine from OpenJDK installations (#9652)
grendello added a commit that referenced this pull request Jan 9, 2025
* dev/grendel/use-libc++:
  Add `$(Nullable)` = `annotations` to projects using NRT annotations without NRT enabled. (#9660)
  [Xamarin.Android.Build.Tasks] Add %(NuGetPackage*) to TaskItems (#9559)
  Bump to dotnet/java-interop@ee47652d (#9659)
  [XABT] Remove <CollectAssemblyFilesForArchive/> from FastDeployment (#9650)
  [Mono.Android] Generate API docs for API level 35 (#9647)
  [java-runtime] simplify `mono.MonoPackageManager.LoadApplication()` (#9655)
  [Mono.Android] Bind Android API-Baklava DP2. (#9653)
  [build+macOS] Remove quarantine from OpenJDK installations (#9652)
@github-actions github-actions bot locked and limited conversation to collaborators Feb 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants