fix(shorebird_cli): don't check for flavors in flutter module (#986)

Co-authored-by: Felix Angelov <felix@shorebird.dev>
This commit is contained in:
Bryan Oltman
2023-08-01 18:09:32 -04:00
committed by GitHub
parent 72628f494f
commit 94d3ca5471
2 changed files with 8 additions and 42 deletions
+4 -7
View File
@@ -58,14 +58,11 @@ class Gradlew {
/// Returns an empty set for apps that do not use product flavors.
Future<Set<String>> 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));
@@ -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);