Commit 36a49360 authored by Luca Zuccarini's avatar Luca Zuccarini Committed by Jonah Williams

Create an injectable factory for application packages. (#26422)

parent d8db70af
......@@ -10,6 +10,7 @@ import 'package:xml/xml.dart' as xml;
import 'android/android_sdk.dart';
import 'android/gradle.dart';
import 'base/context.dart';
import 'base/file_system.dart';
import 'base/os.dart' show os;
import 'base/process.dart';
......@@ -20,6 +21,37 @@ import 'ios/plist_utils.dart' as plist;
import 'project.dart';
import 'tester/flutter_tester.dart';
class ApplicationPackageFactory {
static ApplicationPackageFactory get instance => context[ApplicationPackageFactory];
Future<ApplicationPackage> getPackageForPlatform(
TargetPlatform platform,
{File applicationBinary}) async {
switch (platform) {
case TargetPlatform.android_arm:
case TargetPlatform.android_arm64:
case TargetPlatform.android_x64:
case TargetPlatform.android_x86:
return applicationBinary == null
? await AndroidApk.fromAndroidProject((await FlutterProject.current()).android)
: AndroidApk.fromApk(applicationBinary);
case TargetPlatform.ios:
return applicationBinary == null
? IOSApp.fromIosProject((await FlutterProject.current()).ios)
: IOSApp.fromPrebuiltApp(applicationBinary);
case TargetPlatform.tester:
return FlutterTesterApp.fromCurrentDirectory();
case TargetPlatform.darwin_x64:
case TargetPlatform.linux_x64:
case TargetPlatform.windows_x64:
case TargetPlatform.fuchsia:
return null;
}
assert(platform != null);
return null;
}
}
abstract class ApplicationPackage {
ApplicationPackage({ @required this.id })
: assert(id != null);
......@@ -277,33 +309,6 @@ class PrebuiltIOSApp extends IOSApp {
String get _bundlePath => bundleDir.path;
}
Future<ApplicationPackage> getApplicationPackageForPlatform(
TargetPlatform platform,
{File applicationBinary}) async {
switch (platform) {
case TargetPlatform.android_arm:
case TargetPlatform.android_arm64:
case TargetPlatform.android_x64:
case TargetPlatform.android_x86:
return applicationBinary == null
? await AndroidApk.fromAndroidProject((await FlutterProject.current()).android)
: AndroidApk.fromApk(applicationBinary);
case TargetPlatform.ios:
return applicationBinary == null
? IOSApp.fromIosProject((await FlutterProject.current()).ios)
: IOSApp.fromPrebuiltApp(applicationBinary);
case TargetPlatform.tester:
return FlutterTesterApp.fromCurrentDirectory();
case TargetPlatform.darwin_x64:
case TargetPlatform.linux_x64:
case TargetPlatform.windows_x64:
case TargetPlatform.fuchsia:
return null;
}
assert(platform != null);
return null;
}
class ApplicationPackageStore {
ApplicationPackageStore({ this.android, this.iOS });
......
......@@ -7,6 +7,7 @@ import 'dart:async';
import 'android/android_sdk.dart';
import 'android/android_studio.dart';
import 'android/android_workflow.dart';
import 'application_package.dart';
import 'artifacts.dart';
import 'asset.dart';
import 'base/build.dart';
......@@ -54,6 +55,7 @@ Future<T> runInContext<T>(
AndroidWorkflow: () => AndroidWorkflow(),
AndroidValidator: () => AndroidValidator(),
AndroidLicenseValidator: () => AndroidLicenseValidator(),
ApplicationPackageFactory: () => ApplicationPackageFactory(),
Artifacts: () => CachedArtifacts(),
AssetBundleFactory: () => AssetBundleFactory.defaultInstance,
BotDetector: () => const BotDetector(),
......
......@@ -269,7 +269,7 @@ class FlutterDevice {
printStatus('Launching ${getDisplayPath(hotRunner.mainPath)} on ${device.name} in $modeName mode...');
final TargetPlatform targetPlatform = await device.targetPlatform;
package = await getApplicationPackageForPlatform(
package = await ApplicationPackageFactory.instance.getPackageForPlatform(
targetPlatform,
applicationBinary: hotRunner.applicationBinary
);
......@@ -319,7 +319,7 @@ class FlutterDevice {
bool shouldBuild = true,
}) async {
final TargetPlatform targetPlatform = await device.targetPlatform;
package = await getApplicationPackageForPlatform(
package = await ApplicationPackageFactory.instance.getPackageForPlatform(
targetPlatform,
applicationBinary: coldRunner.applicationBinary
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment