Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit ecaec06

Browse files
authored
Move ban-plugin-java script into separate file and improve testing. (#50875)
Closes flutter/flutter#143962.
1 parent 6a8d888 commit ecaec06

File tree

4 files changed

+101
-33
lines changed

4 files changed

+101
-33
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2013 The Flutter Authors. All rights reserved.
4+
# Use of this source code is governed by a BSD-style license that can be
5+
# found in the LICENSE file.
6+
7+
set -e
8+
9+
# Needed because if it is set, cd may print the path it changed to.
10+
unset CDPATH
11+
12+
# On Mac OS, readlink -f doesn't work, so follow_links traverses the path one
13+
# link at a time, and then cds into the link destination and find out where it
14+
# ends up.
15+
#
16+
# The function is enclosed in a subshell to avoid changing the working directory
17+
# of the caller.
18+
function follow_links() (
19+
cd -P "$(dirname -- "$1")"
20+
file="$PWD/$(basename -- "$1")"
21+
while [[ -L "$file" ]]; do
22+
cd -P "$(dirname -- "$file")"
23+
file="$(readlink -- "$file")"
24+
cd -P "$(dirname -- "$file")"
25+
file="$PWD/$(basename -- "$file")"
26+
done
27+
echo "$file"
28+
)
29+
30+
SCRIPT_DIR=$(follow_links "$(dirname -- "${BASH_SOURCE[0]}")")
31+
SRC_DIR="$(
32+
cd "$SCRIPT_DIR/../.."
33+
pwd -P
34+
)"
35+
36+
# Check if a file named **/GeneratedPluginRegistrant.java exists in the project.
37+
# If it does, fail the build and print a message to the user pointing them to
38+
# the file and instructing them to remove it.
39+
#
40+
# See: https://github.com/flutter/flutter/issues/143782.
41+
42+
# The expected path to the file. Any *other* path is unexpected.
43+
EXPECTED_PATHS=("./shell/platform/android/test/io/flutter/plugins/GeneratedPluginRegistrant.java")
44+
45+
# Temporarily change the working directory to the root of the Flutter project.
46+
pushd "$SRC_DIR/flutter" >/dev/null
47+
48+
# Change back to the original working directory.
49+
function cleanup() {
50+
popd >/dev/null
51+
}
52+
53+
trap cleanup EXIT
54+
55+
# Find all files named GeneratedPluginRegistrant.java in the project.
56+
echo "Finding all files named GeneratedPluginRegistrant.java in the project..."
57+
GENERATED_PLUGIN_REGISTRANT_PATHS=$(find . -name "GeneratedPluginRegistrant.java")
58+
59+
# Iterate over the found paths and check if they are expected.
60+
for path in $GENERATED_PLUGIN_REGISTRANT_PATHS; do
61+
if [[ ! " ${EXPECTED_PATHS[@]} " =~ " ${path} " ]]; then
62+
echo "ERROR: Found unexpected file named GeneratedPluginRegistrant.java at $path."
63+
echo "Please remove this file from the project."
64+
exit 1
65+
fi
66+
done
67+
68+
echo "Done."

