Files
flutter/packages/flutter_tools/gradle/src/main/kotlin/NativePluginLoaderReflectionBridge.kt
auto-submit[bot] 2f72db6c7f Reverts "Convert the Flutter Gradle Plugin entirely to Kotlin source (#166114)" (#166666)
<!-- start_original_pr_link -->
Reverts: flutter/flutter#166114
<!-- end_original_pr_link -->
<!-- start_initiating_author -->
Initiated by: gmackall
<!-- end_initiating_author -->
<!-- start_revert_reason -->
Reason for reverting: a failing postsubmit
<!-- end_revert_reason -->
<!-- start_original_pr_author -->
Original PR Author: gmackall
<!-- end_original_pr_author -->

<!-- start_reviewers -->
Reviewed By: {bartekpacia, reidbaker}
<!-- end_reviewers -->

<!-- start_revert_body -->
This change reverts the following previous change:
Finishes the conversion of the Flutter Gradle plugin from Groovy to
Kotlin.

Fixes https://github.com/flutter/flutter/issues/121541.
Fixes https://github.com/flutter/flutter/issues/166287.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

<!-- end_revert_body -->

Co-authored-by: auto-submit[bot] <flutter-engprod-team@google.com>
2025-04-07 02:51:47 +00:00

62 lines
2.0 KiB
Kotlin

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package com.flutter.gradle
import org.gradle.api.plugins.ExtraPropertiesExtension
import java.io.File
// TODO(gmackall): Remove reflection after migrating to plugin style application in
// https://github.com/flutter/flutter/issues/166461.
// New methods should not be added.
/**
* Class to hide from Kotlin source the dangerous reflection being used to call methods defined
* in script gradle plugins.
*/
object NativePluginLoaderReflectionBridge {
private var nativePluginLoader: Any? = null
/**
* An abstraction to hide reflection from calling sites. See ../scripts/native_plugin_loader.gradle.kts.
*/
@JvmStatic
fun getPlugins(
extraProperties: ExtraPropertiesExtension,
flutterProjectRoot: File
): List<Map<String, Any>> {
nativePluginLoader = extraProperties.get("nativePluginLoader")!!
@Suppress("UNCHECKED_CAST")
val pluginList: List<Map<String, Any>> =
nativePluginLoader!!::class
.members
.firstOrNull { it.name == "getPlugins" }
?.call(nativePluginLoader, flutterProjectRoot) as List<Map<String, Any>>
return pluginList
}
/**
* An abstraction to hide reflection from calling sites. See ../scripts/native_plugin_loader.gradle.kts.
*/
@JvmStatic
fun getDependenciesMetadata(
extraProperties: ExtraPropertiesExtension,
flutterProjectRoot: File
): Map<String, Any> {
nativePluginLoader = extraProperties.get("nativePluginLoader")!!
@Suppress("UNCHECKED_CAST")
val dependenciesMetadata: Map<String, Any> =
nativePluginLoader!!::class
.members
.firstOrNull { it.name == "dependenciesMetadata" }
?.call(nativePluginLoader, flutterProjectRoot) as Map<String, Any>
return dependenciesMetadata
}
}