From 94d3ca54712c483fa51c68c9aae67ccd90f78ca3 Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Tue, 1 Aug 2023 18:09:32 -0400 Subject: [PATCH] fix(shorebird_cli): don't check for flavors in flutter module (#986) Co-authored-by: Felix Angelov --- packages/shorebird_cli/lib/src/gradlew.dart | 11 ++---- .../shorebird_cli/test/src/gradlew_test.dart | 39 ++----------------- 2 files changed, 8 insertions(+), 42 deletions(-) diff --git a/packages/shorebird_cli/lib/src/gradlew.dart b/packages/shorebird_cli/lib/src/gradlew.dart index 539261c1..ec323ba5 100644 --- a/packages/shorebird_cli/lib/src/gradlew.dart +++ b/packages/shorebird_cli/lib/src/gradlew.dart @@ -58,14 +58,11 @@ class Gradlew { /// Returns an empty set for apps that do not use product flavors. Future> productFlavors(String projectPath) async { final javaHome = java.home; - // Flutter apps have android files in root/android - // Flutter modules have android files in root/.android - final androidRoot = [ - Directory(p.join(projectPath, 'android')), - Directory(p.join(projectPath, '.android')), - ].firstWhereOrNull((dir) => dir.existsSync()); + final androidRoot = Directory(p.join(projectPath, 'android')); - if (androidRoot == null) throw MissingAndroidProjectException(projectPath); + if (!androidRoot.existsSync()) { + throw MissingAndroidProjectException(projectPath); + } final executableFile = File(p.join(androidRoot.path, executable)); diff --git a/packages/shorebird_cli/test/src/gradlew_test.dart b/packages/shorebird_cli/test/src/gradlew_test.dart index b98e1141..9e100b62 100644 --- a/packages/shorebird_cli/test/src/gradlew_test.dart +++ b/packages/shorebird_cli/test/src/gradlew_test.dart @@ -90,12 +90,6 @@ Make sure you have run "flutter build apk" at least once.''', return tempDir; } - Directory setUpModuleTempDir() { - final tempDir = Directory.systemTemp.createTempSync(); - Directory(p.join(tempDir.path, '.android')).createSync(recursive: true); - return tempDir; - } - test( 'throws MissingAndroidProjectException ' 'when android root does not exist', () async { @@ -200,9 +194,9 @@ Make sure you have run "flutter build apk" at least once.''', when(() => platform.isLinux).thenReturn(true); when(() => platform.isMacOS).thenReturn(false); when(() => platform.isWindows).thenReturn(false); - final tempDir = setUpModuleTempDir(); + final tempDir = setUpAppTempDir(); File( - p.join(tempDir.path, '.android', 'gradlew'), + p.join(tempDir.path, 'android', 'gradlew'), ).createSync(recursive: true); const javaHome = 'test_java_home'; when(() => platform.environment).thenReturn({'JAVA_HOME': javaHome}); @@ -226,35 +220,10 @@ Make sure you have run "flutter build apk" at least once.''', ); verify( () => process.run( - p.join(tempDir.path, '.android', 'gradlew'), + p.join(tempDir.path, 'android', 'gradlew'), ['app:tasks', '--all', '--console=auto'], runInShell: true, - workingDirectory: p.join(tempDir.path, '.android'), - environment: {'JAVA_HOME': javaHome}, - ), - ).called(1); - }); - - test('extracts flavors from module directory structure', () async { - when(() => platform.isLinux).thenReturn(true); - when(() => platform.isMacOS).thenReturn(false); - when(() => platform.isWindows).thenReturn(false); - final tempDir = setUpModuleTempDir(); - File( - p.join(tempDir.path, '.android', 'gradlew'), - ).createSync(recursive: true); - const javaHome = 'test_java_home'; - when(() => platform.environment).thenReturn({'JAVA_HOME': javaHome}); - await expectLater( - runWithOverrides(() => gradlew.productFlavors(tempDir.path)), - completes, - ); - verify( - () => process.run( - p.join(tempDir.path, '.android', 'gradlew'), - ['app:tasks', '--all', '--console=auto'], - runInShell: true, - workingDirectory: p.join(tempDir.path, '.android'), + workingDirectory: p.join(tempDir.path, 'android'), environment: {'JAVA_HOME': javaHome}, ), ).called(1);