| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library get.handler; | 5 library get.handler; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:math'; |
| 9 | 10 |
| 11 import 'package:analysis_server/src/analysis_server.dart'; |
| 10 import 'package:analysis_server/src/socket_server.dart'; | 12 import 'package:analysis_server/src/socket_server.dart'; |
| 11 import 'package:analyzer/file_system/file_system.dart'; | 13 import 'package:analyzer/file_system/file_system.dart'; |
| 12 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
| 13 import 'package:analyzer/src/generated/engine.dart'; | 15 import 'package:analyzer/src/generated/engine.dart'; |
| 14 import 'package:analyzer/src/generated/java_engine.dart'; | 16 import 'package:analyzer/src/generated/java_engine.dart'; |
| 15 import 'analysis_server.dart'; | 17 import 'analysis_server.dart'; |
| 16 | 18 |
| 17 /** | 19 /** |
| 18 * Instances of the class [GetHandler] handle GET requests. | 20 * Instances of the class [GetHandler] handle GET requests. |
| 19 */ | 21 */ |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 /** | 167 /** |
| 166 * Return a response indicating the status of the analysis server. | 168 * Return a response indicating the status of the analysis server. |
| 167 */ | 169 */ |
| 168 void _returnServerStatus(HttpRequest request) { | 170 void _returnServerStatus(HttpRequest request) { |
| 169 HttpResponse response = request.response; | 171 HttpResponse response = request.response; |
| 170 response.statusCode = HttpStatus.OK; | 172 response.statusCode = HttpStatus.OK; |
| 171 response.headers.add(HttpHeaders.CONTENT_TYPE, "text/html"); | 173 response.headers.add(HttpHeaders.CONTENT_TYPE, "text/html"); |
| 172 response.write('<html>'); | 174 response.write('<html>'); |
| 173 response.write('<head>'); | 175 response.write('<head>'); |
| 174 response.write('<title>Dart Analysis Server - Status</title>'); | 176 response.write('<title>Dart Analysis Server - Status</title>'); |
| 177 response.write('<style>'); |
| 178 response.write('td.right {text-align: right;}'); |
| 179 response.write('</style>'); |
| 175 response.write('</head>'); | 180 response.write('</head>'); |
| 176 response.write('<body>'); | 181 response.write('<body>'); |
| 177 response.write('<h1>Analysis Server</h1>'); | 182 response.write('<h1>Analysis Server</h1>'); |
| 178 if (_server.analysisServer == null) { | 183 AnalysisServer analysisServer = _server.analysisServer; |
| 184 if (analysisServer == null) { |
| 179 response.write('<p>Not running</p>'); | 185 response.write('<p>Not running</p>'); |
| 180 } else { | 186 } else { |
| 181 response.write('<p>Running</p>'); | 187 if (analysisServer.statusAnalyzing) { |
| 188 response.write('<p>Running (analyzing)</p>'); |
| 189 } else { |
| 190 response.write('<p>Running (not analyzing)</p>'); |
| 191 } |
| 182 response.write('<h1>Analysis Contexts</h1>'); | 192 response.write('<h1>Analysis Contexts</h1>'); |
| 183 response.write('<h2>Summary</h2>'); | 193 response.write('<h2>Summary</h2>'); |
| 184 response.write('<table>'); | 194 response.write('<table>'); |
| 185 List headerRowText = ['Context']; | 195 List headerRowText = ['Context']; |
| 186 headerRowText.addAll(CacheState.values); | 196 headerRowText.addAll(CacheState.values); |
| 187 _writeRow(response, headerRowText, true); | 197 _writeRow(response, headerRowText, header: true); |
| 188 _server.analysisServer.folderMap.forEach((Folder folder, AnalysisContextIm
pl context) { | 198 Map<Folder, AnalysisContext> folderMap = analysisServer.folderMap; |
| 199 List<Folder> folders = folderMap.keys.toList(); |
| 200 folders.sort((Folder first, Folder second) |
| 201 => first.shortName.compareTo(second.shortName)); |
| 202 folders.forEach((Folder folder) { |
| 203 AnalysisContextImpl context = folderMap[folder]; |
| 189 String key = folder.shortName; | 204 String key = folder.shortName; |
| 190 AnalysisContextStatistics statistics = context.statistics; | 205 AnalysisContextStatistics statistics = context.statistics; |
| 191 Map<CacheState, int> totals = <CacheState, int>{}; | 206 Map<CacheState, int> totals = <CacheState, int>{}; |
| 192 for (CacheState state in CacheState.values) { | 207 for (CacheState state in CacheState.values) { |
| 193 totals[state] = 0; | 208 totals[state] = 0; |
| 194 } | 209 } |
| 195 statistics.cacheRows.forEach((AnalysisContextStatistics_CacheRow row) { | 210 statistics.cacheRows.forEach((AnalysisContextStatistics_CacheRow row) { |
| 196 for (CacheState state in CacheState.values) { | 211 for (CacheState state in CacheState.values) { |
| 197 totals[state] += row.getCount(state); | 212 totals[state] += row.getCount(state); |
| 198 } | 213 } |
| 199 }); | 214 }); |
| 200 List rowText = ['<a href="#context_${HTML_ESCAPE.convert(key)}">$key</a>
']; | 215 List rowText = ['<a href="#context_${HTML_ESCAPE.convert(key)}">$key</a>
']; |
| 201 for (CacheState state in CacheState.values) { | 216 for (CacheState state in CacheState.values) { |
| 202 rowText.add(totals[state]); | 217 rowText.add(totals[state]); |
| 203 } | 218 } |
| 204 _writeRow(response, rowText); | 219 _writeRow(response, rowText, classes: [null, "right"]); |
| 205 }); | 220 }); |
| 206 response.write('</table>'); | 221 response.write('</table>'); |
| 207 _server.analysisServer.folderMap.forEach((Folder folder, AnalysisContextIm
pl context) { | 222 folders.forEach((Folder folder) { |
| 223 AnalysisContextImpl context = folderMap[folder]; |
| 208 String key = folder.shortName; | 224 String key = folder.shortName; |
| 209 response.write('<h2><a name="context_${HTML_ESCAPE.convert(key)}">Analys
is Context: $key</a></h2>'); | 225 response.write('<h2><a name="context_${HTML_ESCAPE.convert(key)}">Analys
is Context: $key</a></h2>'); |
| 210 AnalysisContextStatistics statistics = context.statistics; | 226 AnalysisContextStatistics statistics = context.statistics; |
| 211 response.write('<table>'); | 227 response.write('<table>'); |
| 212 _writeRow(response, headerRowText, true); | 228 _writeRow(response, headerRowText, header: true); |
| 213 statistics.cacheRows.forEach((AnalysisContextStatistics_CacheRow row) { | 229 statistics.cacheRows.forEach((AnalysisContextStatistics_CacheRow row) { |
| 214 List rowText = [row.name]; | 230 List rowText = [row.name]; |
| 215 for (CacheState state in CacheState.values) { | 231 for (CacheState state in CacheState.values) { |
| 216 String text = row.getCount(state).toString(); | 232 String text = row.getCount(state).toString(); |
| 217 Map<String, String> params = <String, String>{ | 233 Map<String, String> params = <String, String>{ |
| 218 STATE_QUERY_PARAM: state.toString(), | 234 STATE_QUERY_PARAM: state.toString(), |
| 219 CONTEXT_QUERY_PARAM: folder.path, | 235 CONTEXT_QUERY_PARAM: folder.path, |
| 220 DESCRIPTOR_QUERY_PARAM: row.name | 236 DESCRIPTOR_QUERY_PARAM: row.name |
| 221 }; | 237 }; |
| 222 rowText.add(_makeLink(CACHE_STATE_PATH, params, text)); | 238 rowText.add(_makeLink(CACHE_STATE_PATH, params, text)); |
| 223 } | 239 } |
| 224 _writeRow(response, rowText); | 240 _writeRow(response, rowText, classes: [null, "right"]); |
| 225 }); | 241 }); |
| 226 response.write('</table>'); | 242 response.write('</table>'); |
| 227 List<CaughtException> exceptions = statistics.exceptions; | 243 List<CaughtException> exceptions = statistics.exceptions; |
| 228 if (!exceptions.isEmpty) { | 244 if (!exceptions.isEmpty) { |
| 229 response.write('<h2>Exceptions</h2>'); | 245 response.write('<h2>Exceptions</h2>'); |
| 230 exceptions.forEach((CaughtException exception) { | 246 exceptions.forEach((CaughtException exception) { |
| 231 response.write('<p>${exception.exception}</p>'); | 247 response.write('<p>${exception.exception}</p>'); |
| 232 }); | 248 }); |
| 233 } | 249 } |
| 234 }); | 250 }); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 response.write('</body>'); | 283 response.write('</body>'); |
| 268 response.write('</html>'); | 284 response.write('</html>'); |
| 269 response.close(); | 285 response.close(); |
| 270 } | 286 } |
| 271 | 287 |
| 272 /** | 288 /** |
| 273 * Write a single row within a table to the given [response] object. The row | 289 * Write a single row within a table to the given [response] object. The row |
| 274 * will have one cell for each of the [columns], and will be a header row if | 290 * will have one cell for each of the [columns], and will be a header row if |
| 275 * [header] is `true`. | 291 * [header] is `true`. |
| 276 */ | 292 */ |
| 277 void _writeRow(HttpResponse response, List<Object> columns, [bool header = fal
se]) { | 293 void _writeRow(HttpResponse response, List<Object> columns, |
| 294 {bool header : false, List<String> classes}) { |
| 278 response.write('<tr>'); | 295 response.write('<tr>'); |
| 279 columns.forEach((Object value) { | 296 int count = columns.length; |
| 297 int maxClassIndex = classes == null ? 0 : classes.length - 1; |
| 298 for (int i = 0; i < count; i++) { |
| 299 String classAttribute = ''; |
| 300 if (classes != null) { |
| 301 String className = classes[min(i, maxClassIndex)]; |
| 302 if (className != null) { |
| 303 classAttribute = ' class="$className"'; |
| 304 } |
| 305 } |
| 280 if (header) { | 306 if (header) { |
| 281 response.write('<th>'); | 307 response.write('<th$classAttribute>'); |
| 282 } else { | 308 } else { |
| 283 response.write('<td>'); | 309 response.write('<td$classAttribute>'); |
| 284 } | 310 } |
| 285 response.write(value); | 311 response.write(columns[i]); |
| 286 if (header) { | 312 if (header) { |
| 287 response.write('</th>'); | 313 response.write('</th>'); |
| 288 } else { | 314 } else { |
| 289 response.write('</td>'); | 315 response.write('</td>'); |
| 290 } | 316 } |
| 291 }); | 317 }; |
| 292 response.write('</tr>'); | 318 response.write('</tr>'); |
| 293 } | 319 } |
| 294 } | 320 } |
| OLD | NEW |