ci/builders/linux_unopt.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@
4646
]
4747
},
4848
{
49-
"nane": "test:GeneratedPluginRegistant.java omitted",
50-
"script": "flutter/ci/test/format_no_generated_java_test.sh"
49+
"name": "ban GeneratedPluginRegistrant.java",
50+
"script": "flutter/ci/ban_generated_plugin_registrant_java.sh"
51+
},
52+
{
53+
"name": "ban_test GeneratedPluginRegistrant.java",
54+
"script": "flutter/ci/test/ban_generated_plugin_registrant_java_test.sh"
5155
},
5256
{
5357
"language": "python3",

ci/format.sh

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,6 @@ SRC_DIR="$(cd "$SCRIPT_DIR/../.."; pwd -P)"
3232
DART_SDK_DIR="${SRC_DIR}/third_party/dart/tools/sdks/dart-sdk"
3333
DART="${DART_SDK_DIR}/bin/dart"
3434

35-
# Check if a file named **/GeneratedPluginRegistrant.java exists in the project.
36-
# If it does, fail the build and print a message to the user pointing them to
37-
# the file and instructing them to remove it.
38-
#
39-
# See: https://github.com/flutter/flutter/issues/143782.
40-
41-
# The expected path to the file. Any *other* path is unexpected.
42-
EXPECTED_PATHS=("./shell/platform/android/test/io/flutter/plugins/GeneratedPluginRegistrant.java")
43-
44-
# Find all files named GeneratedPluginRegistrant.java in the project.
45-
GENERATED_PLUGIN_REGISTRANT_PATHS=$(find "$SRC_DIR/flutter" -name "GeneratedPluginRegistrant.java")
46-
47-
# Check for GeneratedPluginRegistrant.java in unexpected locations
48-
for expected_path in "${EXPECTED_PATHS[@]}"; do
49-
found_files=$(find . -name "GeneratedPluginRegistrant.java" -not -path "$expected_path")
50-
51-
for file in $found_files; do
52-
echo "Error: Unexpected GeneratedPluginRegistrant.java found: $file"
53-
echo "Please remove the unexpected file and see: https://github.com/flutter/flutter/issues/143782"
54-
exit 1
55-
done
56-
done
57-
5835
cd "$SCRIPT_DIR"
5936
"$DART" \
6037
--disable-dart-dev \

ci/test/format_no_generated_java_test.sh renamed to ci/test/ban_generated_plugin_registrant_java_test.sh

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,39 @@ FLUTTER_DIR="$SRC_DIR/flutter"
3939
# name and location is required to get loaded).
4040
#
4141
# This file is typically generated by Flutter tooling and should not exist.
42+
echo "Creating file ./src/flutter/GeneratedPluginRegistrant.java"
4243
touch "$FLUTTER_DIR/GeneratedPluginRegistrant.java"
4344

44-
# Create a trap that, on exit, removes the file.
45+
# Create a trap that, on exit, removes the temp files.
4546
function cleanup() {
47+
rm -f "$SRC_DIR/third_party/GeneratedPluginRegistrant.java"
4648
rm -f "$FLUTTER_DIR/GeneratedPluginRegistrant.java"
49+
rm -f "$FLUTTER_DIR/third_party/GeneratedPluginRegistrant.java"
4750
}
4851
trap cleanup EXIT
4952

50-
# Runs ../format.sh and verifies that it fails with the expected error message.
51-
# If it fails, the script prints an error message and exits with a non-zero status.
52-
"$FLUTTER_DIR/ci/format.sh" || {
53-
echo "PASS: analyze.sh failed as expected"
54-
exit 0
53+
# Run the ban script, expecting it to fail.
54+
# Intercept the output, only check the exit code.
55+
"$FLUTTER_DIR/ci/ban_generated_plugin_registrant_java.sh" > /dev/null 2>&1 && {
56+
echo "FAIL: ban_generated_plugin_registrant_java did not fail as expected"
57+
exit 1
5558
}
59+
echo "PASS: ban_generated_plugin_registrant_java failed as expected"
5660

57-
echo "FAIL: format.sh did not fail as expected"
58-
exit 1
61+
# Create a file in SRC_DIR/third_party, that should be OK.
62+
echo "Creating file ./src/third_party/GeneratedPluginRegistrant.java"
63+
touch "$SRC_DIR/third_party/GeneratedPluginRegistrant.java"
64+
65+
# Run the ban script, expecting it to succeed.
66+
"$FLUTTER_DIR/ci/ban_generated_plugin_registrant_java.sh" > /dev/null 2>&1 || {
67+
echo "PASS: ban_generated_plugin_registrant_java ignored third_party"
68+
}
69+
70+
# Create a file in SRC_DIR/flutter/third_party, that should be OK too.
71+
echo "Creating file ./src/flutter/third_party/GeneratedPluginRegistrant.java"
72+
touch "$FLUTTER_DIR/third_party/GeneratedPluginRegistrant.java"
73+
74+
# Run the ban script, expecting it to succeed.
75+
"$FLUTTER_DIR/ci/ban_generated_plugin_registrant_java.sh" > /dev/null 2>&1 || {
76+
echo "PASS: ban_generated_plugin_registrant_java ignored flutter/third_party"
77+
}

0 commit comments

Comments
 (0)