| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /// Generic utility functions. Stuff that should possibly be in core. | 5 /// Generic utility functions. Stuff that should possibly be in core. |
| 6 library pub.utils; | 6 library pub.utils; |
| 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 // This is used by [libraryPath]. It must be kept up-to-date with all libraries | |
| 13 // whose paths are looked up using that function. | |
| 14 @MirrorsUsed(targets: const ['pub.io', 'test_pub']) | |
| 15 import 'dart:mirrors'; | |
| 16 | |
| 17 import "package:crypto/crypto.dart"; | 12 import "package:crypto/crypto.dart"; |
| 18 import 'package:path/path.dart' as path; | 13 import 'package:path/path.dart' as path; |
| 19 import "package:stack_trace/stack_trace.dart"; | 14 import "package:stack_trace/stack_trace.dart"; |
| 20 | 15 |
| 21 import 'exceptions.dart'; | 16 import 'exceptions.dart'; |
| 17 import 'io.dart'; |
| 22 import 'log.dart' as log; | 18 import 'log.dart' as log; |
| 23 | 19 |
| 24 export '../../asset/dart/utils.dart'; | 20 export '../../asset/dart/utils.dart'; |
| 25 | 21 |
| 26 /// A regular expression matching a Dart identifier. | 22 /// A regular expression matching a Dart identifier. |
| 27 /// | 23 /// |
| 28 /// This also matches a package name, since they must be Dart identifiers. | 24 /// This also matches a package name, since they must be Dart identifiers. |
| 29 final identifierRegExp = new RegExp(r"[a-zA-Z_][a-zA-Z0-9_]+"); | 25 final identifierRegExp = new RegExp(r"[a-zA-Z_][a-zA-Z0-9_]+"); |
| 30 | 26 |
| 31 /// Like [identifierRegExp], but anchored so that it only matches strings that | 27 /// Like [identifierRegExp], but anchored so that it only matches strings that |
| (...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 }); | 773 }); |
| 778 return Future.wait(pairs).then((resolvedPairs) { | 774 return Future.wait(pairs).then((resolvedPairs) { |
| 779 var map = {}; | 775 var map = {}; |
| 780 for (var pair in resolvedPairs) { | 776 for (var pair in resolvedPairs) { |
| 781 map[pair.first] = pair.last; | 777 map[pair.first] = pair.last; |
| 782 } | 778 } |
| 783 return map; | 779 return map; |
| 784 }); | 780 }); |
| 785 } | 781 } |
| 786 | 782 |
| 787 /// Returns the path to the library named [libraryName]. | |
| 788 /// | |
| 789 /// The library name must be globally unique, or the wrong library path may be | |
| 790 /// returned. Any libraries accessed must be added to the [MirrorsUsed] | |
| 791 /// declaration in the import above. | |
| 792 String libraryPath(String libraryName) { | |
| 793 var lib = currentMirrorSystem().findLibrary(new Symbol(libraryName)); | |
| 794 return path.fromUri(lib.uri); | |
| 795 } | |
| 796 | |
| 797 /// Whether "special" strings such as Unicode characters or color escapes are | 783 /// Whether "special" strings such as Unicode characters or color escapes are |
| 798 /// safe to use. | 784 /// safe to use. |
| 799 /// | 785 /// |
| 800 /// On Windows or when not printing to a terminal, only printable ASCII | 786 /// On Windows or when not printing to a terminal, only printable ASCII |
| 801 /// characters should be used. | 787 /// characters should be used. |
| 802 bool get canUseSpecialChars => !runningAsTest && | 788 bool get canUseSpecialChars => !runningAsTest && |
| 803 Platform.operatingSystem != 'windows' && | 789 Platform.operatingSystem != 'windows' && |
| 804 stdioType(stdout) == StdioType.TERMINAL; | 790 stdioType(stdout) == StdioType.TERMINAL; |
| 805 | 791 |
| 806 /// Gets a "special" string (ANSI escape or Unicode). | 792 /// Gets a "special" string (ANSI escape or Unicode). |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 } else { | 919 } else { |
| 934 throw new ApplicationException(message); | 920 throw new ApplicationException(message); |
| 935 } | 921 } |
| 936 } | 922 } |
| 937 | 923 |
| 938 /// Throw a [DataException] with [message] to indicate that the command has | 924 /// Throw a [DataException] with [message] to indicate that the command has |
| 939 /// failed because of invalid input data. | 925 /// failed because of invalid input data. |
| 940 /// | 926 /// |
| 941 /// This will report the error and cause pub to exit with [exit_codes.DATA]. | 927 /// This will report the error and cause pub to exit with [exit_codes.DATA]. |
| 942 void dataError(String message) => throw new DataException(message); | 928 void dataError(String message) => throw new DataException(message); |
| OLD | NEW |