application_package.dart 3.53 KB
Newer Older
1 2 3 4
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'dart:async';
6 7 8

import 'package:path/path.dart' as path;

9 10 11
import 'artifacts.dart';
import 'build_configuration.dart';

12 13
abstract class ApplicationPackage {
  /// Path to the actual apk or bundle.
14
  final String localPath;
15 16

  /// Package ID from the Android Manifest or equivalent.
17
  final String id;
18 19

  /// File name of the apk or bundle.
20 21 22 23 24 25 26 27 28
  final String name;

  ApplicationPackage({
    String localPath,
    this.id
  }) : localPath = localPath, name = path.basename(localPath) {
    assert(localPath != null);
    assert(id != null);
  }
29 30 31
}

class AndroidApk extends ApplicationPackage {
32 33 34
  static const String _defaultName = 'SkyShell.apk';
  static const String _defaultId = 'org.domokit.sky.shell';
  static const String _defaultLaunchActivity = '$_defaultId/$_defaultId.SkyActivity';
35

36 37
  /// The path to the activity that should be launched.
  /// Defaults to 'org.domokit.sky.shell/org.domokit.sky.shell.SkyActivity'
38 39 40 41 42 43 44 45 46
  final String launchActivity;

  AndroidApk({
    String localPath,
    String id: _defaultId,
    this.launchActivity: _defaultLaunchActivity
  }) : super(localPath: localPath, id: id) {
    assert(launchActivity != null);
  }
47 48
}

49
class IOSApp extends ApplicationPackage {
50 51
  static const String _defaultName = 'SkyShell.app';
  static const String _defaultId = 'com.google.SkyShell';
52

53 54 55 56
  IOSApp({
    String localPath,
    String id: _defaultId
  }) : super(localPath: localPath, id: id);
57 58
}

59 60 61 62 63 64 65
class ApplicationPackageStore {
  final AndroidApk android;
  final IOSApp iOS;
  final IOSApp iOSSimulator;

  ApplicationPackageStore({ this.android, this.iOS, this.iOSSimulator });

66
  ApplicationPackage getPackageForPlatform(TargetPlatform platform) {
67
    switch (platform) {
68
      case TargetPlatform.android:
69
        return android;
70
      case TargetPlatform.iOS:
71
        return iOS;
72
      case TargetPlatform.iOSSimulator:
73
        return iOSSimulator;
Ian Hickson's avatar
Ian Hickson committed
74
      case TargetPlatform.mac:
75
      case TargetPlatform.linux:
76 77
        return null;
    }
78 79
  }

80 81 82 83
  static Future<ApplicationPackageStore> forConfigs(List<BuildConfiguration> configs) async {
    AndroidApk android;
    IOSApp iOS;
    IOSApp iOSSimulator;
84

85
    for (BuildConfiguration config in configs) {
86 87
      switch (config.targetPlatform) {
        case TargetPlatform.android:
88
          assert(android == null);
89 90 91 92 93 94 95 96
          if (config.type != BuildType.prebuilt) {
            String localPath = path.join(config.buildDir, 'apks', AndroidApk._defaultName);
            android = new AndroidApk(localPath: localPath);
          } else {
            Artifact artifact = ArtifactStore.getArtifact(
              type: ArtifactType.shell, targetPlatform: TargetPlatform.android);
            android = new AndroidApk(localPath: await ArtifactStore.getPath(artifact));
          }
97
          break;
98

99
        case TargetPlatform.iOS:
100 101 102
          assert(iOS == null);
          assert(config.type != BuildType.prebuilt);
          iOS = new IOSApp(localPath: path.join(config.buildDir, IOSApp._defaultName));
103
          break;
104

105
        case TargetPlatform.iOSSimulator:
106 107 108
          assert(iOSSimulator == null);
          assert(config.type != BuildType.prebuilt);
          iOSSimulator = new IOSApp(localPath: path.join(config.buildDir, IOSApp._defaultName));
109
          break;
110

Ian Hickson's avatar
Ian Hickson committed
111
        case TargetPlatform.mac:
112
        case TargetPlatform.linux:
113
          break;
114 115 116
      }
    }

117
    return new ApplicationPackageStore(android: android, iOS: iOS, iOSSimulator: iOSSimulator);
118 119
  }
}