From 79608562aac60f8e1dd0c822a7a7d74237cce2f0 Mon Sep 17 00:00:00 2001 From: thosakwe Date: Thu, 14 Sep 2017 20:36:28 -0400 Subject: [PATCH] Works with new build runner, etc. --- .gitignore | 21 ++++++++++++++++++ .idea/modules.xml | 8 +++++++ .idea/serialize.iml | 22 +++++++++++++++++++ .idea/vcs.xml | 6 +++++ .../lib/angel_serialize_generator.dart | 2 +- .../lib/build_context.dart | 17 ++++++++------ angel_serialize_generator/pubspec.yaml | 4 ++-- angel_serialize_generator/tool/actions.dart | 9 ++++++++ angel_serialize_generator/tool/build.dart | 4 ++-- angel_serialize_generator/tool/phases.dart | 7 ------ angel_serialize_generator/tool/watch.dart | 4 ++-- 11 files changed, 83 insertions(+), 21 deletions(-) create mode 100644 .idea/modules.xml create mode 100644 .idea/serialize.iml create mode 100644 .idea/vcs.xml create mode 100644 angel_serialize_generator/tool/actions.dart delete mode 100644 angel_serialize_generator/tool/phases.dart diff --git a/.gitignore b/.gitignore index bfa6a22a..eb3b7e56 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,22 @@ # Created by .ignore support plugin (hsz.mobi) +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/gradle.xml +.idea/**/libraries +.idea/**/mongoSettings.xml +*.iws +/out/ +.idea_modules/ +atlassian-ide-plugin.xml +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..08fe6948 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/serialize.iml b/.idea/serialize.iml new file mode 100644 index 00000000..017e6a01 --- /dev/null +++ b/.idea/serialize.iml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/angel_serialize_generator/lib/angel_serialize_generator.dart b/angel_serialize_generator/lib/angel_serialize_generator.dart index ee4e51b5..1ed44f92 100644 --- a/angel_serialize_generator/lib/angel_serialize_generator.dart +++ b/angel_serialize_generator/lib/angel_serialize_generator.dart @@ -21,7 +21,7 @@ class JsonModelGenerator extends GeneratorForAnnotation { Element element, ConstantReader reader, BuildStep buildStep) async { if (element.kind != ElementKind.CLASS) throw 'Only classes can be annotated with a @Serializable() annotation.'; - var ctx = buildContext( + var ctx = await buildContext( element, serializable, buildStep, diff --git a/angel_serialize_generator/lib/build_context.dart b/angel_serialize_generator/lib/build_context.dart index 7b300297..b0cfbc19 100644 --- a/angel_serialize_generator/lib/build_context.dart +++ b/angel_serialize_generator/lib/build_context.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer/src/dart/element/element.dart'; @@ -13,21 +14,21 @@ const TypeChecker aliasTypeChecker = const TypeChecker.fromRuntime(Alias); const TypeChecker excludeTypeChecker = const TypeChecker.fromRuntime(Exclude); const TypeChecker serializableTypeChecker = -const TypeChecker.fromRuntime(Serializable); + const TypeChecker.fromRuntime(Serializable); // TODO: Should add id, createdAt, updatedAt... -BuildContext buildContext( +Future buildContext( ClassElement clazz, Serializable annotation, BuildStep buildStep, Resolver resolver, bool autoSnakeCaseNames, bool autoIdAndDateFields, - {bool heedExclude: true}) { + {bool heedExclude: true}) async { var ctx = new BuildContext(annotation, originalClassName: clazz.name, sourceFilename: p.basename(buildStep.inputId.path)); - var lib = resolver.getLibrary(buildStep.inputId); + var lib = await resolver.libraryFor(buildStep.inputId); List fieldNames = []; for (var field in clazz.fields) { @@ -62,10 +63,11 @@ BuildContext buildContext( } DartType dateTime; - ['createdAt', 'updatedAt'].forEach((key) { + for (var key in ['createdAt', 'updatedAt']) { if (!fieldNames.contains(key)) { if (dateTime == null) { - var coreLib = resolver.libraries.singleWhere((lib) => lib.isDartCore); + var coreLib = + await resolver.libraries.singleWhere((lib) => lib.isDartCore); var dt = coreLib.getType('DateTime'); dateTime = dt.type; } @@ -75,7 +77,8 @@ BuildContext buildContext( ctx.fields.add(field); ctx.shimmed[key] = true; } - }); + } + ; } return ctx; diff --git a/angel_serialize_generator/pubspec.yaml b/angel_serialize_generator/pubspec.yaml index d3b5e0ef..1ae3d643 100644 --- a/angel_serialize_generator/pubspec.yaml +++ b/angel_serialize_generator/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_serialize_generator -version: 1.0.0-alpha+2 +version: 1.0.0-alpha+3 description: Model serialization generators, designed for use with Angel. author: Tobe O homepage: https://github.com/angel-dart/serialize @@ -13,5 +13,5 @@ dependencies: source_gen: ^0.7.0 dev_dependencies: angel_framework: ^1.0.0 - build_runner: ^0.3.0 + build_runner: ^0.5.0 test: ">= 0.12.13 < 0.13.0" \ No newline at end of file diff --git a/angel_serialize_generator/tool/actions.dart b/angel_serialize_generator/tool/actions.dart new file mode 100644 index 00000000..cf31ddc1 --- /dev/null +++ b/angel_serialize_generator/tool/actions.dart @@ -0,0 +1,9 @@ +import 'package:build_runner/build_runner.dart'; +import 'package:source_gen/source_gen.dart'; +import 'package:angel_serialize_generator/angel_serialize_generator.dart'; + +final List actions = [ + new BuildAction(new PartBuilder([const JsonModelGenerator()]), + 'angel_serialize_generator', + inputs: const ['test/models/*.dart']) +]; diff --git a/angel_serialize_generator/tool/build.dart b/angel_serialize_generator/tool/build.dart index 62711994..35f708bc 100644 --- a/angel_serialize_generator/tool/build.dart +++ b/angel_serialize_generator/tool/build.dart @@ -1,4 +1,4 @@ import 'package:build_runner/build_runner.dart'; -import 'phases.dart'; +import 'actions.dart'; -main() => build(PHASES, deleteFilesByDefault: true); +main() => build(actions, deleteFilesByDefault: true); diff --git a/angel_serialize_generator/tool/phases.dart b/angel_serialize_generator/tool/phases.dart deleted file mode 100644 index 1e49270f..00000000 --- a/angel_serialize_generator/tool/phases.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:build_runner/build_runner.dart'; -import 'package:source_gen/source_gen.dart'; -import 'package:angel_serialize_generator/angel_serialize_generator.dart'; - -final PhaseGroup PHASES = new PhaseGroup.singleAction( - new PartBuilder([const JsonModelGenerator()]), - new InputSet('angel_serialize_generator', const ['test/models/*.dart'])); diff --git a/angel_serialize_generator/tool/watch.dart b/angel_serialize_generator/tool/watch.dart index 1a6ce2f0..0d243320 100644 --- a/angel_serialize_generator/tool/watch.dart +++ b/angel_serialize_generator/tool/watch.dart @@ -1,4 +1,4 @@ import 'package:build_runner/build_runner.dart'; -import 'phases.dart'; +import 'actions.dart'; -main() => watch(PHASES, deleteFilesByDefault: true); +main() => watch(actions, deleteFilesByDefault: true);