flutter/packages/flutter_tools/gradle
Younghan Kim 18071ec0a8
Remove block and line comments when detecting '.flutter-plugins' in settings.gradle(.kts) (#155488)
**PR Title:**

Remove block and line comments when detecting `'.flutter-plugins'` in `settings.gradle`

---

**Description:**

This PR modifies the `configureLegacyPluginEachProjects` function to remove block (`/* ... */`) and line (`// ...`) comments from the `settings.gradle` or `settings.gradle.kts` file content before checking for the presence of the `'.flutter-plugins'` string. This ensures that only uncommented, meaningful code is considered during the detection, preventing false positives when the string appears within comments.

**Why is this change necessary?**

In some cases, the `'.flutter-plugins'` string may be present inside comments in the `settings.gradle` file. The existing implementation does not account for this and may incorrectly detect the string even when it's commented out. This can lead to unintended behavior, such as configuring plugin projects when it is not necessary.

By removing comments before performing the check, we prevent false positives and ensure that the detection logic is accurate, only acting when the `'.flutter-plugins'` string is present in active code.

**Changes Made:**

- **Added comment removal logic:**
  - Removed block comments (`/* ... */`) using the regular expression `/(?s)\/\*.*?\*\//`.
    - The `(?s)` flag enables dot-all mode, allowing `.` to match newline characters.
  - Removed line comments (`// ...`) using the regular expression `/(?m)\/\/.*$`.
    - The `(?m)` flag enables multi-line mode, so `^` and `$` match the start and end of each line.
  - Combined both comment removal steps into a single chain for efficiency.

- **Updated the string detection:**
  - The check for `'.flutter-plugins'` is now performed on the uncommented content of the `settings.gradle` file.
  - This ensures that only meaningful, uncommented code is considered during detection.

**Issue Fixed:**

- Fixes [#155484](https://github.com/flutter/flutter/issues/155484)

---

---

If you need any further assistance or have questions, feel free to reach out!

---

**Links:**

- [Contributor Guide]
- [Tree Hygiene]
- [Flutter Style Guide]
- [Features we expect every widget to implement]
- [CLA]
- [flutter/tests]
- [breaking change policy]
- [Discord]
- [Data Driven Fixes]
2024-11-11 02:47:32 +00:00
..
src/main Remove block and line comments when detecting '.flutter-plugins' in settings.gradle(.kts) (#155488) 2024-11-11 02:47:32 +00:00
.dartignore License update (#45373) 2019-11-27 15:04:02 -08:00
aar_init_script.gradle Fix flutter build aar for modules that use a plugin (#154757) 2024-09-10 16:42:22 +00:00
app_plugin_loader.gradle Switch to more reliable flutter.dev link destinations in the tool (#150587) 2024-06-26 23:30:39 +00:00
build.gradle.kts Format all kotlin according to ktlint (#143390) 2024-02-14 17:58:18 +00:00
flutter_proguard_rules.pro Remove allowoptimization modifier from FlutterPlugin proguard rules (#154715) 2024-09-06 20:37:23 +00:00
flutter.gradle Switch to more reliable flutter.dev link destinations in the tool (#150587) 2024-06-26 23:30:39 +00:00
manual_migration_settings.gradle.md Don't import plugins that don't support android in settings.gradle (#54407) 2020-04-12 08:55:03 -07:00
module_plugin_loader.gradle Fix use of deprecated buildDir in Android templates/tests/examples (#157560) 2024-11-06 21:34:23 +00:00
resolve_dependencies.gradle Allows adding a storage 'realm' to the storage base URL (#131951) 2023-08-09 23:26:05 +00:00
settings_aar.gradle.tmpl
settings.gradle.kts Format all kotlin according to ktlint (#143390) 2024-02-14 17:58:18 +00:00