| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// Development server that compiles Dart to JS on the fly. | 5 /// Development server that compiles Dart to JS on the fly. |
| 6 library dev_compiler.src.server; | 6 library dev_compiler.src.server; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| 11 | 11 |
| 12 import 'package:analyzer/file_system/file_system.dart' show ResourceUriResolver; | 12 import 'package:analyzer/file_system/file_system.dart' show ResourceUriResolver; |
| 13 import 'package:analyzer/file_system/memory_file_system.dart'; | 13 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 14 import 'package:analyzer/src/generated/engine.dart' | 14 import 'package:analyzer/src/generated/engine.dart' |
| 15 show AnalysisContext, ChangeSet; | 15 show AnalysisContext, ChangeSet; |
| 16 import 'package:analyzer/src/generated/error.dart'; | 16 import 'package:analyzer/src/generated/error.dart'; |
| 17 import 'package:analyzer/src/generated/source.dart'; | 17 import 'package:analyzer/src/generated/source.dart'; |
| 18 import 'package:logging/logging.dart' show Level, Logger, LogRecord; | 18 import 'package:logging/logging.dart' show Level, Logger, LogRecord; |
| 19 import 'package:path/path.dart' as path; | 19 import 'package:path/path.dart' as path; |
| 20 import 'package:shelf/shelf.dart' as shelf; | 20 import 'package:shelf/shelf.dart' as shelf; |
| 21 import 'package:shelf/shelf_io.dart' as shelf; | 21 import 'package:shelf/shelf_io.dart' as shelf; |
| 22 import 'package:shelf_static/shelf_static.dart' as shelf_static; | 22 import 'package:shelf_static/shelf_static.dart' as shelf_static; |
| 23 | 23 |
| 24 import '../codegen/code_generator.dart' show CodeGenerator; | 24 import '../codegen/code_generator.dart' show CodeGenerator; |
| 25 import '../codegen/html_codegen.dart' show generateEntryHtml; | 25 import '../codegen/html_codegen.dart' show generateEntryHtml; |
| 26 import '../codegen/js_codegen.dart'; | 26 import '../codegen/js_codegen.dart'; |
| 27 import '../report/html_reporter.dart' show HtmlReporter; |
| 27 import '../analysis_context.dart'; | 28 import '../analysis_context.dart'; |
| 28 import '../compiler.dart' show AbstractCompiler, createErrorReporter; | 29 import '../compiler.dart' show AbstractCompiler, createErrorReporter; |
| 29 import '../info.dart' | 30 import '../info.dart' |
| 30 show AnalyzerMessage, CheckerResults, LibraryInfo, LibraryUnit; | 31 show AnalyzerMessage, CheckerResults, LibraryInfo, LibraryUnit; |
| 31 import '../options.dart'; | 32 import '../options.dart'; |
| 32 import '../report.dart'; | 33 import '../report.dart'; |
| 33 import '../utils.dart'; | 34 import '../utils.dart'; |
| 34 | 35 |
| 35 import 'dependency_graph.dart'; | 36 import 'dependency_graph.dart'; |
| 36 | 37 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 changed++; | 178 changed++; |
| 178 return _buildSource(n); | 179 return _buildSource(n); |
| 179 }); | 180 }); |
| 180 clock.stop(); | 181 clock.stop(); |
| 181 if (changed > 0) _dumpInfoIfRequested(); | 182 if (changed > 0) _dumpInfoIfRequested(); |
| 182 var time = (clock.elapsedMilliseconds / 1000).toStringAsFixed(2); | 183 var time = (clock.elapsedMilliseconds / 1000).toStringAsFixed(2); |
| 183 _log.fine("Compiled ${changed} libraries in ${time} s\n"); | 184 _log.fine("Compiled ${changed} libraries in ${time} s\n"); |
| 184 } | 185 } |
| 185 | 186 |
| 186 _dumpInfoIfRequested() { | 187 _dumpInfoIfRequested() { |
| 187 if (!options.dumpInfo || reporter is! SummaryReporter) return; | 188 if (reporter is HtmlReporter) { |
| 188 var result = (reporter as SummaryReporter).result; | 189 (reporter as HtmlReporter).finish(options); |
| 189 if (!options.serverMode) print(summaryToString(result)); | 190 } else { |
| 190 var filepath = options.serverMode | 191 if (!options.dumpInfo || reporter is! SummaryReporter) return; |
| 191 ? path.join(outputDir, 'messages.json') | 192 var result = (reporter as SummaryReporter).result; |
| 192 : options.dumpInfoFile; | 193 if (!options.serverMode) print(summaryToString(result)); |
| 193 if (filepath == null) return; | 194 var filepath = options.serverMode |
| 194 new File(filepath).writeAsStringSync(JSON.encode(result.toJsonMap())); | 195 ? path.join(outputDir, 'messages.json') |
| 196 : options.dumpInfoFile; |
| 197 if (filepath == null) return; |
| 198 new File(filepath).writeAsStringSync(JSON.encode(result.toJsonMap())); |
| 199 } |
| 195 } | 200 } |
| 196 } | 201 } |
| 197 | 202 |
| 198 class DevServer { | 203 class DevServer { |
| 199 final ServerCompiler compiler; | 204 final ServerCompiler compiler; |
| 200 final String outDir; | 205 final String outDir; |
| 201 final String host; | 206 final String host; |
| 202 final int port; | 207 final int port; |
| 203 final String _entryPath; | 208 final String _entryPath; |
| 204 | 209 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 307 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
| 303 var src = resolver.resolveAbsolute(uri, actualUri); | 308 var src = resolver.resolveAbsolute(uri, actualUri); |
| 304 return src.exists() ? src : null; | 309 return src.exists() ? src : null; |
| 305 } | 310 } |
| 306 | 311 |
| 307 Uri restoreAbsolute(Source source) => resolver.restoreAbsolute(source); | 312 Uri restoreAbsolute(Source source) => resolver.restoreAbsolute(source); |
| 308 } | 313 } |
| 309 | 314 |
| 310 final _log = new Logger('dev_compiler.src.server'); | 315 final _log = new Logger('dev_compiler.src.server'); |
| 311 final _earlyErrorResult = new CheckerResults(const [], true); | 316 final _earlyErrorResult = new CheckerResults(const [], true); |
| OLD | NEW |