pubspec_schema.dart 1.48 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter_tools/src/flutter_manifest.dart';
6
import 'package:flutter_tools/src/globals.dart' as globals;
7
import 'package:yaml/yaml.dart';
8

9
import 'common.dart';
10

11
/// Check if the pubspec.yaml file under the `projectDir` is valid for a plugin project.
12 13
void validatePubspecForPlugin({
  required String projectDir,
Daco Harkes's avatar
Daco Harkes committed
14 15
  String? pluginClass,
  bool ffiPlugin = false,
16 17 18 19 20
  required List<String> expectedPlatforms,
  List<String> unexpectedPlatforms = const <String>[],
  String? androidIdentifier,
  String? webFileName,
}) {
Daco Harkes's avatar
Daco Harkes committed
21
  assert(pluginClass != null || ffiPlugin);
22
  final FlutterManifest manifest =
23
      FlutterManifest.createFromPath('$projectDir/pubspec.yaml', fileSystem: globals.fs, logger: globals.logger)!;
24
  final YamlMap platformMaps = YamlMap.wrap(manifest.supportedPlatforms!);
25
  for (final String platform in expectedPlatforms) {
26 27
    expect(platformMaps[platform], isNotNull);
    final YamlMap platformMap = platformMaps[platform]! as YamlMap;
Daco Harkes's avatar
Daco Harkes committed
28 29 30
    if (pluginClass != null) {
      expect(platformMap['pluginClass'], pluginClass);
    }
31
    if (platform == 'android') {
32
      expect(platformMap['package'], androidIdentifier);
33
    }
34
    if (platform == 'web') {
35
      expect(platformMap['fileName'], webFileName);
36
    }
37 38
  }
  for (final String platform in unexpectedPlatforms) {
39
    expect(platformMaps[platform], isNull);
40
  }
41
}