| 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 analysis_server.src.get_handler; | 5 library analysis_server.src.get_handler; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 */ | 112 */ |
| 113 static const String CONTEXT_QUERY_PARAM = 'context'; | 113 static const String CONTEXT_QUERY_PARAM = 'context'; |
| 114 | 114 |
| 115 /** | 115 /** |
| 116 * Query parameter used to represent the descriptor to search for, when | 116 * Query parameter used to represent the descriptor to search for, when |
| 117 * accessing [CACHE_STATE_PATH]. | 117 * accessing [CACHE_STATE_PATH]. |
| 118 */ | 118 */ |
| 119 static const String DESCRIPTOR_QUERY_PARAM = 'descriptor'; | 119 static const String DESCRIPTOR_QUERY_PARAM = 'descriptor'; |
| 120 | 120 |
| 121 /** | 121 /** |
| 122 * Query parameter used to represent the index in the [_overlayContents]. | |
| 123 */ | |
| 124 static const String ID_PARAM = 'id'; | |
| 125 | |
| 126 /** | |
| 127 * Query parameter used to represent the name of elements to search for, when | 122 * Query parameter used to represent the name of elements to search for, when |
| 128 * accessing [INDEX_ELEMENT_BY_NAME]. | 123 * accessing [INDEX_ELEMENT_BY_NAME]. |
| 129 */ | 124 */ |
| 130 static const String INDEX_ELEMENT_NAME = 'name'; | 125 static const String INDEX_ELEMENT_NAME = 'name'; |
| 131 | 126 |
| 132 /** | 127 /** |
| 128 * Query parameter used to represent the path of an overlayed file. |
| 129 */ |
| 130 static const String PATH_PARAM = 'path'; |
| 131 |
| 132 /** |
| 133 * Query parameter used to represent the source to search for, when accessing | 133 * Query parameter used to represent the source to search for, when accessing |
| 134 * [CACHE_ENTRY_PATH]. | 134 * [CACHE_ENTRY_PATH]. |
| 135 */ | 135 */ |
| 136 static const String SOURCE_QUERY_PARAM = 'entry'; | 136 static const String SOURCE_QUERY_PARAM = 'entry'; |
| 137 | 137 |
| 138 /** | 138 /** |
| 139 * Query parameter used to represent the cache state to search for, when | 139 * Query parameter used to represent the cache state to search for, when |
| 140 * accessing [CACHE_STATE_PATH]. | 140 * accessing [CACHE_STATE_PATH]. |
| 141 */ | 141 */ |
| 142 static const String STATE_QUERY_PARAM = 'state'; | 142 static const String STATE_QUERY_PARAM = 'state'; |
| 143 | 143 |
| 144 static final ContentType _htmlContent = | 144 static final ContentType _htmlContent = |
| 145 new ContentType("text", "html", charset: "utf-8"); | 145 new ContentType("text", "html", charset: "utf-8"); |
| 146 | 146 |
| 147 /** | 147 /** |
| 148 * The socket server whose status is to be reported on. | 148 * The socket server whose status is to be reported on. |
| 149 */ | 149 */ |
| 150 SocketServer _server; | 150 SocketServer _server; |
| 151 | 151 |
| 152 /** | 152 /** |
| 153 * Buffer containing strings printed by the analysis server. | 153 * Buffer containing strings printed by the analysis server. |
| 154 */ | 154 */ |
| 155 List<String> _printBuffer; | 155 List<String> _printBuffer; |
| 156 | 156 |
| 157 /** | 157 /** |
| 158 * Contents of overlay files. | 158 * Contents of overlay files. |
| 159 */ | 159 */ |
| 160 final Map<int, String> _overlayContents = <int, String>{}; | 160 final Map<String, String> _overlayContents = <String, String>{}; |
| 161 | 161 |
| 162 /** | 162 /** |
| 163 * Initialize a newly created handler for GET requests. | 163 * Initialize a newly created handler for GET requests. |
| 164 */ | 164 */ |
| 165 GetHandler(this._server, this._printBuffer); | 165 GetHandler(this._server, this._printBuffer); |
| 166 | 166 |
| 167 /** | 167 /** |
| 168 * Return the active [CompletionDomainHandler] | 168 * Return the active [CompletionDomainHandler] |
| 169 * or `null` if either analysis server is not running | 169 * or `null` if either analysis server is not running |
| 170 * or there is no completion domain handler. | 170 * or there is no completion domain handler. |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 Folder folder = _findFolder(analysisServer, contextFilter); | 708 Folder folder = _findFolder(analysisServer, contextFilter); |
| 709 if (folder == null) { | 709 if (folder == null) { |
| 710 return _returnFailure(request, 'Invalid context: $contextFilter'); | 710 return _returnFailure(request, 'Invalid context: $contextFilter'); |
| 711 } | 711 } |
| 712 | 712 |
| 713 List<String> priorityNames; | 713 List<String> priorityNames; |
| 714 List<String> explicitNames = <String>[]; | 714 List<String> explicitNames = <String>[]; |
| 715 List<String> implicitNames = <String>[]; | 715 List<String> implicitNames = <String>[]; |
| 716 Map<String, String> links = new HashMap<String, String>(); | 716 Map<String, String> links = new HashMap<String, String>(); |
| 717 List<CaughtException> exceptions = <CaughtException>[]; | 717 List<CaughtException> exceptions = <CaughtException>[]; |
| 718 Map<String, int> overlayMap = new HashMap<String, int>(); | |
| 719 AnalysisContextImpl context = analysisServer.folderMap[folder]; | 718 AnalysisContextImpl context = analysisServer.folderMap[folder]; |
| 720 priorityNames = | 719 priorityNames = |
| 721 context.prioritySources.map((Source source) => source.fullName).toList()
; | 720 context.prioritySources.map((Source source) => source.fullName).toList()
; |
| 722 context.visitCacheItems( | 721 context.visitCacheItems( |
| 723 (Source source, SourceEntry sourceEntry, DataDescriptor rowDesc, | 722 (Source source, SourceEntry sourceEntry, DataDescriptor rowDesc, |
| 724 CacheState state) { | 723 CacheState state) { |
| 725 String sourceName = source.fullName; | 724 String sourceName = source.fullName; |
| 726 if (!links.containsKey(sourceName)) { | 725 if (!links.containsKey(sourceName)) { |
| 727 CaughtException exception = sourceEntry.exception; | 726 CaughtException exception = sourceEntry.exception; |
| 728 if (exception != null) { | 727 if (exception != null) { |
| 729 exceptions.add(exception); | 728 exceptions.add(exception); |
| 730 } | 729 } |
| 731 String link = makeLink(CACHE_ENTRY_PATH, { | 730 String link = makeLink(CACHE_ENTRY_PATH, { |
| 732 CONTEXT_QUERY_PARAM: folder.path, | 731 CONTEXT_QUERY_PARAM: folder.path, |
| 733 SOURCE_QUERY_PARAM: source.uri.toString() | 732 SOURCE_QUERY_PARAM: source.uri.toString() |
| 734 }, sourceName, exception != null); | 733 }, sourceName, exception != null); |
| 735 if (sourceEntry.explicitlyAdded) { | 734 if (sourceEntry.explicitlyAdded) { |
| 736 explicitNames.add(sourceName); | 735 explicitNames.add(sourceName); |
| 737 } else { | 736 } else { |
| 738 implicitNames.add(sourceName); | 737 implicitNames.add(sourceName); |
| 739 } | 738 } |
| 740 links[sourceName] = link; | 739 links[sourceName] = link; |
| 741 } | 740 } |
| 742 }); | 741 }); |
| 743 _overlayContents.clear(); | |
| 744 int count = 0; | |
| 745 context.visitContentCache((Source source, int stamp, String contents) { | |
| 746 count++; | |
| 747 overlayMap[source.fullName] = count; | |
| 748 _overlayContents[count] = contents; | |
| 749 }); | |
| 750 explicitNames.sort(); | 742 explicitNames.sort(); |
| 751 implicitNames.sort(); | 743 implicitNames.sort(); |
| 752 | 744 |
| 745 _overlayContents.clear(); |
| 746 context.visitContentCache((Source source, int stamp, String contents) { |
| 747 _overlayContents[source.fullName] = contents; |
| 748 }); |
| 749 |
| 753 void _writeFiles(StringBuffer buffer, String title, List<String> fileNames) | 750 void _writeFiles(StringBuffer buffer, String title, List<String> fileNames) |
| 754 { | 751 { |
| 755 buffer.write('<h3>$title</h3>'); | 752 buffer.write('<h3>$title</h3>'); |
| 756 if (fileNames == null || fileNames.isEmpty) { | 753 if (fileNames == null || fileNames.isEmpty) { |
| 757 buffer.write('<p>None</p>'); | 754 buffer.write('<p>None</p>'); |
| 758 } else { | 755 } else { |
| 759 buffer.write('<table style="width: 100%">'); | 756 buffer.write('<table style="width: 100%">'); |
| 760 for (String fileName in fileNames) { | 757 for (String fileName in fileNames) { |
| 761 buffer.write('<tr><td>'); | 758 buffer.write('<tr><td>'); |
| 762 buffer.write(links[fileName]); | 759 buffer.write(links[fileName]); |
| 763 buffer.write('</td><td>'); | 760 buffer.write('</td><td>'); |
| 764 if (overlayMap.containsKey(fileName)) { | 761 if (_overlayContents.containsKey(fileName)) { |
| 765 buffer.write(makeLink(OVERLAY_PATH, { | 762 buffer.write(makeLink(OVERLAY_PATH, { |
| 766 ID_PARAM: overlayMap[fileName].toString() | 763 PATH_PARAM: fileName |
| 767 }, 'overlay')); | 764 }, 'overlay')); |
| 768 } | 765 } |
| 769 buffer.write('</td></tr>'); | 766 buffer.write('</td></tr>'); |
| 770 } | 767 } |
| 771 buffer.write('</table>'); | 768 buffer.write('</table>'); |
| 772 } | 769 } |
| 773 } | 770 } |
| 774 | 771 |
| 775 _writeResponse(request, (StringBuffer buffer) { | 772 _writeResponse(request, (StringBuffer buffer) { |
| 776 _writePage( | 773 _writePage( |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 }); | 923 }); |
| 927 buffer.write('</table>'); | 924 buffer.write('</table>'); |
| 928 }); | 925 }); |
| 929 }); | 926 }); |
| 930 } else { | 927 } else { |
| 931 return _returnFailure(request, 'LocalIndex expected, but $index found.'); | 928 return _returnFailure(request, 'LocalIndex expected, but $index found.'); |
| 932 } | 929 } |
| 933 } | 930 } |
| 934 | 931 |
| 935 void _returnOverlayContents(HttpRequest request) { | 932 void _returnOverlayContents(HttpRequest request) { |
| 936 String idString = request.requestedUri.queryParameters[ID_PARAM]; | 933 String path = request.requestedUri.queryParameters[PATH_PARAM]; |
| 937 if (idString == null) { | 934 if (path == null) { |
| 938 return _returnFailure(request, 'Query parameter $ID_PARAM required'); | 935 return _returnFailure(request, 'Query parameter $PATH_PARAM required'); |
| 939 } | 936 } |
| 940 int id = int.parse(idString); | 937 String contents = _overlayContents[path]; |
| 941 String contents = _overlayContents[id]; | |
| 942 | 938 |
| 943 _writeResponse(request, (StringBuffer buffer) { | 939 _writeResponse(request, (StringBuffer buffer) { |
| 944 _writePage( | 940 _writePage( |
| 945 buffer, | 941 buffer, |
| 946 'Analysis Server - Overlay', | 942 'Analysis Server - Overlay', |
| 947 [], | 943 [], |
| 948 (StringBuffer buffer) { | 944 (StringBuffer buffer) { |
| 949 buffer.write('<pre>${HTML_ESCAPE.convert(contents)}</pre>'); | 945 buffer.write('<pre>${HTML_ESCAPE.convert(contents)}</pre>'); |
| 950 }); | 946 }); |
| 951 }); | 947 }); |
| 952 } | 948 } |
| 953 | 949 |
| 954 /** | 950 /** |
| 955 * Return a response displaying overlays information. | 951 * Return a response displaying overlays information. |
| 956 */ | 952 */ |
| 957 void _returnOverlaysInfo(HttpRequest request) { | 953 void _returnOverlaysInfo(HttpRequest request) { |
| 958 AnalysisServer analysisServer = _server.analysisServer; | 954 AnalysisServer analysisServer = _server.analysisServer; |
| 959 if (analysisServer == null) { | 955 if (analysisServer == null) { |
| 960 return _returnFailure(request, 'Analysis server is not running'); | 956 return _returnFailure(request, 'Analysis server is not running'); |
| 961 } | 957 } |
| 962 | 958 |
| 963 _writeResponse(request, (StringBuffer buffer) { | 959 _writeResponse(request, (StringBuffer buffer) { |
| 964 _writePage( | 960 _writePage( |
| 965 buffer, | 961 buffer, |
| 966 'Analysis Server - Overlays', | 962 'Analysis Server - Overlays', |
| 967 [], | 963 [], |
| 968 (StringBuffer buffer) { | 964 (StringBuffer buffer) { |
| 969 buffer.write('<table border="1">'); | 965 buffer.write('<table border="1">'); |
| 970 int count = 0; | |
| 971 _overlayContents.clear(); | 966 _overlayContents.clear(); |
| 972 analysisServer.folderMap.forEach((_, AnalysisContextImpl context) { | 967 ContentCache overlayState = analysisServer.overlayState; |
| 973 context.visitContentCache( | 968 overlayState.accept((Source source, int stamp, String contents) { |
| 974 (Source source, int stamp, String contents) { | 969 String fileName = source.fullName; |
| 975 count++; | 970 buffer.write('<tr>'); |
| 976 buffer.write('<tr>'); | 971 String link = makeLink(OVERLAY_PATH, { |
| 977 String linkRef = '$OVERLAY_PATH?id=$count'; | 972 PATH_PARAM: fileName |
| 978 String linkText = HTML_ESCAPE.convert(source.toString()); | 973 }, fileName); |
| 979 buffer.write('<td><a href="$linkRef">$linkText</a></td>'); | 974 DateTime time = new DateTime.fromMillisecondsSinceEpoch(stamp); |
| 980 buffer.write( | 975 _writeRow(buffer, [link, time]); |
| 981 '<td>${new DateTime.fromMillisecondsSinceEpoch(stamp)}</td>'); | 976 _overlayContents[fileName] = contents; |
| 982 buffer.write('</tr>'); | |
| 983 _overlayContents[count] = contents; | |
| 984 }); | |
| 985 }); | 977 }); |
| 978 int count = _overlayContents.length; |
| 986 buffer.write('<tr><td colspan="2">Total: $count entries.</td></tr>'); | 979 buffer.write('<tr><td colspan="2">Total: $count entries.</td></tr>'); |
| 987 buffer.write('</table>'); | 980 buffer.write('</table>'); |
| 988 }); | 981 }); |
| 989 }); | 982 }); |
| 990 } | 983 } |
| 991 | 984 |
| 992 /** | 985 /** |
| 993 * Return a response indicating the status of the analysis server. | 986 * Return a response indicating the status of the analysis server. |
| 994 */ | 987 */ |
| 995 void _returnServerStatus(HttpRequest request) { | 988 void _returnServerStatus(HttpRequest request) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1016 buffer.write('<p>'); | 1009 buffer.write('<p>'); |
| 1017 buffer.write(makeLink(COMPLETION_PATH, {}, 'Completion data')); | 1010 buffer.write(makeLink(COMPLETION_PATH, {}, 'Completion data')); |
| 1018 buffer.write('</p>'); | 1011 buffer.write('</p>'); |
| 1019 buffer.write('<p>'); | 1012 buffer.write('<p>'); |
| 1020 buffer.write( | 1013 buffer.write( |
| 1021 makeLink(COMMUNICATION_PERFORMANCE_PATH, {}, 'Performance')); | 1014 makeLink(COMMUNICATION_PERFORMANCE_PATH, {}, 'Performance')); |
| 1022 buffer.write('</p>'); | 1015 buffer.write('</p>'); |
| 1023 buffer.write('<p>'); | 1016 buffer.write('<p>'); |
| 1024 buffer.write(makeLink(STATUS_PATH, {}, 'Server status')); | 1017 buffer.write(makeLink(STATUS_PATH, {}, 'Server status')); |
| 1025 buffer.write('</p>'); | 1018 buffer.write('</p>'); |
| 1019 buffer.write('<p>'); |
| 1020 buffer.write(makeLink(OVERLAYS_PATH, {}, 'File overlays')); |
| 1021 buffer.write('</p>'); |
| 1026 }); | 1022 }); |
| 1027 }); | 1023 }); |
| 1028 } | 1024 } |
| 1029 | 1025 |
| 1030 /** | 1026 /** |
| 1031 * Return a two digit decimal representation of the given non-negative integer | 1027 * Return a two digit decimal representation of the given non-negative integer |
| 1032 * [value]. | 1028 * [value]. |
| 1033 */ | 1029 */ |
| 1034 String _twoDigit(int value) { | 1030 String _twoDigit(int value) { |
| 1035 if (value < 10) { | 1031 if (value < 10) { |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1650 * 'error'. | 1646 * 'error'. |
| 1651 */ | 1647 */ |
| 1652 static String makeLink(String path, Map<String, String> params, | 1648 static String makeLink(String path, Map<String, String> params, |
| 1653 String innerHtml, [bool hasError = false]) { | 1649 String innerHtml, [bool hasError = false]) { |
| 1654 Uri uri = new Uri(path: path, queryParameters: params); | 1650 Uri uri = new Uri(path: path, queryParameters: params); |
| 1655 String href = HTML_ESCAPE.convert(uri.toString()); | 1651 String href = HTML_ESCAPE.convert(uri.toString()); |
| 1656 String classAttribute = hasError ? ' class="error"' : ''; | 1652 String classAttribute = hasError ? ' class="error"' : ''; |
| 1657 return '<a href="$href"$classAttribute>$innerHtml</a>'; | 1653 return '<a href="$href"$classAttribute>$innerHtml</a>'; |
| 1658 } | 1654 } |
| 1659 } | 1655 } |
| OLD | NEW |