trphoenix
2018-11-29 25f4612acc6885d3f977c16252e2185b874b3394
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (c) 2018, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
 
import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
 
part 'build_config.g.dart';
 
@JsonSerializable(checked: true, anyMap: true)
class Config {
  @JsonKey(required: true)
  final Map<String, Builder> builders;
 
  // Verifying enum keys in map
  Map<AutoApply, int> weights;
 
  Config({@required this.builders});
 
  factory Config.fromJson(Map map) => _$ConfigFromJson(map);
 
  Map<String, dynamic> toJson() => _$ConfigToJson(this);
}
 
@JsonSerializable(
    includeIfNull: false,
    disallowUnrecognizedKeys: true,
    checked: true,
    anyMap: true)
class Builder {
  @JsonKey(nullable: true)
  final String target;
 
  final String import;
 
  @JsonKey(name: 'is_optional')
  final bool isOptional;
 
  @JsonKey(disallowNullValue: true)
  final Uri configLocation;
 
  @JsonKey(name: 'auto_apply', disallowNullValue: true)
  final AutoApply autoApply;
 
  @JsonKey(name: 'build_to')
  final BuildTo buildTo;
 
  final AutoApply defaultEnumTest;
 
  @JsonKey(name: 'builder_factories', nullable: false)
  final List<String> builderFactories;
 
  @JsonKey(name: 'applies_builders')
  final List<String> appliesBuilders;
 
  @JsonKey(name: 'required_inputs')
  final List<String> requiredInputs;
 
  @JsonKey(name: 'build_extensions')
  final Map<String, List<String>> buildExtentions;
 
  Builder(
      {@required this.import,
      this.target,
      this.isOptional,
      this.autoApply,
      this.buildTo,
      this.defaultEnumTest,
      this.builderFactories,
      this.appliesBuilders,
      this.requiredInputs,
      this.buildExtentions,
      this.configLocation}) {
    if (builderFactories.isEmpty) {
      throw ArgumentError.value(builderFactories, 'builderFactories',
          'Must have at least one value.');
    }
  }
 
  factory Builder.fromJson(Map map) => _$BuilderFromJson(map);
 
  Map<String, dynamic> toJson() => _$BuilderToJson(this);
}
 
enum AutoApply {
  none,
  dependents,
  @JsonValue('all_packages')
  allPackages,
  @JsonValue('root_package')
  rootPackage
}
 
enum BuildTo { cache, source }