Create an injectable factory for application packages. (#26422)
This commit is contained in:
committed by
Jonah Williams
parent
d8db70af1a
commit
36a493602c
@@ -10,6 +10,7 @@ import 'package:xml/xml.dart' as xml;
|
|||||||
|
|
||||||
import 'android/android_sdk.dart';
|
import 'android/android_sdk.dart';
|
||||||
import 'android/gradle.dart';
|
import 'android/gradle.dart';
|
||||||
|
import 'base/context.dart';
|
||||||
import 'base/file_system.dart';
|
import 'base/file_system.dart';
|
||||||
import 'base/os.dart' show os;
|
import 'base/os.dart' show os;
|
||||||
import 'base/process.dart';
|
import 'base/process.dart';
|
||||||
@@ -20,6 +21,37 @@ import 'ios/plist_utils.dart' as plist;
|
|||||||
import 'project.dart';
|
import 'project.dart';
|
||||||
import 'tester/flutter_tester.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 {
|
abstract class ApplicationPackage {
|
||||||
ApplicationPackage({ @required this.id })
|
ApplicationPackage({ @required this.id })
|
||||||
: assert(id != null);
|
: assert(id != null);
|
||||||
@@ -277,33 +309,6 @@ class PrebuiltIOSApp extends IOSApp {
|
|||||||
String get _bundlePath => bundleDir.path;
|
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 {
|
class ApplicationPackageStore {
|
||||||
ApplicationPackageStore({ this.android, this.iOS });
|
ApplicationPackageStore({ this.android, this.iOS });
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import 'dart:async';
|
|||||||
import 'android/android_sdk.dart';
|
import 'android/android_sdk.dart';
|
||||||
import 'android/android_studio.dart';
|
import 'android/android_studio.dart';
|
||||||
import 'android/android_workflow.dart';
|
import 'android/android_workflow.dart';
|
||||||
|
import 'application_package.dart';
|
||||||
import 'artifacts.dart';
|
import 'artifacts.dart';
|
||||||
import 'asset.dart';
|
import 'asset.dart';
|
||||||
import 'base/build.dart';
|
import 'base/build.dart';
|
||||||
@@ -54,6 +55,7 @@ Future<T> runInContext<T>(
|
|||||||
AndroidWorkflow: () => AndroidWorkflow(),
|
AndroidWorkflow: () => AndroidWorkflow(),
|
||||||
AndroidValidator: () => AndroidValidator(),
|
AndroidValidator: () => AndroidValidator(),
|
||||||
AndroidLicenseValidator: () => AndroidLicenseValidator(),
|
AndroidLicenseValidator: () => AndroidLicenseValidator(),
|
||||||
|
ApplicationPackageFactory: () => ApplicationPackageFactory(),
|
||||||
Artifacts: () => CachedArtifacts(),
|
Artifacts: () => CachedArtifacts(),
|
||||||
AssetBundleFactory: () => AssetBundleFactory.defaultInstance,
|
AssetBundleFactory: () => AssetBundleFactory.defaultInstance,
|
||||||
BotDetector: () => const BotDetector(),
|
BotDetector: () => const BotDetector(),
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ class FlutterDevice {
|
|||||||
printStatus('Launching ${getDisplayPath(hotRunner.mainPath)} on ${device.name} in $modeName mode...');
|
printStatus('Launching ${getDisplayPath(hotRunner.mainPath)} on ${device.name} in $modeName mode...');
|
||||||
|
|
||||||
final TargetPlatform targetPlatform = await device.targetPlatform;
|
final TargetPlatform targetPlatform = await device.targetPlatform;
|
||||||
package = await getApplicationPackageForPlatform(
|
package = await ApplicationPackageFactory.instance.getPackageForPlatform(
|
||||||
targetPlatform,
|
targetPlatform,
|
||||||
applicationBinary: hotRunner.applicationBinary
|
applicationBinary: hotRunner.applicationBinary
|
||||||
);
|
);
|
||||||
@@ -319,7 +319,7 @@ class FlutterDevice {
|
|||||||
bool shouldBuild = true,
|
bool shouldBuild = true,
|
||||||
}) async {
|
}) async {
|
||||||
final TargetPlatform targetPlatform = await device.targetPlatform;
|
final TargetPlatform targetPlatform = await device.targetPlatform;
|
||||||
package = await getApplicationPackageForPlatform(
|
package = await ApplicationPackageFactory.instance.getPackageForPlatform(
|
||||||
targetPlatform,
|
targetPlatform,
|
||||||
applicationBinary: coldRunner.applicationBinary
|
applicationBinary: coldRunner.applicationBinary
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user